Skip to content

Commit 051ee0a

Browse files
Mason Ray Hanna IIIofeeg
authored andcommitted
Added supposed check for windows paths.
1 parent 62fd9a5 commit 051ee0a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

clippy_lints/src/methods/path_join_correction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, join_a
7676
if_chain!(
7777
if let ExprKind::Lit(spanned) = &join_arg.kind;
7878
if let LitKind::Str(symbol, _) = spanned.node;
79-
if symbol.as_str().starts_with('/');
79+
if symbol.as_str().starts_with('/') || symbol.as_str().starts_with('\\');
8080
then {
8181
span_lint_and_sugg(
8282
cx,
8383
PATH_JOIN_CORRECTION,
8484
span.with_hi(expr.span.hi()),
8585
r#"argument in join called on path contains a starting '/'"#,
86-
"try removing first '/'",
86+
"try removing first '/' or '\\'",
8787
"join(\"your/path/here\")".to_owned(),
8888
applicability
8989
);

tests/ui/path_join_correction.fixed

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ fn main() {
3535
path.join("/sh");
3636
println!("{}", path.display());
3737

38+
//should be linted
39+
let path = Path::new("C:\\Users");
40+
path.join("\\user");
41+
println!("{}", path.display());
42+
3843
// should not be linted
3944
let path: &[&str] = &["/bin"];
4045
path.join("/sh");

0 commit comments

Comments
 (0)