Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unnameable_types lint emits incorrect visibility syntax #126241

Open
kpreid opened this issue Jun 10, 2024 · 1 comment
Open

unnameable_types lint emits incorrect visibility syntax #126241

kpreid opened this issue Jun 10, 2024 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. D-papercut Diagnostics: An error or lint that needs small tweaks. L-unnameable_types Lint: unnameable_types T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kpreid
Copy link
Contributor

kpreid commented Jun 10, 2024

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.

@kpreid kpreid added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 10, 2024
@traviscross
Copy link
Contributor

cc @petrochenkov

@traviscross traviscross added the L-unnameable_types Lint: unnameable_types label Jun 10, 2024
@fmease fmease added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-papercut Diagnostics: An error or lint that needs small tweaks. A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. and removed A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. D-papercut Diagnostics: An error or lint that needs small tweaks. L-unnameable_types Lint: unnameable_types T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants