Skip to content

Commit ee35ae5

Browse files
committed
Mark PartialEq as #[rustc_trivial_field_reads]
1 parent e384365 commit ee35ae5

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

library/core/src/cmp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ use crate::ops::ControlFlow;
247247
append_const_msg
248248
)]
249249
#[rustc_diagnostic_item = "PartialEq"]
250+
#[rustc_trivial_field_reads]
250251
#[const_trait]
251252
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
252253
pub trait PartialEq<Rhs: PointeeSized = Self>: PointeeSized {

tests/ui/lint/dead-code/partial-eq.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+

0 commit comments

Comments
 (0)