Skip to content

Bad error message when using pub(in crate::foo) #142729

Closed as duplicate of#109657
Closed as duplicate of#109657
@TethysSvensson

Description

@TethysSvensson

Code

mod a {
    mod b {
        pub(in crate::a) struct Foo;
        pub(in crate::c) struct Bar;
    }
}

mod c {}

Current output

error[E0433]: failed to resolve: could not find `c` in the crate root
 --> src/lib.rs:4:23
  |
4 |         pub(in crate::c) struct Bar;
  |                       ^ could not find `c` in the crate root

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

Desired output

error[E0433]: invalid privacy specifier: `c` is not a parent module of `a::b`
 --> src/lib.rs:4:23
  |
4 |         pub(in crate::c) struct Bar;
  |                       ^ `c` is not a parent module of `a::b`

Rationale and extra context

No response

Other cases

Rust Version

$ rustc --version --verbose
rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-unknown-linux-gnu
release: 1.87.0
LLVM version: 20.1.1

Anything else?

No response

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