]> git.lizzy.rs Git - rust.git/blob - tests/ui/const_static_lifetime.rs
fc9f0e066d43f61e1591eeb90c4fe8ac5f5ebc14
[rust.git] / tests / ui / const_static_lifetime.rs
1 #[derive(Debug)]
2 struct Foo {}
3
4 const VAR_ONE: &'static str = "Test constant #1"; // ERROR Consider removing 'static.
5
6 const VAR_TWO: &str = "Test constant #2"; // This line should not raise a warning.
7
8 const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static
9
10 const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
11
12 const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
13
14 const VAR_SIX: &'static u8 = &5;
15
16 const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
17
18 const VAR_HEIGHT: &'static Foo = &Foo {};
19
20 const VAR_SLICE: &'static [u8] = b"Test constant #1"; // ERROR Consider removing 'static.
21
22 const VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static.
23
24 const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static.
25
26 static STATIC_VAR_ONE: &'static 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: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static
31
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
36 static STATIC_VAR_SIX: &'static u8 = &5;
37
38 static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
39
40 static STATIC_VAR_HEIGHT: &'static Foo = &Foo {};
41
42 static STATIC_VAR_SLICE: &'static [u8] = b"Test static #3"; // ERROR Consider removing 'static.
43
44 static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static.
45
46 static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static.
47
48 fn main() {
49     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);
59 }
60
61 trait Bar {
62     const TRAIT_VAR: &'static str;
63 }
64
65 impl Foo {
66     const IMPL_VAR: &'static str = "var";
67 }
68
69 impl Bar for Foo {
70     const TRAIT_VAR: &'static str = "foo";
71 }