Skip to content

Improve error behaviour in test case #1934

@philberty

Description

@philberty

I tried this code: https://godbolt.org/z/9jE9ozo5M

I already have this fix in phil/dev as its making our coercion sites closer to rustc.

struct Foo<A> { 
    a: A,                                                        
}                                      
                                                                    
impl Foo<isize> {    
    fn bar(self) -> isize {                                
        self.a
    }                                               
}

impl Foo<char> {
    fn bar(self) -> char {
        self.a
    }
}

impl<T> Foo<T> {
    fn bar(self) -> T {
        self.a
    }
}

fn main() {
    let a = Foo { a: 123 };
    a.bar();
}

I expected to see this happen:

$ rustc test.rs
error[E0592]: duplicate definitions with name `bar`
  --> test.rs:6:5
   |
6  |     fn bar(self) -> isize {
   |     ^^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `bar`
...
18 |     fn bar(self) -> T {
   |     ----------------- other definition for `bar`

error[E0592]: duplicate definitions with name `bar`
  --> test.rs:12:5
   |
12 |     fn bar(self) -> char {
   |     ^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `bar`
...
18 |     fn bar(self) -> T {
   |     ----------------- other definition for `bar`

Instead, this happened:

<source>:25:7: error: multiple candidates found for method 'bar'
    6 |     fn bar(self) -> isize {
      |     ~~ 
......
   18 |     fn bar(self) -> T {
      |     ~~ 
......
   25 |     a.bar();
      |       ^~~
<source>:25:5: error: failed to type resolve expression
   25 |     a.bar();
      |     ^

Meta

  • What version of Rust GCC were you using, git sha if possible. 0d4a447

Metadata

Metadata

Assignees

No one assigned

    Labels

    diagnosticdiagnostic static analysis

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions