]> git.proxmox.com Git - rustc.git/blob - src/test/ui/lint/dead-code/issue-85255.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / test / ui / lint / dead-code / issue-85255.rs
1 // Unused `pub` fields in non-`pub` structs should also trigger dead code warnings.
2 // check-pass
3
4 #![warn(dead_code)]
5
6 struct Foo {
7 a: i32, //~ WARNING: fields `a` and `b` are never read
8 pub b: i32,
9 }
10
11 struct Bar;
12
13 impl Bar {
14 fn a(&self) -> i32 { 5 } //~ WARNING: associated function `a` is never used
15 pub fn b(&self) -> i32 { 6 } //~ WARNING: associated function `b` is never used
16 }
17
18 pub(crate) struct Foo1 {
19 a: i32, //~ WARNING: fields `a` and `b` are never read
20 pub b: i32,
21 }
22
23 pub(crate) struct Bar1;
24
25 impl Bar1 {
26 fn a(&self) -> i32 { 5 } //~ WARNING: associated function `a` is never used
27 pub fn b(&self) -> i32 { 6 } //~ WARNING: associated function `b` is never used
28 }
29
30 pub(crate) struct Foo2 {
31 a: i32, //~ WARNING: fields `a` and `b` are never read
32 pub b: i32,
33 }
34
35 pub(crate) struct Bar2;
36
37 impl Bar2 {
38 fn a(&self) -> i32 { 5 } //~ WARNING: associated function `a` is never used
39 pub fn b(&self) -> i32 { 6 } //~ WARNING: associated function `b` is never used
40 }
41
42
43 fn main() {
44 let _ = Foo { a: 1, b: 2 };
45 let _ = Bar;
46 let _ = Foo1 { a: 1, b: 2 };
47 let _ = Bar1;
48 let _ = Foo2 { a: 1, b: 2 };
49 let _ = Bar2;
50 }