]>
Commit | Line | Data |
---|---|---|
f20569fa XL |
1 | #![allow(unused)] |
2 | ||
3 | #[derive(Debug)] | |
04454e1e | 4 | struct Foo; |
f20569fa | 5 | |
fe692bf9 | 6 | const VAR_ONE: &str = "Test constant #1"; // ERROR: Consider removing 'static. |
f20569fa XL |
7 | |
8 | const VAR_TWO: &str = "Test constant #2"; // This line should not raise a warning. | |
9 | ||
fe692bf9 | 10 | const VAR_THREE: &[&str] = &["one", "two"]; // ERROR: Consider removing 'static |
f20569fa | 11 | |
fe692bf9 | 12 | const VAR_FOUR: (&str, (&str, &str), &str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static |
f20569fa XL |
13 | |
14 | const VAR_SIX: &u8 = &5; | |
15 | ||
16 | const VAR_HEIGHT: &Foo = &Foo {}; | |
17 | ||
fe692bf9 | 18 | const VAR_SLICE: &[u8] = b"Test constant #1"; // ERROR: Consider removing 'static. |
f20569fa | 19 | |
fe692bf9 | 20 | const VAR_TUPLE: &(u8, u8) = &(1, 2); // ERROR: Consider removing 'static. |
f20569fa | 21 | |
fe692bf9 | 22 | const VAR_ARRAY: &[u8; 1] = b"T"; // ERROR: Consider removing 'static. |
f20569fa | 23 | |
fe692bf9 | 24 | static STATIC_VAR_ONE: &str = "Test static #1"; // ERROR: Consider removing 'static. |
f20569fa XL |
25 | |
26 | static STATIC_VAR_TWO: &str = "Test static #2"; // This line should not raise a warning. | |
27 | ||
fe692bf9 | 28 | static STATIC_VAR_THREE: &[&str] = &["one", "two"]; // ERROR: Consider removing 'static |
f20569fa XL |
29 | |
30 | static STATIC_VAR_SIX: &u8 = &5; | |
31 | ||
32 | static STATIC_VAR_HEIGHT: &Foo = &Foo {}; | |
33 | ||
fe692bf9 | 34 | static STATIC_VAR_SLICE: &[u8] = b"Test static #3"; // ERROR: Consider removing 'static. |
f20569fa | 35 | |
fe692bf9 | 36 | static STATIC_VAR_TUPLE: &(u8, u8) = &(1, 2); // ERROR: Consider removing 'static. |
f20569fa | 37 | |
fe692bf9 | 38 | static STATIC_VAR_ARRAY: &[u8; 1] = b"T"; // ERROR: Consider removing 'static. |
f20569fa | 39 | |
9c376795 FG |
40 | static mut STATIC_MUT_SLICE: &mut [u32] = &mut [0]; |
41 | ||
f20569fa XL |
42 | fn main() { |
43 | let false_positive: &'static str = "test"; | |
9c376795 FG |
44 | |
45 | unsafe { | |
46 | STATIC_MUT_SLICE[0] = 0; | |
47 | } | |
f20569fa XL |
48 | } |
49 | ||
50 | trait Bar { | |
51 | const TRAIT_VAR: &'static str; | |
52 | } | |
53 | ||
54 | impl Foo { | |
55 | const IMPL_VAR: &'static str = "var"; | |
56 | } | |
57 | ||
58 | impl Bar for Foo { | |
59 | const TRAIT_VAR: &'static str = "foo"; | |
60 | } | |
2b03887a | 61 | |
487cf647 | 62 | #[clippy::msrv = "1.16"] |
2b03887a | 63 | fn msrv_1_16() { |
2b03887a FG |
64 | static V: &'static u8 = &16; |
65 | } | |
66 | ||
487cf647 | 67 | #[clippy::msrv = "1.17"] |
2b03887a | 68 | fn msrv_1_17() { |
2b03887a FG |
69 | static V: &u8 = &17; |
70 | } |