Auto merge of #10006 - Jarcho:issue_9890, r=Manishearth

Don't suggest removing `mut` from references in `redundant_static_lifetimes`

fixes #9890
changelog: `redundant_static_lifetimes`: Don't suggest removing `mut` from references
This commit is contained in:
bors 2022-12-01 22:25:38 +00:00
commit be0eb20fff
4 changed files with 21 additions and 3 deletions

View file

@ -66,7 +66,7 @@ impl RedundantStaticLifetimes {
TyKind::Path(..) | TyKind::Slice(..) | TyKind::Array(..) | TyKind::Tup(..) => { TyKind::Path(..) | TyKind::Slice(..) | TyKind::Array(..) | TyKind::Tup(..) => {
if lifetime.ident.name == rustc_span::symbol::kw::StaticLifetime { if lifetime.ident.name == rustc_span::symbol::kw::StaticLifetime {
let snip = snippet(cx, borrow_type.ty.span, "<type>"); let snip = snippet(cx, borrow_type.ty.span, "<type>");
let sugg = format!("&{snip}"); let sugg = format!("&{}{snip}", borrow_type.mutbl.prefix_str());
span_lint_and_then( span_lint_and_then(
cx, cx,
REDUNDANT_STATIC_LIFETIMES, REDUNDANT_STATIC_LIFETIMES,

View file

@ -39,8 +39,14 @@ static STATIC_VAR_TUPLE: &(u8, u8) = &(1, 2); // ERROR Consider removing 'static
static STATIC_VAR_ARRAY: &[u8; 1] = b"T"; // ERROR Consider removing 'static. static STATIC_VAR_ARRAY: &[u8; 1] = b"T"; // ERROR Consider removing 'static.
static mut STATIC_MUT_SLICE: &mut [u32] = &mut [0];
fn main() { fn main() {
let false_positive: &'static str = "test"; let false_positive: &'static str = "test";
unsafe {
STATIC_MUT_SLICE[0] = 0;
}
} }
trait Bar { trait Bar {

View file

@ -39,8 +39,14 @@ static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing
static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static. static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static.
static mut STATIC_MUT_SLICE: &'static mut [u32] = &mut [0];
fn main() { fn main() {
let false_positive: &'static str = "test"; let false_positive: &'static str = "test";
unsafe {
STATIC_MUT_SLICE[0] = 0;
}
} }
trait Bar { trait Bar {

View file

@ -97,10 +97,16 @@ LL | static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removin
| -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]` | -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]`
error: statics have by default a `'static` lifetime error: statics have by default a `'static` lifetime
--> $DIR/redundant_static_lifetimes.rs:65:16 --> $DIR/redundant_static_lifetimes.rs:42:31
|
LL | static mut STATIC_MUT_SLICE: &'static mut [u32] = &mut [0];
| -^^^^^^^---------- help: consider removing `'static`: `&mut [u32]`
error: statics have by default a `'static` lifetime
--> $DIR/redundant_static_lifetimes.rs:71:16
| |
LL | static V: &'static u8 = &17; LL | static V: &'static u8 = &17;
| -^^^^^^^--- help: consider removing `'static`: `&u8` | -^^^^^^^--- help: consider removing `'static`: `&u8`
error: aborting due to 17 previous errors error: aborting due to 18 previous errors