-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
join_absolute_paths
Address PR review
- Loading branch information
Showing
4 changed files
with
105 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
#![allow(unused)] | ||
//@no-rustfix | ||
|
||
#![allow(clippy::needless_raw_string_hashes)] | ||
#![warn(clippy::join_absolute_paths)] | ||
|
||
use std::path::{Path, PathBuf}; | ||
|
||
fn main() { | ||
// should be linted | ||
let path = Path::new("/bin"); | ||
path.join("/sh"); | ||
//~^ ERROR: argument to `Path::join` starts with a path separator | ||
|
||
// should be linted | ||
let path = Path::new("C:\\Users"); | ||
path.join("\\user"); | ||
//~^ ERROR: argument to `Path::join` starts with a path separator | ||
|
||
let path = PathBuf::from("/bin"); | ||
path.join("/sh"); | ||
//~^ ERROR: argument to `Path::join` starts with a path separator | ||
|
||
let path = PathBuf::from("/bin"); | ||
path.join(r#"/sh"#); | ||
//~^ ERROR: argument to `Path::join` starts with a path separator | ||
|
||
// should not be linted | ||
let path: &[&str] = &["/bin"]; | ||
path.join("/sh"); | ||
|
||
// should not be linted | ||
let path = Path::new("/bin"); | ||
path.join("sh"); | ||
|
||
// should be linted | ||
let path = PathBuf::from("/bin"); | ||
path.join("/sh"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,67 @@ | ||
error: argument to `Path::join` starts with a path separator | ||
--> $DIR/join_absolute_paths.rs:9:15 | ||
--> $DIR/join_absolute_paths.rs:10:15 | ||
| | ||
LL | path.join("/sh"); | ||
| ^^^^^ | ||
| | ||
= note: joining a path starting with separator will replace the path instead | ||
= help: if this is unintentional, try removing the starting separator | ||
= help: if this is intentional, try creating a new Path instead | ||
= note: `-D clippy::join-absolute-paths` implied by `-D warnings` | ||
help: if this is unintentional, try removing the starting separator | ||
| | ||
LL | path.join("sh"); | ||
| ~~~~ | ||
help: if this is intentional, try creating a new Path instead | ||
| | ||
LL | PathBuf::from("/sh"); | ||
| ~~~~~~~~~~~~~~~~~~~~ | ||
|
||
error: argument to `Path::join` starts with a path separator | ||
--> $DIR/join_absolute_paths.rs:13:15 | ||
--> $DIR/join_absolute_paths.rs:14:15 | ||
| | ||
LL | path.join("\\user"); | ||
| ^^^^^^^^ | ||
| | ||
= note: joining a path starting with separator will replace the path instead | ||
= help: if this is unintentional, try removing the starting separator | ||
= help: if this is intentional, try creating a new Path instead | ||
help: if this is unintentional, try removing the starting separator | ||
| | ||
LL | path.join("\user"); | ||
| ~~~~~~~ | ||
help: if this is intentional, try creating a new Path instead | ||
| | ||
LL | PathBuf::from("\\user"); | ||
| ~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
error: argument to `Path::join` starts with a path separator | ||
--> $DIR/join_absolute_paths.rs:18:15 | ||
| | ||
LL | path.join("/sh"); | ||
| ^^^^^ | ||
| | ||
= note: joining a path starting with separator will replace the path instead | ||
help: if this is unintentional, try removing the starting separator | ||
| | ||
LL | path.join("sh"); | ||
| ~~~~ | ||
help: if this is intentional, try creating a new Path instead | ||
| | ||
LL | PathBuf::from("/sh"); | ||
| ~~~~~~~~~~~~~~~~~~~~ | ||
|
||
error: argument to `Path::join` starts with a path separator | ||
--> $DIR/join_absolute_paths.rs:22:15 | ||
| | ||
LL | path.join(r#"/sh"#); | ||
| ^^^^^^^^ | ||
| | ||
= note: joining a path starting with separator will replace the path instead | ||
help: if this is unintentional, try removing the starting separator | ||
| | ||
LL | path.join(r#"sh"#); | ||
| ~~~~~~~ | ||
help: if this is intentional, try creating a new Path instead | ||
| | ||
LL | PathBuf::from(r#"/sh"#); | ||
| ~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to 4 previous errors | ||
|