Skip to content

Commit 44b2b90

Browse files
committed
test: two params with the same generic
1 parent 78accf0 commit 44b2b90

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

tests/ui/needless_path_new.fixed

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ fn takes_path(_: &Path) {}
77

88
fn takes_path_and_impl_path(_: &Path, _: impl AsRef<Path>) {}
99

10+
fn takes_two_impl_paths_with_the_same_generic<P: AsRef<Path>>(_: P, _: P) {}
11+
1012
struct Foo;
1113

1214
impl Foo {
@@ -33,6 +35,12 @@ fn main() {
3335
"bar", //~ needless_path_new
3436
);
3537

38+
// we can and should change both at the same time
39+
takes_two_impl_paths_with_the_same_generic(
40+
"foo", //~ needless_path_new
41+
"bar", //~ needless_path_new
42+
);
43+
3644
// no warning
3745
takes_path(Path::new("foo"));
3846

tests/ui/needless_path_new.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ fn takes_path(_: &Path) {}
77

88
fn takes_path_and_impl_path(_: &Path, _: impl AsRef<Path>) {}
99

10+
fn takes_two_impl_paths_with_the_same_generic<P: AsRef<Path>>(_: P, _: P) {}
11+
1012
struct Foo;
1113

1214
impl Foo {
@@ -33,6 +35,12 @@ fn main() {
3335
Path::new("bar"), //~ needless_path_new
3436
);
3537

38+
// we can and should change both at the same time
39+
takes_two_impl_paths_with_the_same_generic(
40+
Path::new("foo"), //~ needless_path_new
41+
Path::new("bar"), //~ needless_path_new
42+
);
43+
3644
// no warning
3745
takes_path(Path::new("foo"));
3846

tests/ui/needless_path_new.stderr

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: the expression enclosed in `Path::new` implements `AsRef<Path>`
2-
--> tests/ui/needless_path_new.rs:22:15
2+
--> tests/ui/needless_path_new.rs:24:15
33
|
44
LL | fs::write(Path::new("foo.txt"), "foo");
55
| ^^^^^^^^^^^^^^^^^^^^ help: remove the enclosing `Path::new`: `"foo.txt"`
@@ -8,22 +8,34 @@ LL | fs::write(Path::new("foo.txt"), "foo");
88
= help: to override `-D warnings` add `#[allow(clippy::needless_path_new)]`
99

1010
error: the expression enclosed in `Path::new` implements `AsRef<Path>`
11-
--> tests/ui/needless_path_new.rs:25:9
11+
--> tests/ui/needless_path_new.rs:27:9
1212
|
1313
LL | Path::new("foo"),
1414
| ^^^^^^^^^^^^^^^^ help: remove the enclosing `Path::new`: `"foo"`
1515

1616
error: the expression enclosed in `Path::new` implements `AsRef<Path>`
17-
--> tests/ui/needless_path_new.rs:26:9
17+
--> tests/ui/needless_path_new.rs:28:9
1818
|
1919
LL | Path::new("bar"),
2020
| ^^^^^^^^^^^^^^^^ help: remove the enclosing `Path::new`: `"bar"`
2121

2222
error: the expression enclosed in `Path::new` implements `AsRef<Path>`
23-
--> tests/ui/needless_path_new.rs:33:9
23+
--> tests/ui/needless_path_new.rs:35:9
2424
|
2525
LL | Path::new("bar"),
2626
| ^^^^^^^^^^^^^^^^ help: remove the enclosing `Path::new`: `"bar"`
2727

28-
error: aborting due to 4 previous errors
28+
error: the expression enclosed in `Path::new` implements `AsRef<Path>`
29+
--> tests/ui/needless_path_new.rs:40:9
30+
|
31+
LL | Path::new("foo"),
32+
| ^^^^^^^^^^^^^^^^ help: remove the enclosing `Path::new`: `"foo"`
33+
34+
error: the expression enclosed in `Path::new` implements `AsRef<Path>`
35+
--> tests/ui/needless_path_new.rs:41:9
36+
|
37+
LL | Path::new("bar"),
38+
| ^^^^^^^^^^^^^^^^ help: remove the enclosing `Path::new`: `"bar"`
39+
40+
error: aborting due to 6 previous errors
2941

0 commit comments

Comments
 (0)