Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jruderman opened this issue Nov 6, 2023 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jruderman
Copy link
Contributor

jruderman commented Nov 6, 2023

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.

@jruderman jruderman added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 6, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 6, 2023
@estebank estebank added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 6, 2023
@estebank
Copy link
Contributor

estebank commented Nov 6, 2023

When applying the suggestion you do get the following error:

error[E0412]: cannot find type `S` in this scope
  --> src/main.rs:14:6
   |
14 |     <S as base::T>::f();
   |      ^ not found in this scope
   |
help: consider importing this struct
   |
1  + use crate::base::S;
   |

which lowers the urgency in fixing this. I'm realizing that we can choose to use with_forced_trimmed_paths! or with_no_trimmed_paths! based on whether the DefId is accessible from the current scope, given that we are already in resolve by the time we emit this error. This goes for both the self ty and the trait.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants