Skip to content

Commit c0a5a85

Browse files
committed
test: add test case for impl trait arg suggestion
1 parent f1b508c commit c0a5a85

3 files changed

+118
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// run-rustfix
2+
3+
struct A {
4+
5+
}
6+
7+
trait M {
8+
fn foo(_a: Self);
9+
fn bar(_a: Self);
10+
fn baz(_a: i32);
11+
}
12+
13+
impl M for A {
14+
fn foo(_a: Self) {}
15+
fn bar(_a: A) {}
16+
fn baz(_a: i32) {}
17+
}
18+
19+
fn main() {
20+
let _a = A {};
21+
A::foo(_a);
22+
//~^ ERROR no method named `foo` found
23+
A::baz(0);
24+
//~^ ERROR no method named `baz` found
25+
26+
let _b = A {};
27+
A::bar(_b);
28+
//~^ ERROR no method named `bar` found
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// run-rustfix
2+
3+
struct A {
4+
5+
}
6+
7+
trait M {
8+
fn foo(_a: Self);
9+
fn bar(_a: Self);
10+
fn baz(_a: i32);
11+
}
12+
13+
impl M for A {
14+
fn foo(_a: Self) {}
15+
fn bar(_a: A) {}
16+
fn baz(_a: i32) {}
17+
}
18+
19+
fn main() {
20+
let _a = A {};
21+
_a.foo();
22+
//~^ ERROR no method named `foo` found
23+
_a.baz(0);
24+
//~^ ERROR no method named `baz` found
25+
26+
let _b = A {};
27+
_b.bar();
28+
//~^ ERROR no method named `bar` found
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
error[E0599]: no method named `foo` found for struct `A` in the current scope
2+
--> $DIR/suggest-assoc-fn-call-for-impl-trait.rs:21:8
3+
|
4+
LL | struct A {
5+
| -------- method `foo` not found for this struct
6+
...
7+
LL | _a.foo();
8+
| ---^^^--
9+
| | |
10+
| | this is an associated function, not a method
11+
| help: use associated function syntax instead: `A::foo(_a)`
12+
|
13+
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
14+
note: the candidate is defined in the trait `M`
15+
--> $DIR/suggest-assoc-fn-call-for-impl-trait.rs:8:5
16+
|
17+
LL | fn foo(_a: Self);
18+
| ^^^^^^^^^^^^^^^^^
19+
20+
error[E0599]: no method named `baz` found for struct `A` in the current scope
21+
--> $DIR/suggest-assoc-fn-call-for-impl-trait.rs:23:8
22+
|
23+
LL | struct A {
24+
| -------- method `baz` not found for this struct
25+
...
26+
LL | _a.baz(0);
27+
| ---^^^---
28+
| | |
29+
| | this is an associated function, not a method
30+
| help: use associated function syntax instead: `A::baz(0)`
31+
|
32+
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
33+
note: the candidate is defined in the trait `M`
34+
--> $DIR/suggest-assoc-fn-call-for-impl-trait.rs:10:5
35+
|
36+
LL | fn baz(_a: i32);
37+
| ^^^^^^^^^^^^^^^^
38+
39+
error[E0599]: no method named `bar` found for struct `A` in the current scope
40+
--> $DIR/suggest-assoc-fn-call-for-impl-trait.rs:27:8
41+
|
42+
LL | struct A {
43+
| -------- method `bar` not found for this struct
44+
...
45+
LL | _b.bar();
46+
| ---^^^--
47+
| | |
48+
| | this is an associated function, not a method
49+
| help: use associated function syntax instead: `A::bar(_b)`
50+
|
51+
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
52+
note: the candidate is defined in the trait `M`
53+
--> $DIR/suggest-assoc-fn-call-for-impl-trait.rs:9:5
54+
|
55+
LL | fn bar(_a: Self);
56+
| ^^^^^^^^^^^^^^^^^
57+
58+
error: aborting due to 3 previous errors
59+
60+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)