Closed
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
Area: Messages for errors, warnings, and lintsArea: Trait systemArea: Visibility / privacyCategory: An issue proposing an enhancement or a PR with one.Diagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: An error or lint that needs small tweaks.Relevant to the compiler team, which will review and decide on the PR/issue.