]> git.lizzy.rs Git - rust.git/blob - tests/ui/const_static_lifetime.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / const_static_lifetime.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #[derive(Debug)]
11 struct Foo {}
12
13 const VAR_ONE: &'static str = "Test constant #1"; // ERROR Consider removing 'static.
14
15 const VAR_TWO: &str = "Test constant #2"; // This line should not raise a warning.
16
17 const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static
18
19 const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static
20
21 const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static
22
23 const VAR_SIX: &'static u8 = &5;
24
25 const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])];
26
27 const VAR_HEIGHT: &'static Foo = &Foo {};
28
29 const VAR_SLICE: &'static [u8] = b"Test constant #1"; // ERROR Consider removing 'static.
30
31 const VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static.
32
33 const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static.
34
35 fn main() {
36     let false_positive: &'static str = "test";
37     println!("{}", VAR_ONE);
38     println!("{}", VAR_TWO);
39     println!("{:?}", VAR_THREE);
40     println!("{:?}", VAR_FOUR);
41     println!("{:?}", VAR_FIVE);
42     println!("{:?}", VAR_SIX);
43     println!("{:?}", VAR_SEVEN);
44     println!("{:?}", VAR_HEIGHT);
45     println!("{}", false_positive);
46 }
47
48 trait Bar {
49     const TRAIT_VAR: &'static str;
50 }
51
52 impl Foo {
53     const IMPL_VAR: &'static str = "var";
54 }
55
56 impl Bar for Foo {
57     const TRAIT_VAR: &'static str = "foo";
58 }