-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemA-visibilityArea: Visibility / privacyArea: Visibility / privacyC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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 use
ing it at the top level.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemA-visibilityArea: Visibility / privacyArea: Visibility / privacyC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.