]> git.lizzy.rs Git - rust.git/blob - tests/ui/lint/dead-code/lint-dead-code-1.rs
Auto merge of #106884 - clubby789:fieldless-enum-debug, r=michaelwoerister
[rust.git] / tests / ui / lint / dead-code / lint-dead-code-1.rs
1 #![no_std]
2 #![allow(unused_variables)]
3 #![allow(non_camel_case_types)]
4 #![allow(non_upper_case_globals)]
5 #![deny(dead_code)]
6
7 #![crate_type="lib"]
8
9 pub use foo2::Bar2;
10
11 mod foo {
12     pub struct Bar; //~ ERROR: struct `Bar` is never constructed
13 }
14
15 mod foo2 {
16     pub struct Bar2;
17 }
18
19 pub static pub_static: isize = 0;
20 static priv_static: isize = 0; //~ ERROR: static `priv_static` is never used
21 const used_static: isize = 0;
22 pub static used_static2: isize = used_static;
23 const USED_STATIC: isize = 0;
24 const STATIC_USED_IN_ENUM_DISCRIMINANT: isize = 10;
25
26 pub const pub_const: isize = 0;
27 const priv_const: isize = 0; //~ ERROR: constant `priv_const` is never used
28 const used_const: isize = 0;
29 pub const used_const2: isize = used_const;
30 const USED_CONST: isize = 1;
31 const CONST_USED_IN_ENUM_DISCRIMINANT: isize = 11;
32
33 pub type typ = *const UsedStruct4;
34 pub struct PubStruct;
35 struct PrivStruct; //~ ERROR: struct `PrivStruct` is never constructed
36 struct UsedStruct1 {
37     #[allow(dead_code)]
38     x: isize
39 }
40 struct UsedStruct2(isize);
41 struct UsedStruct3;
42 pub struct UsedStruct4;
43 // this struct is never used directly, but its method is, so we don't want
44 // to warn it
45 struct SemiUsedStruct;
46 impl SemiUsedStruct {
47     fn la_la_la() {}
48 }
49 struct StructUsedAsField;
50 pub struct StructUsedInEnum;
51 struct StructUsedInGeneric;
52 pub struct PubStruct2 {
53     #[allow(dead_code)]
54     struct_used_as_field: *const StructUsedAsField
55 }
56
57 pub enum pub_enum { foo1, bar1 }
58 pub enum pub_enum2 { a(*const StructUsedInEnum) }
59 pub enum pub_enum3 {
60     Foo = STATIC_USED_IN_ENUM_DISCRIMINANT,
61     Bar = CONST_USED_IN_ENUM_DISCRIMINANT,
62 }
63
64 enum priv_enum { foo2, bar2 } //~ ERROR: enum `priv_enum` is never used
65 enum used_enum {
66     foo3,
67     bar3 //~ ERROR variant `bar3` is never constructed
68 }
69
70 fn f<T>() {}
71
72 pub fn pub_fn() {
73     used_fn();
74     let used_struct1 = UsedStruct1 { x: 1 };
75     let used_struct2 = UsedStruct2(1);
76     let used_struct3 = UsedStruct3;
77     let e = used_enum::foo3;
78     SemiUsedStruct::la_la_la();
79
80     let i = 1;
81     match i {
82         USED_STATIC => (),
83         USED_CONST => (),
84         _ => ()
85     }
86     f::<StructUsedInGeneric>();
87 }
88 fn priv_fn() { //~ ERROR: function `priv_fn` is never used
89     let unused_struct = PrivStruct;
90 }
91 fn used_fn() {}
92
93 fn foo() { //~ ERROR: function `foo` is never used
94     bar();
95     let unused_enum = priv_enum::foo2;
96 }
97
98 fn bar() { //~ ERROR: function `bar` is never used
99     foo();
100 }
101
102 fn baz() -> impl Copy { //~ ERROR: function `baz` is never used
103     "I'm unused, too"
104 }
105
106 // Code with #[allow(dead_code)] should be marked live (and thus anything it
107 // calls is marked live)
108 #[allow(dead_code)]
109 fn g() { h(); }
110 fn h() {}