Skip to content

Better help for pub(in parent) in edition 2018 and beyond #118878

Open
@zackw

Description

@zackw

Code

// Compile with edition 2018 or later
mod foo {
    pub(in parent) fn bar() {
        println!("hello from bar");
    }
}

fn main() {
    bar();
}

Current output

error: relative paths are not supported in visibilities in 2018 edition or later
 --> src/lib.rs:2:12
  |
2 |     pub(in parent) fn bar() {
  |            ^^^^^^ help: try: `crate::parent`

Desired output

error: relative paths are not supported in visibilities in 2018 edition or later
 --> src/lib.rs:2:12
  |
2 |     pub(in parent) fn bar() {
  |            ^^^^^^ help: try: `crate::parent`
  |         ^^^^^^^^ help: did you mean? `super`

Rationale and extra context

If the programmer wrote pub(in parent) and there is no module named parent in the crate (at the location where edition 2015 would have resolved the path), it is likely that what they were actually trying to do is make the item visible to "the parent module", which is properly spelled super.

It would also probably be helpful to refer the programmer to https://doc.rust-lang.org/reference/visibility-and-privacy.html#pubin-path-pubcrate-pubsuper-and-pubself either directly or via --explain.

Note also that this error is missing an E-code (and therefore there is nothing to use --explain on).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.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