Skip to content

Commit 31c9830

Browse files
committed
redundant_static_lifetimes: split test, make rustfixable
1 parent f6d1a62 commit 31c9830

5 files changed

+148
-90
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// run-rustfix
2+
3+
#![allow(unused)]
4+
5+
#[derive(Debug)]
6+
struct Foo {}
7+
8+
const VAR_ONE: &str = "Test constant #1"; // ERROR Consider removing 'static.
9+
10+
const VAR_TWO: &str = "Test constant #2"; // This line should not raise a warning.
11+
12+
const VAR_THREE: &[&str] = &["one", "two"]; // ERROR Consider removing 'static
13+
14+
const VAR_FOUR: (&str, (&str, &str), &str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
15+
16+
const VAR_SIX: &u8 = &5;
17+
18+
const VAR_HEIGHT: &Foo = &Foo {};
19+
20+
const VAR_SLICE: &[u8] = b"Test constant #1"; // ERROR Consider removing 'static.
21+
22+
const VAR_TUPLE: &(u8, u8) = &(1, 2); // ERROR Consider removing 'static.
23+
24+
const VAR_ARRAY: &[u8; 1] = b"T"; // ERROR Consider removing 'static.
25+
26+
static STATIC_VAR_ONE: &str = "Test static #1"; // ERROR Consider removing 'static.
27+
28+
static STATIC_VAR_TWO: &str = "Test static #2"; // This line should not raise a warning.
29+
30+
static STATIC_VAR_THREE: &[&str] = &["one", "two"]; // ERROR Consider removing 'static
31+
32+
static STATIC_VAR_SIX: &u8 = &5;
33+
34+
static STATIC_VAR_HEIGHT: &Foo = &Foo {};
35+
36+
static STATIC_VAR_SLICE: &[u8] = b"Test static #3"; // ERROR Consider removing 'static.
37+
38+
static STATIC_VAR_TUPLE: &(u8, u8) = &(1, 2); // ERROR Consider removing 'static.
39+
40+
static STATIC_VAR_ARRAY: &[u8; 1] = b"T"; // ERROR Consider removing 'static.
41+
42+
fn main() {
43+
let false_positive: &'static str = "test";
44+
}
45+
46+
trait Bar {
47+
const TRAIT_VAR: &'static str;
48+
}
49+
50+
impl Foo {
51+
const IMPL_VAR: &'static str = "var";
52+
}
53+
54+
impl Bar for Foo {
55+
const TRAIT_VAR: &'static str = "foo";
56+
}

tests/ui/redundant_static_lifetimes.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// run-rustfix
2+
3+
#![allow(unused)]
4+
15
#[derive(Debug)]
26
struct Foo {}
37

@@ -9,12 +13,8 @@ const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing '
913

1014
const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
1115

12-
const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
13-
1416
const VAR_SIX: &'static u8 = &5;
1517

16-
const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
17-
1818
const VAR_HEIGHT: &'static Foo = &Foo {};
1919

2020
const VAR_SLICE: &'static [u8] = b"Test constant #1"; // ERROR Consider removing 'static.
@@ -29,14 +29,8 @@ static STATIC_VAR_TWO: &str = "Test static #2"; // This line should not raise a
2929

3030
static STATIC_VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static
3131

32-
static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
33-
34-
static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
35-
3632
static STATIC_VAR_SIX: &'static u8 = &5;
3733

38-
static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
39-
4034
static STATIC_VAR_HEIGHT: &'static Foo = &Foo {};
4135

4236
static STATIC_VAR_SLICE: &'static [u8] = b"Test static #3"; // ERROR Consider removing 'static.
@@ -47,15 +41,6 @@ static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'st
4741

4842
fn main() {
4943
let false_positive: &'static str = "test";
50-
println!("{}", VAR_ONE);
51-
println!("{}", VAR_TWO);
52-
println!("{:?}", VAR_THREE);
53-
println!("{:?}", VAR_FOUR);
54-
println!("{:?}", VAR_FIVE);
55-
println!("{:?}", VAR_SIX);
56-
println!("{:?}", VAR_SEVEN);
57-
println!("{:?}", VAR_HEIGHT);
58-
println!("{}", false_positive);
5944
}
6045

6146
trait Bar {
Lines changed: 11 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,35 @@
11
error: Constants have by default a `'static` lifetime
2-
--> $DIR/redundant_static_lifetimes.rs:4:17
2+
--> $DIR/redundant_static_lifetimes.rs:8:17
33
|
44
LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR Consider removing 'static.
55
| -^^^^^^^---- help: consider removing `'static`: `&str`
66
|
77
= note: `-D clippy::redundant-static-lifetimes` implied by `-D warnings`
88

99
error: Constants have by default a `'static` lifetime
10-
--> $DIR/redundant_static_lifetimes.rs:8:21
10+
--> $DIR/redundant_static_lifetimes.rs:12:21
1111
|
1212
LL | const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static
1313
| -^^^^^^^---- help: consider removing `'static`: `&str`
1414

1515
error: Constants have by default a `'static` lifetime
16-
--> $DIR/redundant_static_lifetimes.rs:10:32
16+
--> $DIR/redundant_static_lifetimes.rs:14:32
1717
|
1818
LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
1919
| -^^^^^^^---- help: consider removing `'static`: `&str`
2020

2121
error: Constants have by default a `'static` lifetime
22-
--> $DIR/redundant_static_lifetimes.rs:10:47
22+
--> $DIR/redundant_static_lifetimes.rs:14:47
2323
|
2424
LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
2525
| -^^^^^^^---- help: consider removing `'static`: `&str`
2626

2727
error: Constants have by default a `'static` lifetime
28-
--> $DIR/redundant_static_lifetimes.rs:12:18
29-
|
30-
LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
31-
| -^^^^^^^------------------ help: consider removing `'static`: `&[&[&'static str]]`
32-
33-
error: Constants have by default a `'static` lifetime
34-
--> $DIR/redundant_static_lifetimes.rs:12:30
35-
|
36-
LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
37-
| -^^^^^^^---- help: consider removing `'static`: `&str`
38-
39-
error: Constants have by default a `'static` lifetime
40-
--> $DIR/redundant_static_lifetimes.rs:14:17
28+
--> $DIR/redundant_static_lifetimes.rs:16:17
4129
|
4230
LL | const VAR_SIX: &'static u8 = &5;
4331
| -^^^^^^^--- help: consider removing `'static`: `&u8`
4432

45-
error: Constants have by default a `'static` lifetime
46-
--> $DIR/redundant_static_lifetimes.rs:16:29
47-
|
48-
LL | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
49-
| -^^^^^^^--------------- help: consider removing `'static`: `&[&'static str]`
50-
51-
error: Constants have by default a `'static` lifetime
52-
--> $DIR/redundant_static_lifetimes.rs:16:39
53-
|
54-
LL | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
55-
| -^^^^^^^---- help: consider removing `'static`: `&str`
56-
5733
error: Constants have by default a `'static` lifetime
5834
--> $DIR/redundant_static_lifetimes.rs:18:20
5935
|
@@ -91,70 +67,34 @@ LL | static STATIC_VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consid
9167
| -^^^^^^^---- help: consider removing `'static`: `&str`
9268

9369
error: Statics have by default a `'static` lifetime
94-
--> $DIR/redundant_static_lifetimes.rs:32:40
95-
|
96-
LL | static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
97-
| -^^^^^^^---- help: consider removing `'static`: `&str`
98-
99-
error: Statics have by default a `'static` lifetime
100-
--> $DIR/redundant_static_lifetimes.rs:32:55
101-
|
102-
LL | static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
103-
| -^^^^^^^---- help: consider removing `'static`: `&str`
104-
105-
error: Statics have by default a `'static` lifetime
106-
--> $DIR/redundant_static_lifetimes.rs:34:26
107-
|
108-
LL | static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
109-
| -^^^^^^^------------------ help: consider removing `'static`: `&[&[&'static str]]`
110-
111-
error: Statics have by default a `'static` lifetime
112-
--> $DIR/redundant_static_lifetimes.rs:34:38
113-
|
114-
LL | static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
115-
| -^^^^^^^---- help: consider removing `'static`: `&str`
116-
117-
error: Statics have by default a `'static` lifetime
118-
--> $DIR/redundant_static_lifetimes.rs:36:25
70+
--> $DIR/redundant_static_lifetimes.rs:32:25
11971
|
12072
LL | static STATIC_VAR_SIX: &'static u8 = &5;
12173
| -^^^^^^^--- help: consider removing `'static`: `&u8`
12274

12375
error: Statics have by default a `'static` lifetime
124-
--> $DIR/redundant_static_lifetimes.rs:38:37
125-
|
126-
LL | static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
127-
| -^^^^^^^--------------- help: consider removing `'static`: `&[&'static str]`
128-
129-
error: Statics have by default a `'static` lifetime
130-
--> $DIR/redundant_static_lifetimes.rs:38:47
131-
|
132-
LL | static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
133-
| -^^^^^^^---- help: consider removing `'static`: `&str`
134-
135-
error: Statics have by default a `'static` lifetime
136-
--> $DIR/redundant_static_lifetimes.rs:40:28
76+
--> $DIR/redundant_static_lifetimes.rs:34:28
13777
|
13878
LL | static STATIC_VAR_HEIGHT: &'static Foo = &Foo {};
13979
| -^^^^^^^---- help: consider removing `'static`: `&Foo`
14080

14181
error: Statics have by default a `'static` lifetime
142-
--> $DIR/redundant_static_lifetimes.rs:42:27
82+
--> $DIR/redundant_static_lifetimes.rs:36:27
14383
|
14484
LL | static STATIC_VAR_SLICE: &'static [u8] = b"Test static #3"; // ERROR Consider removing 'static.
14585
| -^^^^^^^----- help: consider removing `'static`: `&[u8]`
14686

14787
error: Statics have by default a `'static` lifetime
148-
--> $DIR/redundant_static_lifetimes.rs:44:27
88+
--> $DIR/redundant_static_lifetimes.rs:38:27
14989
|
15090
LL | static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static.
15191
| -^^^^^^^--------- help: consider removing `'static`: `&(u8, u8)`
15292

15393
error: Statics have by default a `'static` lifetime
154-
--> $DIR/redundant_static_lifetimes.rs:46:27
94+
--> $DIR/redundant_static_lifetimes.rs:40:27
15595
|
15696
LL | static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static.
15797
| -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]`
15898

159-
error: aborting due to 26 previous errors
99+
error: aborting due to 16 previous errors
160100

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// these are rustfixable, but run-rustfix tests cannot handle them
2+
3+
const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
4+
5+
const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
6+
7+
static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
8+
9+
static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
10+
11+
static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
12+
13+
fn main() {}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
error: Constants have by default a `'static` lifetime
2+
--> $DIR/redundant_static_lifetimes_multiple.rs:3:18
3+
|
4+
LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
5+
| -^^^^^^^------------------ help: consider removing `'static`: `&[&[&'static str]]`
6+
|
7+
= note: `-D clippy::redundant-static-lifetimes` implied by `-D warnings`
8+
9+
error: Constants have by default a `'static` lifetime
10+
--> $DIR/redundant_static_lifetimes_multiple.rs:3:30
11+
|
12+
LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
13+
| -^^^^^^^---- help: consider removing `'static`: `&str`
14+
15+
error: Constants have by default a `'static` lifetime
16+
--> $DIR/redundant_static_lifetimes_multiple.rs:5:29
17+
|
18+
LL | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
19+
| -^^^^^^^--------------- help: consider removing `'static`: `&[&'static str]`
20+
21+
error: Constants have by default a `'static` lifetime
22+
--> $DIR/redundant_static_lifetimes_multiple.rs:5:39
23+
|
24+
LL | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
25+
| -^^^^^^^---- help: consider removing `'static`: `&str`
26+
27+
error: Statics have by default a `'static` lifetime
28+
--> $DIR/redundant_static_lifetimes_multiple.rs:7:40
29+
|
30+
LL | static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
31+
| -^^^^^^^---- help: consider removing `'static`: `&str`
32+
33+
error: Statics have by default a `'static` lifetime
34+
--> $DIR/redundant_static_lifetimes_multiple.rs:7:55
35+
|
36+
LL | static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
37+
| -^^^^^^^---- help: consider removing `'static`: `&str`
38+
39+
error: Statics have by default a `'static` lifetime
40+
--> $DIR/redundant_static_lifetimes_multiple.rs:9:26
41+
|
42+
LL | static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
43+
| -^^^^^^^------------------ help: consider removing `'static`: `&[&[&'static str]]`
44+
45+
error: Statics have by default a `'static` lifetime
46+
--> $DIR/redundant_static_lifetimes_multiple.rs:9:38
47+
|
48+
LL | static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
49+
| -^^^^^^^---- help: consider removing `'static`: `&str`
50+
51+
error: Statics have by default a `'static` lifetime
52+
--> $DIR/redundant_static_lifetimes_multiple.rs:11:37
53+
|
54+
LL | static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
55+
| -^^^^^^^--------------- help: consider removing `'static`: `&[&'static str]`
56+
57+
error: Statics have by default a `'static` lifetime
58+
--> $DIR/redundant_static_lifetimes_multiple.rs:11:47
59+
|
60+
LL | static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
61+
| -^^^^^^^---- help: consider removing `'static`: `&str`
62+
63+
error: aborting due to 10 previous errors
64+

0 commit comments

Comments
 (0)