]> git.lizzy.rs Git - rust.git/blob - tests/ui/const_static_lifetime.rs
Merge pull request #2984 from flip1995/single_char_pattern
[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 fn main() {
27     let false_positive: &'static str = "test";
28     println!("{}", VAR_ONE);
29     println!("{}", VAR_TWO);
30     println!("{:?}", VAR_THREE);
31     println!("{:?}", VAR_FOUR);
32     println!("{:?}", VAR_FIVE);
33     println!("{:?}", VAR_SIX);
34     println!("{:?}", VAR_SEVEN);
35     println!("{:?}", VAR_HEIGHT);
36     println!("{}", false_positive);
37 }
38
39 trait Bar {
40     const TRAIT_VAR: &'static str;
41 }
42
43 impl Foo {
44     const IMPL_VAR: &'static str = "var";
45 }
46
47 impl Bar for Foo {
48     const TRAIT_VAR: &'static str = "foo";
49 }