Skip to content

Commit

Permalink
Auto merge of rust-lang#10006 - Jarcho:issue_9890, r=Manishearth
Browse files Browse the repository at this point in the history
Don't suggest removing `mut` from references in `redundant_static_lifetimes`

fixes rust-lang#9890
changelog: `redundant_static_lifetimes`: Don't suggest removing `mut` from references
  • Loading branch information
bors committed Dec 1, 2022
2 parents 53e1b45 + 55096ea commit be0eb20
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/redundant_static_lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl RedundantStaticLifetimes {
TyKind::Path(..) | TyKind::Slice(..) | TyKind::Array(..) | TyKind::Tup(..) => {
if lifetime.ident.name == rustc_span::symbol::kw::StaticLifetime {
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(
cx,
REDUNDANT_STATIC_LIFETIMES,
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/redundant_static_lifetimes.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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 mut STATIC_MUT_SLICE: &mut [u32] = &mut [0];

fn main() {
let false_positive: &'static str = "test";

unsafe {
STATIC_MUT_SLICE[0] = 0;
}
}

trait Bar {
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/redundant_static_lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 mut STATIC_MUT_SLICE: &'static mut [u32] = &mut [0];

fn main() {
let false_positive: &'static str = "test";

unsafe {
STATIC_MUT_SLICE[0] = 0;
}
}

trait Bar {
Expand Down
10 changes: 8 additions & 2 deletions tests/ui/redundant_static_lifetimes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,16 @@ LL | static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removin
| -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]`

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;
| -^^^^^^^--- help: consider removing `'static`: `&u8`

error: aborting due to 17 previous errors
error: aborting due to 18 previous errors

0 comments on commit be0eb20

Please sign in to comment.