]> git.lizzy.rs Git - rust.git/blob - tests/ui/derives/clone-debug-dead-code.rs
Rollup merge of #106717 - klensy:typo, r=lcnr
[rust.git] / tests / ui / derives / clone-debug-dead-code.rs
1 // Checks that derived implementations of Clone and Debug do not
2 // contribute to dead code analysis (issue #84647).
3
4 #![forbid(dead_code)]
5
6 struct A { f: () }
7 //~^ ERROR: field `f` is never read
8
9 #[derive(Clone)]
10 struct B { f: () }
11 //~^ ERROR: field `f` is never read
12
13 #[derive(Debug)]
14 struct C { f: () }
15 //~^ ERROR: field `f` is never read
16
17 #[derive(Debug,Clone)]
18 struct D { f: () }
19 //~^ ERROR: field `f` is never read
20
21 struct E { f: () }
22 //~^ ERROR: field `f` is never read
23 // Custom impl, still doesn't read f
24 impl Clone for E {
25     fn clone(&self) -> Self {
26         Self { f: () }
27     }
28 }
29
30 struct F { f: () }
31 // Custom impl that actually reads f
32 impl Clone for F {
33     fn clone(&self) -> Self {
34         Self { f: self.f }
35     }
36 }
37
38 fn main() {
39     let _ = A { f: () };
40     let _ = B { f: () };
41     let _ = C { f: () };
42     let _ = D { f: () };
43     let _ = E { f: () };
44     let _ = F { f: () };
45 }