]> git.lizzy.rs Git - rust.git/blob - tests/ui/lint/dead-code/lint-dead-code-4.rs
Rollup merge of #106644 - alexcrichton:update-wasi-toolchain, r=cuviper
[rust.git] / tests / ui / lint / dead-code / lint-dead-code-4.rs
1 #![allow(unused_variables)]
2 #![allow(non_camel_case_types)]
3 #![deny(dead_code)]
4
5 struct Foo {
6     x: usize,
7     b: bool, //~ ERROR: field `b` is never read
8 }
9
10 fn field_read(f: Foo) -> usize {
11     f.x.pow(2)
12 }
13
14 enum XYZ {
15     X, //~ ERROR variants `X` and `Y` are never constructed
16     Y {
17         a: String,
18         b: i32,
19         c: i32,
20     },
21     Z
22 }
23
24 enum ABC { //~ ERROR enum `ABC` is never used
25     A,
26     B {
27         a: String,
28         b: i32,
29         c: i32,
30     },
31     C
32 }
33
34 // ensure struct variants get warning for their fields
35 enum IJK {
36     I, //~ ERROR variants `I` and `K` are never constructed
37     J {
38         a: String,
39         b: i32, //~ ERROR fields `b` and `c` are never read
40         c: i32,
41     },
42     K
43
44 }
45
46 fn struct_variant_partial_use(b: IJK) -> String {
47     match b {
48         IJK::J { a, b: _, .. } => a,
49         _ => "".to_string()
50     }
51 }
52
53 fn field_match_in_patterns(b: XYZ) -> String {
54     match b {
55         XYZ::Y { a, b: _, .. } => a,
56         _ => "".to_string()
57     }
58 }
59
60 struct Bar {
61     x: usize, //~ ERROR: fields `x` and `c` are never read
62     b: bool,
63     c: bool,
64     _guard: ()
65 }
66
67 #[repr(C)]
68 struct Baz {
69     x: u32,
70 }
71
72 fn field_match_in_let(f: Bar) -> bool {
73     let Bar { b, c: _, .. } = f;
74     b
75 }
76
77 fn main() {
78     field_read(Foo { x: 1, b: false });
79     field_match_in_patterns(XYZ::Z);
80     struct_variant_partial_use(IJK::J { a: "".into(), b: 1, c: -1 });
81     field_match_in_let(Bar { x: 42, b: true, c: false, _guard: () });
82     let _ = Baz { x: 0 };
83 }