diff options
| author | bors <bors@rust-lang.org> | 2023-11-20 12:30:03 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-11-20 12:30:03 +0000 |
| commit | 11a2eb03fa55d38e6d55079ba48573d335d0fbb6 (patch) | |
| tree | 6acbe5a25effde2cb68a27b33eb71805858a9cca /tests | |
| parent | 41140e3cb8642abb12404520ac95c4ac82ead73f (diff) | |
| parent | 34d9e88a4739a33d0d570947691c78d6980c48a9 (diff) | |
| download | rust-11a2eb03fa55d38e6d55079ba48573d335d0fbb6.tar.gz rust-11a2eb03fa55d38e6d55079ba48573d335d0fbb6.zip | |
Auto merge of #11453 - xFrednet:11208-path-join-correct, r=blyxyas
New lint `clippy::join_absolute_paths` Hey `@ofeeg,` this PR is a copy of all the changes you did in https://github.com/rust-lang/rust-clippy/commit/47171d3c6366dd08476b2ab1e1661950d13a4218 from PR https://github.com/rust-lang/rust-clippy/pull/11208. I wasn't sure how to fix the git history. Hope you're okay with me figuring this out in this separate PR --- changelog: New lint [`join_absolute_paths`] [#11453](https://github.com/rust-lang/rust-clippy/pull/11453) Closes: https://github.com/rust-lang/rust-clippy/issues/10655 r? `@Centri3` Since you also gave feedback on the other PR. I hope that I copied everything correctly, but a third pair of eyes would be appreciated :D
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/join_absolute_paths.rs | 30 | ||||
| -rw-r--r-- | tests/ui/join_absolute_paths.stderr | 68 |
2 files changed, 98 insertions, 0 deletions
diff --git a/tests/ui/join_absolute_paths.rs b/tests/ui/join_absolute_paths.rs new file mode 100644 index 00000000000..efa77a0492e --- /dev/null +++ b/tests/ui/join_absolute_paths.rs @@ -0,0 +1,30 @@ +//@no-rustfix + +#![allow(clippy::needless_raw_string_hashes)] +#![warn(clippy::join_absolute_paths)] + +use std::path::{Path, PathBuf}; + +fn main() { + let path = Path::new("/bin"); + path.join("/sh"); + //~^ ERROR: argument to `Path::join` starts with a path separator + + 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 + + let path: &[&str] = &["/bin"]; + path.join("/sh"); + + let path = Path::new("/bin"); + path.join("sh"); +} diff --git a/tests/ui/join_absolute_paths.stderr b/tests/ui/join_absolute_paths.stderr new file mode 100644 index 00000000000..0c2f89d9978 --- /dev/null +++ b/tests/ui/join_absolute_paths.stderr @@ -0,0 +1,68 @@ +error: argument to `Path::join` starts with a path separator + --> $DIR/join_absolute_paths.rs:10:15 + | +LL | path.join("/sh"); + | ^^^^^ + | + = note: joining a path starting with separator will replace the path instead + = note: `-D clippy::join-absolute-paths` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::join_absolute_paths)]` +help: if this is unintentional, try removing the starting separator + | +LL | path.join("sh"); + | ~~~~ +help: if this is intentional, try using `Path::new` instead + | +LL | PathBuf::from("/sh"); + | ~~~~~~~~~~~~~~~~~~~~ + +error: argument to `Path::join` starts with a path separator + --> $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 + | +LL | path.join("\user"); + | ~~~~~~~ +help: if this is intentional, try using `Path::new` 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 using `Path::new` 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 using `Path::new` instead + | +LL | PathBuf::from(r#"/sh"#); + | ~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 4 previous errors + |
