Skip to content

Commit

Permalink
Use a different approach to remove \ and / from the start of the give…
Browse files Browse the repository at this point in the history
…n path
  • Loading branch information
andrehjr committed Apr 17, 2019
1 parent 8bee58a commit 645683d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions clippy_lints/src/path_buf_push_overwrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathBufPushOverwrite {
if pushed_path.has_root();
if let Some(root) = pushed_path.components().next();
if root == Component::RootDir;
if let Some(root_str) = root.as_os_str().to_str();
then {
span_lint_and_sugg(
cx,
PATH_BUF_PUSH_OVERWRITE,
lit.span,
&format!("Calling `push` with '{}' (file system root) will overwrite the previous path definition", root_str),
&format!("Remove '{}' from the beginning of the given path", root_str),
format!("\"{}\"", pushed_path_lit.trim_start_matches(root_str)),
"Calling `push` with '/' or '\\' (file system root) will overwrite the previous path definition",
"try",
format!("\"{}\"", pushed_path_lit.trim_start_matches(|c| c == '/' || c == '\\')),
Applicability::MachineApplicable,
);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/path_buf_push_overwrite.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: Calling `push` with '/' (file system root) will overwrite the previous path definition
error: Calling `push` with '/' or '/' (file system root) will overwrite the previous path definition
--> $DIR/path_buf_push_overwrite.rs:6:12
|
LL | x.push("/bar");
| ^^^^^^ help: Remove '/' from the beginning of the given path: `"bar"`
| ^^^^^^ help: try: `"bar"`
|
= note: #[deny(clippy::path_buf_push_overwrite)] on by default

Expand Down

0 comments on commit 645683d

Please sign in to comment.