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

Wrong compiler suggestion for no_mangle statics inside private module #47383

Closed
phil-opp opened this issue Jan 12, 2018 · 0 comments
Closed

Wrong compiler suggestion for no_mangle statics inside private module #47383

phil-opp opened this issue Jan 12, 2018 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@phil-opp
Copy link
Contributor

Defining a pub static inside a private module like this

mod test {
    #[no_mangle]
    pub static FOO: usize = 1;
}

yields the following warning:

warning: static is marked #[no_mangle], but not exported
 --> src/main.rs:7:5
  |
7 |     pub static FOO: usize = 1;
  |     -^^^^^^^^^^^^^^^^^^^^^^^^^
  |     |
  |     help: try making it public: `pub`
  |
  = note: #[warn(private_no_mangle_statics)] on by default

The suggestion wrongly tells us to add a pub to the already public FOO.

(playpen)

@nagisa nagisa added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 12, 2018
zackmdavis added a commit to zackmdavis/rust that referenced this issue Jan 16, 2018
The incompetent fool who added these suggestions in 38e5a96 apparently
thought it was safe to assume that, because the offending function or
static was unreachable, it would therefore have not have any existing
visibility modifiers, making it safe for us to unconditionally suggest
inserting `pub`. This isn't true.

This resolves rust-lang#47383.
kennytm added a commit to kennytm/rust that referenced this issue Jan 17, 2018
…ested_double-pub, r=estebank

private no-mangle lints: only suggest `pub` if it doesn't already exist

Fixes rust-lang#47383 (function or static can be `pub` but unreachable because it's in a private module; adding another `pub` is nonsensical).

r? @estebank
kennytm added a commit to kennytm/rust that referenced this issue Jan 17, 2018
…ested_double-pub, r=estebank

private no-mangle lints: only suggest `pub` if it doesn't already exist

Fixes rust-lang#47383 (function or static can be `pub` but unreachable because it's in a private module; adding another `pub` is nonsensical).

r? @estebank
zackmdavis added a commit to zackmdavis/rust that referenced this issue Jul 1, 2018
This is probably quite a lot less likely to come up in practice than the
"inherited" (no visibility keyword) case, but now that we have
visibility spans in the HIR, we can do this, and it presumably doesn't
hurt to be exhaustive. (Who can say but that the attention to detail
just might knock someone's socks off, someday, somewhere?)

This is inspired by rust-lang#47383.
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
Projects
None yet
Development

No branches or pull requests

2 participants