Skip to content

Commit 55096ea

Browse files
committed
Don't suggest removing mut from references in redundant_static_lifetimes
1 parent 1cdb06d commit 55096ea

4 files changed

+21
-3
lines changed

clippy_lints/src/redundant_static_lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl RedundantStaticLifetimes {
6666
TyKind::Path(..) | TyKind::Slice(..) | TyKind::Array(..) | TyKind::Tup(..) => {
6767
if lifetime.ident.name == rustc_span::symbol::kw::StaticLifetime {
6868
let snip = snippet(cx, borrow_type.ty.span, "<type>");
69-
let sugg = format!("&{snip}");
69+
let sugg = format!("&{}{snip}", borrow_type.mutbl.prefix_str());
7070
span_lint_and_then(
7171
cx,
7272
REDUNDANT_STATIC_LIFETIMES,

tests/ui/redundant_static_lifetimes.fixed

+6
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ static STATIC_VAR_TUPLE: &(u8, u8) = &(1, 2); // ERROR Consider removing 'static
3939

4040
static STATIC_VAR_ARRAY: &[u8; 1] = b"T"; // ERROR Consider removing 'static.
4141

42+
static mut STATIC_MUT_SLICE: &mut [u32] = &mut [0];
43+
4244
fn main() {
4345
let false_positive: &'static str = "test";
46+
47+
unsafe {
48+
STATIC_MUT_SLICE[0] = 0;
49+
}
4450
}
4551

4652
trait Bar {

tests/ui/redundant_static_lifetimes.rs

+6
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing
3939

4040
static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static.
4141

42+
static mut STATIC_MUT_SLICE: &'static mut [u32] = &mut [0];
43+
4244
fn main() {
4345
let false_positive: &'static str = "test";
46+
47+
unsafe {
48+
STATIC_MUT_SLICE[0] = 0;
49+
}
4450
}
4551

4652
trait Bar {

tests/ui/redundant_static_lifetimes.stderr

+8-2
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,16 @@ LL | static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removin
9797
| -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]`
9898

9999
error: statics have by default a `'static` lifetime
100-
--> $DIR/redundant_static_lifetimes.rs:65:16
100+
--> $DIR/redundant_static_lifetimes.rs:42:31
101+
|
102+
LL | static mut STATIC_MUT_SLICE: &'static mut [u32] = &mut [0];
103+
| -^^^^^^^---------- help: consider removing `'static`: `&mut [u32]`
104+
105+
error: statics have by default a `'static` lifetime
106+
--> $DIR/redundant_static_lifetimes.rs:71:16
101107
|
102108
LL | static V: &'static u8 = &17;
103109
| -^^^^^^^--- help: consider removing `'static`: `&u8`
104110

105-
error: aborting due to 17 previous errors
111+
error: aborting due to 18 previous errors
106112

0 commit comments

Comments
 (0)