Skip to content

unnameable_types lint emits incorrect visibility syntax #126241

Closed
@kpreid

Description

@kpreid

Code

#![warn(unnameable_types)]

pub mod foo {
    pub fn get() -> bar::Baz {
        bar::Baz
    }
    
    mod bar {
        pub struct Baz;
    }
}

Current output

warning: struct `Baz` is reachable but cannot be named
 --> src/lib.rs:9:9
  |
9 |         pub struct Baz;
  |         ^^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(foo)`
  |
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![warn(unnameable_types)]
  |         ^^^^^^^^^^^^^^^^

warning: `playground` (lib) generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.27s

Desired output

- reachable at visibility `pub`, but can only be named at visibility `pub(foo)`
+ reachable at visibility `pub`, but can only be named at visibility `pub(in crate::foo)`

Rationale and extra context

pub(foo) is not valid visibility syntax.

Rust Version

rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-apple-darwin
release: 1.79.0
LLVM version: 18.1.7

Note that this is the pre-release of stable 1.79.0. Nightly has the same flaw.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.D-papercutDiagnostics: An error or lint that needs small tweaks.L-unnameable_typesLint: unnameable_typesT-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