File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -247,6 +247,7 @@ use crate::ops::ControlFlow;
247
247
append_const_msg
248
248
) ]
249
249
#[ rustc_diagnostic_item = "PartialEq" ]
250
+ #[ rustc_trivial_field_reads]
250
251
#[ const_trait]
251
252
#[ rustc_const_unstable( feature = "const_trait_impl" , issue = "67792" ) ]
252
253
pub trait PartialEq < Rhs : PointeeSized = Self > : PointeeSized {
Original file line number Diff line number Diff line change
1
+ #![ deny( dead_code) ]
2
+
3
+ #[ derive( PartialEq ) ]
4
+ struct MyStruct {
5
+ x : i32 ,
6
+ y : i32 , //~ ERROR field `y` is never read
7
+ }
8
+
9
+ struct MyStruct2 {
10
+ x : i32 ,
11
+ y : i32 , //~ ERROR field `y` is never read
12
+ }
13
+
14
+ pub fn main ( ) {
15
+ let ms = MyStruct { x : 1 , y : 2 } ;
16
+ let _ = ms. x ;
17
+
18
+ let ms = MyStruct2 { x : 1 , y : 2 } ;
19
+ let _ = ms. x ;
20
+ }
Original file line number Diff line number Diff line change
1
+ error: field `y` is never read
2
+ --> $DIR/partial-eq.rs:6:5
3
+ |
4
+ LL | struct MyStruct {
5
+ | -------- field in this struct
6
+ LL | x: i32,
7
+ LL | y: i32,
8
+ | ^
9
+ |
10
+ = note: `MyStruct` has a derived impl for the trait `PartialEq`, but this is intentionally ignored during dead code analysis
11
+ note: the lint level is defined here
12
+ --> $DIR/partial-eq.rs:1:9
13
+ |
14
+ LL | #![deny(dead_code)]
15
+ | ^^^^^^^^^
16
+
17
+ error: field `y` is never read
18
+ --> $DIR/partial-eq.rs:11:5
19
+ |
20
+ LL | struct MyStruct2 {
21
+ | --------- field in this struct
22
+ LL | x: i32,
23
+ LL | y: i32,
24
+ | ^
25
+
26
+ error: aborting due to 2 previous errors
27
+
You can’t perform that action at this time.
0 commit comments