Skip to content

Error suggests implementing private trait instead of importing it. #57457

Description

@pierzchalski

If I implement a private trait on a public struct, then use a trait method elsewhere, the diagnostic message suggests implementing the already implemented private trait instead of making the trait public and importing it. For example, this code:

mod m {
    trait T {
        fn f(&self);
    }
    
    pub struct S;
    
    impl T for S {
        fn f(&self) {}
    }
}

fn main() {
    let s = m::S;
    s.f();
}

Results in this diagnostic:

error[E0599]: no method named `f` found for type `m::S` in the current scope
  --> src/main.rs:15:7
   |
6  |     pub struct S;
   |     ------------- method `f` not found for this
...
15 |     s.f();
   |       ^
   |
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `f`, perhaps you need to implement it:
           candidate #1: `m::T`

The note should suggest making m::T public and useing it at the top level.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemA-visibilityArea: Visibility / privacyC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.D-papercutDiagnostics: An error or lint that needs small tweaks.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