Skip to content

Commit 1e0a3f2

Browse files
committed
test: method calls
1 parent cee5d5b commit 1e0a3f2

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed

tests/ui/needless_path_new.fixed

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,40 @@ fn takes_path(_: &Path) {}
77

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

10+
struct Foo;
11+
12+
impl Foo {
13+
fn takes_path(_: &Path) {}
14+
fn takes_self_and_path(&self, _: &Path) {}
15+
fn takes_path_and_impl_path(_: &Path, _: impl AsRef<Path>) {}
16+
fn takes_self_and_path_and_impl_path(&self, _: &Path, _: impl AsRef<Path>) {}
17+
}
18+
1019
fn main() {
20+
let f = Foo;
21+
1122
fs::write("foo.txt", "foo"); //~ needless_path_new
1223

1324
fs::copy(
1425
"foo", //~ needless_path_new
1526
"bar", //~ needless_path_new
1627
);
1728

29+
Foo::takes_path(Path::new("foo"));
30+
31+
f.takes_self_and_path_and_impl_path(
32+
Path::new("foo"),
33+
"bar", //~ needless_path_new
34+
);
35+
1836
// no warning
1937
takes_path(Path::new("foo"));
2038

2139
// the paramater that _could_ be passed directly, was
2240
// the parameter that could't, wasn't
23-
takes_path_and_impl_path(Path::new("foo"), "foo");
41+
takes_path_and_impl_path(Path::new("foo"), "bar");
42+
43+
// same but as a method
44+
Foo::takes_path_and_impl_path(Path::new("foo"), "bar");
45+
f.takes_self_and_path_and_impl_path(Path::new("foo"), "bar");
2446
}

tests/ui/needless_path_new.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,40 @@ fn takes_path(_: &Path) {}
77

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

10+
struct Foo;
11+
12+
impl Foo {
13+
fn takes_path(_: &Path) {}
14+
fn takes_self_and_path(&self, _: &Path) {}
15+
fn takes_path_and_impl_path(_: &Path, _: impl AsRef<Path>) {}
16+
fn takes_self_and_path_and_impl_path(&self, _: &Path, _: impl AsRef<Path>) {}
17+
}
18+
1019
fn main() {
20+
let f = Foo;
21+
1122
fs::write(Path::new("foo.txt"), "foo"); //~ needless_path_new
1223

1324
fs::copy(
1425
Path::new("foo"), //~ needless_path_new
1526
Path::new("bar"), //~ needless_path_new
1627
);
1728

29+
Foo::takes_path(Path::new("foo"));
30+
31+
f.takes_self_and_path_and_impl_path(
32+
Path::new("foo"),
33+
Path::new("bar"), //~ needless_path_new
34+
);
35+
1836
// no warning
1937
takes_path(Path::new("foo"));
2038

2139
// the paramater that _could_ be passed directly, was
2240
// the parameter that could't, wasn't
23-
takes_path_and_impl_path(Path::new("foo"), "foo");
41+
takes_path_and_impl_path(Path::new("foo"), "bar");
42+
43+
// same but as a method
44+
Foo::takes_path_and_impl_path(Path::new("foo"), "bar");
45+
f.takes_self_and_path_and_impl_path(Path::new("foo"), "bar");
2446
}

tests/ui/needless_path_new.stderr

Lines changed: 10 additions & 4 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:11:15
2+
--> tests/ui/needless_path_new.rs:22:15
33
|
44
LL | fs::write(Path::new("foo.txt"), "foo");
55
| ^^^^^^^^^^^^^^^^^^^^ help: remove the enclosing `Path::new`: `"foo.txt"`
@@ -8,16 +8,22 @@ 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:14:9
11+
--> tests/ui/needless_path_new.rs:25: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:15:9
17+
--> tests/ui/needless_path_new.rs:26:9
1818
|
1919
LL | Path::new("bar"),
2020
| ^^^^^^^^^^^^^^^^ help: remove the enclosing `Path::new`: `"bar"`
2121

22-
error: aborting due to 3 previous errors
22+
error: the expression enclosed in `Path::new` implements `AsRef<Path>`
23+
--> tests/ui/needless_path_new.rs:33:9
24+
|
25+
LL | Path::new("bar"),
26+
| ^^^^^^^^^^^^^^^^ help: remove the enclosing `Path::new`: `"bar"`
27+
28+
error: aborting due to 4 previous errors
2329

0 commit comments

Comments
 (0)