Skip to content

Commit 57eed05

Browse files
committed
test: add test case for disambiguate the associated function diagnostic
1 parent 11a0308 commit 57eed05

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
struct A {}
2+
3+
fn main() {
4+
let _a = A {};
5+
_a.new(1);
6+
//~^ ERROR no method named `new` found for struct `A` in the current scope
7+
}
8+
9+
trait M {
10+
fn new(_a: i32);
11+
}
12+
impl M for A {
13+
fn new(_a: i32) {}
14+
}
15+
16+
trait N {
17+
fn new(_a: Self, _b: i32);
18+
}
19+
impl N for A {
20+
fn new(_a: Self, _b: i32) {}
21+
}
22+
23+
trait O {
24+
fn new(_a: Self, _b: i32);
25+
}
26+
impl O for A {
27+
fn new(_a: A, _b: i32) {}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
error[E0599]: no method named `new` found for struct `A` in the current scope
2+
--> $DIR/disambiguate-associated-function-first-arg.rs:5:8
3+
|
4+
LL | struct A {}
5+
| -------- method `new` not found for this struct
6+
...
7+
LL | _a.new(1);
8+
| ^^^ this is an associated function, not a method
9+
|
10+
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
11+
note: candidate #1 is defined in the trait `M`
12+
--> $DIR/disambiguate-associated-function-first-arg.rs:10:5
13+
|
14+
LL | fn new(_a: i32);
15+
| ^^^^^^^^^^^^^^^^
16+
note: candidate #2 is defined in the trait `N`
17+
--> $DIR/disambiguate-associated-function-first-arg.rs:17:5
18+
|
19+
LL | fn new(_a: Self, _b: i32);
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
21+
note: candidate #3 is defined in the trait `O`
22+
--> $DIR/disambiguate-associated-function-first-arg.rs:24:5
23+
|
24+
LL | fn new(_a: Self, _b: i32);
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
26+
help: disambiguate the associated function for candidate #1
27+
|
28+
LL | <A as M>::new(1);
29+
| ~~~~~~~~~~~~~~~~
30+
help: disambiguate the associated function for candidate #2
31+
|
32+
LL | <A as N>::new(_a, 1);
33+
| ~~~~~~~~~~~~~~~~~~~~
34+
help: disambiguate the associated function for candidate #3
35+
|
36+
LL | <A as O>::new(_a, 1);
37+
| ~~~~~~~~~~~~~~~~~~~~
38+
39+
error: aborting due to 1 previous error
40+
41+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)