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