diff options
| author | Young-Flash <871946895@qq.com> | 2023-12-13 19:58:08 +0800 |
|---|---|---|
| committer | Young-Flash <871946895@qq.com> | 2023-12-16 13:01:37 +0800 |
| commit | ffd619a69521b034ea9d37f5f128055dbea35671 (patch) | |
| tree | f508b6958765e515cd4b7471410731e8108b100c | |
| parent | 6c6a2c1ef75aaa2fd3b813e3a12dd7908bdd94b1 (diff) | |
| download | rust-ffd619a69521b034ea9d37f5f128055dbea35671.tar.gz rust-ffd619a69521b034ea9d37f5f128055dbea35671.zip | |
test: add test case for `disambiguate the associated function` diagnostic
| -rw-r--r-- | tests/ui/methods/disambiguate-associated-function-first-arg.rs | 28 | ||||
| -rw-r--r-- | tests/ui/methods/disambiguate-associated-function-first-arg.stderr | 41 |
2 files changed, 69 insertions, 0 deletions
diff --git a/tests/ui/methods/disambiguate-associated-function-first-arg.rs b/tests/ui/methods/disambiguate-associated-function-first-arg.rs new file mode 100644 index 00000000000..1f8aa07b685 --- /dev/null +++ b/tests/ui/methods/disambiguate-associated-function-first-arg.rs @@ -0,0 +1,28 @@ +struct A {} + +fn main() { + let _a = A {}; + _a.new(1); + //~^ ERROR no method named `new` found for struct `A` in the current scope +} + +trait M { + fn new(_a: i32); +} +impl M for A { + fn new(_a: i32) {} +} + +trait N { + fn new(_a: Self, _b: i32); +} +impl N for A { + fn new(_a: Self, _b: i32) {} +} + +trait O { + fn new(_a: Self, _b: i32); +} +impl O for A { + fn new(_a: A, _b: i32) {} +} diff --git a/tests/ui/methods/disambiguate-associated-function-first-arg.stderr b/tests/ui/methods/disambiguate-associated-function-first-arg.stderr new file mode 100644 index 00000000000..b66ee7b8f4d --- /dev/null +++ b/tests/ui/methods/disambiguate-associated-function-first-arg.stderr @@ -0,0 +1,41 @@ +error[E0599]: no method named `new` found for struct `A` in the current scope + --> $DIR/disambiguate-associated-function-first-arg.rs:5:8 + | +LL | struct A {} + | -------- method `new` not found for this struct +... +LL | _a.new(1); + | ^^^ this is an associated function, not a method + | + = note: found the following associated functions; to be used as methods, functions must have a `self` parameter +note: candidate #1 is defined in the trait `M` + --> $DIR/disambiguate-associated-function-first-arg.rs:10:5 + | +LL | fn new(_a: i32); + | ^^^^^^^^^^^^^^^^ +note: candidate #2 is defined in the trait `N` + --> $DIR/disambiguate-associated-function-first-arg.rs:17:5 + | +LL | fn new(_a: Self, _b: i32); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: candidate #3 is defined in the trait `O` + --> $DIR/disambiguate-associated-function-first-arg.rs:24:5 + | +LL | fn new(_a: Self, _b: i32); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: disambiguate the associated function for candidate #1 + | +LL | <A as M>::new(1); + | ~~~~~~~~~~~~~~~~ +help: disambiguate the associated function for candidate #2 + | +LL | <A as N>::new(_a, 1); + | ~~~~~~~~~~~~~~~~~~~~ +help: disambiguate the associated function for candidate #3 + | +LL | <A as O>::new(_a, 1); + | ~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0599`. |
