Skip to content

Commit 25ee587

Browse files
author
Mason Ray Hanna III
committed
Added supposed check for windows paths.
1 parent 4361151 commit 25ee587

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

clippy_lints/src/methods/path_join_correction.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, join_a
1414
if_chain!(
1515
if let ExprKind::Lit(spanned) = &join_arg.kind;
1616
if let LitKind::Str(symbol, _) = spanned.node;
17-
if symbol.as_str().starts_with('/');
17+
if symbol.as_str().starts_with('/') || symbol.as_str().starts_with('\\');
1818
then {
1919
span_lint_and_sugg(
2020
cx,
2121
PATH_JOIN_CORRECTION,
2222
span.with_hi(expr.span.hi()),
2323
r#"argument in join called on path contains a starting '/'"#,
24-
"try removing first '/'",
24+
"try removing first '/' or '\\'",
2525
"join(\"your/path/here\")".to_owned(),
2626
applicability
2727
);

tests/ui/path_join_correction.fixed

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ fn main() {
1010
path.join("/sh");
1111
println!("{}", path.display());
1212

13+
//should be linted
14+
let path = Path::new("C:\\Users");
15+
path.join("\\user");
16+
println!("{}", path.display());
17+
1318
// should not be linted
1419
let path: &[&str] = &["/bin"];
1520
path.join("/sh");

tests/ui/path_join_correction.rs

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ fn main() {
1010
path.join("/sh");
1111
println!("{}", path.display());
1212

13+
//should be linted
14+
let path = Path::new("C:\\Users");
15+
path.join("\\user");
16+
println!("{}", path.display());
17+
1318
// should not be linted
1419
let path: &[&str] = &["/bin"];
1520
path.join("/sh");

0 commit comments

Comments
 (0)