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