-
Notifications
You must be signed in to change notification settings - Fork 187
Closed
Labels
Description
- You can view similiar on compiler-explorer
- Solving this issue helps this PR [E0034] Ambiguous Method Call Error #2365 to emit error code similiar to rustc.
I tried this code:
// https://doc.rust-lang.org/error_codes/E0034.html
struct Test;
trait Trait1 {
fn foo();
}
trait Trait2 {
fn foo();
}
impl Trait1 for Test { fn foo() {} }
impl Trait2 for Test { fn foo() {} }
fn main() {
Test::foo() // { dg-error "multiple applicable items in scope for: test" }
// error, which foo() to call?
}
This happened:
- Location info was not clear.
gcc/crab1 ../mahad-testsuite/E0034.rs -frust-incomplete-and-experimental-compiler-do-not-use
../mahad-testsuite/E0034.rs:16:11: error: multiple applicable items in scope for: foo
- 12 | impl Trait1 for Test { fn foo() {} }
- | ^^^^^^^^
+ 12 | impl Trait1 for Test { fn foo() {} }
+ | ~~
- 13 | impl Trait2 for Test { fn foo() {} }
- | ^^^^^^^^
+ 13 | impl Trait2 for Test { fn foo() {} }
+ | ~~
......
+ 16 | Test::foo() // { dg-error "multiple applicable items in scope for: test" }
- | ^^^ multiple `foo` found
+ | ^~~
../mahad-testsuite/E0034.rs:16:5: error: Failed to resolve expression of function call
16 | Test::foo() // { dg-error "multiple applicable items in scope for: test" }
| ^~~~
Analyzing compilation unit
Time variable usr sys wall GGC
phase parsing : 0.00 ( 0%) 0.00 ( 0%) 0.01 (100%) 8192 ( 5%)
parser (global) : 0.00 ( 0%) 0.00 ( 0%) 0.01 (100%) 8192 ( 5%)
TOTAL : 0.00 0.00 0.01 146k
Extra diagnostic checks enabled; compiler may run slowly.
Configure with --enable-checking=release to disable checks.
I expected to see this happen:
- Location info similiar to rustc-1.49.
mahad@linux:~/Desktop/mahad/gccrs-build$ rustc ../mahad-testsuite/E0034.rs
error[E0034]: multiple applicable items in scope
--> ../mahad-testsuite/E0034.rs:16:11
|
16 | Test::foo() // { dg-error "multiple applicable items in scope for: test" }
| ^^^ multiple `foo` found
|
note: candidate #1 is defined in an impl of the trait `Trait1` for the type `Test`
--> ../mahad-testsuite/E0034.rs:12:24
|
12 | impl Trait1 for Test { fn foo() {} }
| ^^^^^^^^
note: candidate #2 is defined in an impl of the trait `Trait2` for the type `Test`
--> ../mahad-testsuite/E0034.rs:13:24
|
13 | impl Trait2 for Test { fn foo() {} }
| ^^^^^^^^
help: disambiguate the associated function for candidate #1
|
16 | Trait1::foo() // { dg-error "multiple applicable items in scope for: test" }
| ^^^^^^^^^^^
help: disambiguate the associated function for candidate #2
|
16 | Trait2::foo() // { dg-error "multiple applicable items in scope for: test" }
| ^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0034`.
Meta
- What version of Rust GCC were you using, git sha 5d33b88.