Skip to content

Hint for E0790 does not result in valid code (missing path to implementation) #117623

Open
@jruderman

Description

@jruderman

Code

mod base {
    pub trait T {
        fn f();
    }

    pub struct S;

    impl T for S {
        fn f() {}
    }
}

pub fn foo() {
    base::T::f();
}

fn main() { }

Current output

error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
  --> awex.rs:14:5
   |
3  |         fn f();
   |         ------- `T::f` defined here
...
14 |     base::T::f();
   |     ^^^^^^^^^^ cannot call associated function of trait
   |
help: use the fully-qualified path to the only available implementation
   |
14 |     <S as base::T>::f();
   |     +++++        +

Desired output

help: use the fully-qualified path to the only available implementation
   |
14 |     <base::S as base::T>::f();
   |     +++++++++++        +

Rationale and extra context

Since base::S has not been imported, the hint code should use base::S rather than S

Other cases

No response

Anything else?

I noticed this in tests/ui/traits/static-method-generic-inference.rs. Reduced to isolate the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions