Skip to content

Wrong compiler suggestion for no_mangle statics inside private module #47383

Closed
@phil-opp

Description

@phil-opp

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions