Skip to content

Mark PartialEq as #[rustc_trivial_field_reads] #143487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_builtin_macros/src/format_foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ pub(crate) mod printf {
/// Precision of the conversion.
precision: Option<Num>,
/// Length modifier for the conversion.
// FIXME(#143487): is it okay that this field is never read?
#[cfg_attr(not(bootstrap), expect(dead_code))]
length: Option<&'a str>,
/// Type of parameter being converted.
type_: &'a str,
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_data_structures/src/sync/worker_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ use crate::sync::CacheAligned;
/// A pointer to the `RegistryData` which uniquely identifies a registry.
/// This identifier can be reused if the registry gets freed.
#[derive(Clone, Copy, PartialEq)]
struct RegistryId(*const RegistryData);
struct RegistryId(
#[cfg_attr(
not(bootstrap),
expect(dead_code, reason = "This field is only used for equality comparisons")
)]
*const RegistryData,
);

impl RegistryId {
#[inline(always)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_errors/src/json/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct TestData {
}

#[derive(Deserialize, Debug, PartialEq, Eq)]
#[allow(dead_code, reason = "Fields are only used for equality comparisons")]
struct SpanTestData {
pub byte_start: u32,
pub byte_end: u32,
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_hir_typeck/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,21 @@ use crate::errors::{
enum Context {
Normal,
Fn,
Loop(hir::LoopSource),
Loop(
// FIXME(#143487): is it okay that this field is never read?
#[cfg_attr(not(bootstrap), expect(dead_code))] hir::LoopSource,
),
Closure(Span),
Coroutine {
coroutine_span: Span,
kind: hir::CoroutineDesugaring,
source: hir::CoroutineSource,
},
UnlabeledBlock(Span),
UnlabeledIfBlock(Span),
UnlabeledIfBlock(
// FIXME(#143487): is it okay that this field is never read?
#[cfg_attr(not(bootstrap), expect(dead_code))] Span,
),
LabeledBlock,
/// E.g. The labeled block inside `['_'; 'block: { break 'block 1 + 2; }]`.
AnonConst,
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_pattern_analysis/src/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,13 @@ impl Slice {

/// A globally unique id to distinguish `Opaque` patterns.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct OpaqueId(u32);
pub struct OpaqueId(
#[cfg_attr(
not(bootstrap),
expect(dead_code, reason = "This field is only used for equality comparisons")
)]
u32,
);

impl OpaqueId {
pub fn new() -> Self {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_thread_pool/tests/scoped_threadpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crossbeam_utils::thread;
use rustc_thread_pool::ThreadPoolBuilder;

#[derive(PartialEq, Eq, Debug)]
struct Local(i32);
struct Local(#[allow(dead_code, reason = "Only used for equality comparisons")] i32);

scoped_tls::scoped_thread_local!(static LOCAL: Local);

Expand Down
1 change: 1 addition & 0 deletions library/core/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ use crate::ops::ControlFlow;
append_const_msg
)]
#[rustc_diagnostic_item = "PartialEq"]
#[rustc_trivial_field_reads]
#[const_trait]
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
pub trait PartialEq<Rhs: PointeeSized = Self>: PointeeSized {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ struct AtHwcap {
f8fma: bool,
f8dp4: bool,
f8dp2: bool,
f8e4m3: bool,
f8e5m2: bool,
// f8e4m3: bool,
// f8e5m2: bool,
smelutv2: bool,
smef8f16: bool,
smef8f32: bool,
Expand Down Expand Up @@ -230,8 +230,8 @@ impl From<auxvec::AuxVec> for AtHwcap {
f8fma: bit::test(auxv.hwcap2, 52),
f8dp4: bit::test(auxv.hwcap2, 53),
f8dp2: bit::test(auxv.hwcap2, 54),
f8e4m3: bit::test(auxv.hwcap2, 55),
f8e5m2: bit::test(auxv.hwcap2, 56),
// f8e4m3: bit::test(auxv.hwcap2, 55),
// f8e5m2: bit::test(auxv.hwcap2, 56),
smelutv2: bit::test(auxv.hwcap2, 57),
smef8f16: bit::test(auxv.hwcap2, 58),
smef8f32: bit::test(auxv.hwcap2, 59),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub(crate) fn detect_features() -> cache::Initializer {
cache(opt_hwcap, facilities)
}

// FIXME(#143487): is it okay that the fields are never read?
#[expect(dead_code)]
#[derive(Debug, Default, PartialEq)]
struct AtHwcap {
esan3: bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::mem;
// That means the untagged variants is in the niche variant range!
// However, using the corresponding value (2+1 = 3) is not a valid encoding of this variant.
#[derive(Copy, Clone, PartialEq)]
#[allow(dead_code)]
enum Foo {
Var1,
Var2(bool),
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/pass/binops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fn test_ptr() {
}

#[derive(PartialEq, Debug)]
#[allow(dead_code)]
struct P {
x: isize,
y: isize,
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/pass/coercions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(coerce_unsized, unsize)]
#![allow(dead_code)]

use std::marker::Unsize;
use std::ops::CoerceUnsized;
Expand Down
2 changes: 2 additions & 0 deletions src/tools/miri/tests/pass/deriving-associated-types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

pub trait DeclaredTrait {
type Type;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

#[derive(Copy, Clone, PartialEq, Debug)]
struct A<'a> {
x: i32,
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/pass/tuple_like_struct_constructor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
fn main() {
#[derive(PartialEq, Eq, Debug)]
#[allow(dead_code)]
struct A(i32);
assert_eq!(Some(42).map(A), Some(A(42)));
}
7 changes: 5 additions & 2 deletions src/tools/rust-analyzer/crates/hir-def/src/hir/format_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,12 @@ pub enum FormatArgumentKind {

// Only used in parse_args and report_invalid_references,
// to indicate how a referred argument was used.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, Debug)]
enum PositionUsedAs {
Placeholder(Option<TextRange>),
Placeholder(
// FIXME(#143487): is it okay that the field is never read?
#[allow(dead_code)] Option<TextRange>,
),
Precision,
Width,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ pub(crate) enum PatKind {
/// `Foo(...)` or `Foo{...}` or `Foo`, where `Foo` is a variant name from an ADT with
/// multiple variants.
Variant {
// FIXME(#143487): is it okay that the field is never read?
#[allow(dead_code)]
substs: Substitution,
enum_variant: EnumVariantId,
subpatterns: Vec<FieldPat>,
Expand Down
5 changes: 4 additions & 1 deletion src/tools/rust-analyzer/crates/hir-ty/src/infer/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,10 @@ enum PointerKind {
// slice
Length,
OfAlias,
OfParam(PlaceholderIndex),
OfParam(
// FIXME(#143487): is it okay that the field is never read?
#[allow(dead_code)] PlaceholderIndex,
),
Error,
}

Expand Down
4 changes: 3 additions & 1 deletion src/tools/rust-analyzer/crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4634,9 +4634,11 @@ impl Closure {
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug)]
pub struct ClosureCapture {
owner: DefWithBodyId,
// FIXME(#143487): is it okay that the field is never read?
#[allow(dead_code)]
closure: ClosureId,
capture: hir_ty::CapturedItem,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ pub(crate) struct PatternContext {
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct ParamContext {
pub(crate) param_list: ast::ParamList,
#[allow(dead_code, reason = "Used for equality comparison")]
pub(crate) param: ast::Param,
pub(crate) kind: ParamKind,
}
Expand Down
10 changes: 8 additions & 2 deletions src/tools/rust-analyzer/xtask/src/publish/notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,15 @@ impl Default for ListNesting {

#[derive(Debug, PartialEq, Eq)]
enum ListMarker {
Asterisk(usize),
Asterisk(
// FIXME(#143487): is it okay that the field is never read?
#[allow(dead_code)] usize,
),
Hyphen,
Dot(usize),
Dot(
// FIXME(#143487): is it okay that the field is never read?
#[allow(dead_code)] usize,
),
}

impl ListMarker {
Expand Down
1 change: 1 addition & 0 deletions tests/ui/abi/extern/extern-pass-FiveU16s.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ run-pass
#![allow(improper_ctypes)]
#![allow(dead_code)]

// Test a foreign function that accepts and returns a struct by value.

Expand Down
1 change: 1 addition & 0 deletions tests/ui/abi/extern/extern-pass-TwoU16s.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ run-pass
#![allow(improper_ctypes)]
#![allow(dead_code)]

// Test a foreign function that accepts and returns a struct
// by value.
Expand Down
1 change: 1 addition & 0 deletions tests/ui/abi/extern/extern-pass-TwoU32s.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ run-pass
#![allow(improper_ctypes)]
#![allow(dead_code)]

// Test a foreign function that accepts and returns a struct
// by value.
Expand Down
1 change: 1 addition & 0 deletions tests/ui/abi/extern/extern-pass-TwoU64s.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ run-pass
#![allow(improper_ctypes)]
#![allow(dead_code)]

// Test a foreign function that accepts and returns a struct
// by value.
Expand Down
1 change: 1 addition & 0 deletions tests/ui/abi/extern/extern-pass-TwoU8s.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ run-pass
#![allow(improper_ctypes)]
#![allow(dead_code)]

// Test a foreign function that accepts and returns a struct
// by value.
Expand Down
1 change: 1 addition & 0 deletions tests/ui/abi/homogenous-floats-target-feature-mixup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#![allow(overflowing_literals)]
#![allow(unused_variables)]
#![allow(dead_code)]

use std::process::{Command, ExitStatus};
use std::env;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//@ run-pass

#![allow(unused_variables)]
#![allow(dead_code)]

// Test that the drop order for parameters in a fn and async fn matches up. Also test that
// parameters (used or unused) are not dropped until the async fn completes execution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//@[nomiropt]compile-flags: -Z mir-opt-level=0

#![allow(unused_variables)]
#![allow(dead_code)]

// Test that the drop order for parameters in a fn and async fn matches up. Also test that
// parameters (used or unused) are not dropped until the async fn completes execution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#![allow(unused_variables)]
#![allow(unused_must_use)]
#![allow(path_statements)]
#![allow(dead_code)]

// Test that the drop order for locals in a fn and async fn matches up.
extern crate arc_wake;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//@[nomiropt]compile-flags: -Z mir-opt-level=0

#![allow(unused_variables)]
#![allow(dead_code)]

// Test the drop order for parameters relative to local variables and
// temporaries created in the tail return expression of the function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// This file is mostly copy-pasted from drop-order-for-async-fn-parameters.rs

#![allow(unused_variables)]
#![allow(dead_code)]

extern crate arc_wake;

Expand Down
2 changes: 2 additions & 0 deletions tests/ui/binding/match-larger-const.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//@ run-pass
#![allow(dead_code)]

#[derive(Eq, PartialEq)]
pub struct Data([u8; 4]);

Expand Down
1 change: 1 addition & 0 deletions tests/ui/binop/binops.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ run-pass

#![allow(non_camel_case_types)]
#![allow(dead_code)]
// Binop corner cases

fn test_nil() {
Expand Down
1 change: 1 addition & 0 deletions tests/ui/codegen/mono-respects-abi-alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//! leading to incorrect method dispatch for `unwrap()`.

//@ run-pass
#![allow(dead_code)]

#[derive(Copy, Clone)]
struct S<T> {
Expand Down
1 change: 1 addition & 0 deletions tests/ui/coercion/issue-39823.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ run-pass
//@ aux-build:issue-39823.rs
#![allow(dead_code)]

extern crate issue_39823;
use issue_39823::{RemoteC, RemoteG};
Expand Down
1 change: 1 addition & 0 deletions tests/ui/coherence/coherence-where-clause.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ run-pass
#![allow(dead_code)]

use std::fmt::Debug;
trait MyTrait {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ run-pass
#![allow(dead_code)]

trait ConstDefault {
const DEFAULT: Self;
Expand Down
1 change: 1 addition & 0 deletions tests/ui/consts/const_in_pattern/issue-62614.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ run-pass
#![allow(dead_code)]

struct Sum(u32, u32);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ run-pass
#![allow(dead_code)]
struct NoDerive(#[allow(dead_code)] i32);

#[derive(PartialEq)]
Expand Down
1 change: 1 addition & 0 deletions tests/ui/consts/match-const-fn-structs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ run-pass
#![allow(unused_variables)]
#![allow(dead_code)]

// https://github.com/rust-lang/rust/issues/46114

Expand Down
2 changes: 2 additions & 0 deletions tests/ui/deriving/deriving-associated-types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//@ run-pass
#![allow(dead_code)]

pub trait DeclaredTrait {
type Type;
}
Expand Down
1 change: 1 addition & 0 deletions tests/ui/deriving/deriving-via-extension-struct-tuple.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ run-pass
#![allow(dead_code)]
#[derive(PartialEq, Debug)]
struct Foo(isize, isize, String);

Expand Down
2 changes: 2 additions & 0 deletions tests/ui/deriving/deriving-via-extension-struct.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//@ run-pass
#![allow(dead_code)]

#[derive(PartialEq, Debug)]
struct Foo {
x: isize,
Expand Down
Loading
Loading