Skip to content

Commit 645683d

Browse files
committed
Use a different approach to remove \ and / from the start of the given path
1 parent 8bee58a commit 645683d

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

clippy_lints/src/path_buf_push_overwrite.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathBufPushOverwrite {
5555
if pushed_path.has_root();
5656
if let Some(root) = pushed_path.components().next();
5757
if root == Component::RootDir;
58-
if let Some(root_str) = root.as_os_str().to_str();
5958
then {
6059
span_lint_and_sugg(
6160
cx,
6261
PATH_BUF_PUSH_OVERWRITE,
6362
lit.span,
64-
&format!("Calling `push` with '{}' (file system root) will overwrite the previous path definition", root_str),
65-
&format!("Remove '{}' from the beginning of the given path", root_str),
66-
format!("\"{}\"", pushed_path_lit.trim_start_matches(root_str)),
63+
"Calling `push` with '/' or '\\' (file system root) will overwrite the previous path definition",
64+
"try",
65+
format!("\"{}\"", pushed_path_lit.trim_start_matches(|c| c == '/' || c == '\\')),
6766
Applicability::MachineApplicable,
6867
);
6968
}

tests/ui/path_buf_push_overwrite.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: Calling `push` with '/' (file system root) will overwrite the previous path definition
1+
error: Calling `push` with '/' or '/' (file system root) will overwrite the previous path definition
22
--> $DIR/path_buf_push_overwrite.rs:6:12
33
|
44
LL | x.push("/bar");
5-
| ^^^^^^ help: Remove '/' from the beginning of the given path: `"bar"`
5+
| ^^^^^^ help: try: `"bar"`
66
|
77
= note: #[deny(clippy::path_buf_push_overwrite)] on by default
88

0 commit comments

Comments
 (0)