Change:
Defining a static inside a private module like this yields the following warning: The suggestion wrongly tells us to add a to the already public . ()

Discussion:
let msg = "function is marked #[no_mangle], but not exported"; let mut err = cx.struct_span_lint(PRIVATE_NO_MANGLE_FNS, it.span, msg); let insertion_span = it.span.with_hi(it.span.lo()); <del> err.span_suggestion(insertion_span, "try making it public", "pub ".to_owned()); </del> <ins> if it.vis == hir::Visibility::Inherited { err.span_suggestion(insertion_span, "try making it public", "pub ".to_owned()); } </ins> err.emit(); } if generics.is_type_parameterized() {

let msg = "static is marked #[no_mangle], but not exported"; let mut err = cx.struct_span_lint(PRIVATE_NO_MANGLE_STATICS, it.span, msg); let insertion_span = it.span.with_hi(it.span.lo()); <del> err.span_suggestion(insertion_span, "try making it public", "pub ".to_owned()); </del> <ins> if it.vis == hir::Visibility::Inherited { err.span_suggestion(insertion_span, "try making it public", "pub ".to_owned()); } </ins> err.emit(); } }

fn rio_grande() {} // should suggest `pub` //~^ WARN function is marked <ins> mod badlands { // The private-no-mangle lints shouldn't suggest inserting `pub` when the // item is already `pub` (but triggered the lint because, e.g., it's in a // private module). (Issue #47383) #[no_mangle] pub static DAUNTLESS: bool = true; //~^ WARN static is marked #[no_mangle] pub fn val_jean() {} //~^ WARN function is marked } </ins> struct Equinox { warp_factor: f32, }

warning: unnecessary parentheses around assigned value <del> --> $DIR/suggestions.rs:36:21 </del> <ins> --> $DIR/suggestions.rs:46:21 </ins> | <del> 36 |         let mut a = (1); // should suggest no `mut`, no parens </del> <ins> 46 |         let mut a = (1); // should suggest no `mut`, no parens </ins> |                     ^^^ help: remove these parentheses | note: lint level defined here

|                     ^^^^^^^^^^^^^ warning: use of deprecated attribute `no_debug`: the `#[no_debug]` attribute was an experimental feature that has been deprecated due to lack of demand. See https://github.com/rust-lang/rust/issues/29721 <del> --> $DIR/suggestions.rs:31:1 </del> <ins> --> $DIR/suggestions.rs:41:1 </ins> | <del> 31 | #[no_debug] // should suggest removal of deprecated attribute </del> <ins> 41 | #[no_debug] // should suggest removal of deprecated attribute </ins> | ^^^^^^^^^^^ help: remove this attribute | = note: #[warn(deprecated)] on by default warning: variable does not need to be mutable <del> --> $DIR/suggestions.rs:36:13 </del> <ins> --> $DIR/suggestions.rs:46:13 </ins> | <del> 36 |         let mut a = (1); // should suggest no `mut`, no parens </del> <ins> 46 |         let mut a = (1); // should suggest no `mut`, no parens </ins> |             ---^^ |             | |             help: remove this `mut`

| = note: #[warn(private_no_mangle_fns)] on by default <ins> warning: static is marked #[no_mangle], but not exported --> $DIR/suggestions.rs:31:18 | 31 |     #[no_mangle] pub static DAUNTLESS: bool = true; |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: function is marked #[no_mangle], but not exported --> $DIR/suggestions.rs:33:18 | 33 |     #[no_mangle] pub fn val_jean() {} |                  ^^^^^^^^^^^^^^^^^^^^ </ins> warning: denote infinite loops with `loop { ... }` <del> --> $DIR/suggestions.rs:34:5 </del> <ins> --> $DIR/suggestions.rs:44:5 </ins> | <del> 34 |     while true { // should suggest `loop` </del> <ins> 44 |     while true { // should suggest `loop` </ins> |     ^^^^^^^^^^ help: use `loop` | = note: #[warn(while_true)] on by default warning: the `warp_factor:` in this pattern is redundant <del> --> $DIR/suggestions.rs:41:23 </del> <ins> --> $DIR/suggestions.rs:51:23 </ins> | <del> 41 |             Equinox { warp_factor: warp_factor } => {} // should suggest shorthand </del> <ins> 51 |             Equinox { warp_factor: warp_factor } => {} // should suggest shorthand </ins> |                       ------------^^^^^^^^^^^^ |                       | |                       help: remove this