Skip to content

Importing from the wrong module leads to privacy error, which is unhelpful #57619

Description

@Manishearth
use crate::foo::Bar;

mod foo {use crate::bar::Bar;}
pub mod bar {pub struct Bar;}

this kind of thing happens pretty often for me, where I try importing from the wrong module.

This gives me the following error:

error[E0603]: struct `Bar` is private
 --> src/main.rs:3:17
  |
3 | use crate::foo::Bar;
  |                 ^^^

this is misleading because most Rust mental models don't consider use statements to be private instances, they just work that way.

Ideally, this error would notice that it's a private use statement, and instead backtrack it to find the actual path that should be used.

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-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-enhancementCategory: An issue proposing an enhancement or a PR with one.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