Skip to content

Rustc suggests importing trait inside private module #90258

Closed
@Noratrieb

Description

@Noratrieb
fn main() {
    let _ = [0; 32].slice();
}

The current output is:

error[E0599]: no method named `slice` found for array `[{integer}; 32]` in the current scope
 --> priv.rs:2:18
  |
2 |     let _ = [0; 32].slice();
  |                     ^^^^^ method not found in `[{integer}; 32]`
  |
  = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
  |
1 | use std::collections::vec_deque::ring_slices::RingSlices;
  |

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.

Here, rustc suggests importing the trait RingSlices, which is inside a private module and can't be used.

If possible, rustc should probably check whether a suggested trait is usable in the current module, and only suggest it if it is.

One thing that is useful about the current version is, that it might suggest that the user should make the module public if they control it. Maybe it should still be emitted if the trait is in the current crate.

Found by @angelsflyinhell, a rust beginner that was a bit confused by this

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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