Skip to content

Commit 6c09c40

Browse files
authored
Rollup merge of rust-lang#145145 - fee1-dead-contrib:push-qnmpmtmtpkkr, r=jieyouxu
some `derive_more` refactors some clauses can be merged together without requiring an attribute for each trait derived. also manually impl `Eq` because the `derive_where` generated code is too much for my comfort (cc ModProg/derive-where#128)
2 parents 8c58da3 + 71f6e53 commit 6c09c40

File tree

17 files changed

+180
-100
lines changed

17 files changed

+180
-100
lines changed

compiler/rustc_next_trait_solver/src/solve/inspect/build.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<I: Interner> From<WipCanonicalGoalEvaluationStep<I>> for DebugSolver<I> {
6868
}
6969
}
7070

71-
#[derive_where(PartialEq, Eq, Debug; I: Interner)]
71+
#[derive_where(PartialEq, Debug; I: Interner)]
7272
struct WipGoalEvaluation<I: Interner> {
7373
pub uncanonicalized_goal: Goal<I, I::Predicate>,
7474
pub orig_values: Vec<I::GenericArg>,
@@ -78,6 +78,8 @@ struct WipGoalEvaluation<I: Interner> {
7878
pub result: Option<QueryResult<I>>,
7979
}
8080

81+
impl<I: Interner> Eq for WipGoalEvaluation<I> {}
82+
8183
impl<I: Interner> WipGoalEvaluation<I> {
8284
fn finalize(self) -> inspect::GoalEvaluation<I> {
8385
inspect::GoalEvaluation {
@@ -98,7 +100,7 @@ impl<I: Interner> WipGoalEvaluation<I> {
98100
/// This only exists during proof tree building and does not have
99101
/// a corresponding struct in `inspect`. We need this to track a
100102
/// bunch of metadata about the current evaluation.
101-
#[derive_where(PartialEq, Eq, Debug; I: Interner)]
103+
#[derive_where(PartialEq, Debug; I: Interner)]
102104
struct WipCanonicalGoalEvaluationStep<I: Interner> {
103105
/// Unlike `EvalCtxt::var_values`, we append a new
104106
/// generic arg here whenever we create a new inference
@@ -111,6 +113,8 @@ struct WipCanonicalGoalEvaluationStep<I: Interner> {
111113
evaluation: WipProbe<I>,
112114
}
113115

116+
impl<I: Interner> Eq for WipCanonicalGoalEvaluationStep<I> {}
117+
114118
impl<I: Interner> WipCanonicalGoalEvaluationStep<I> {
115119
fn current_evaluation_scope(&mut self) -> &mut WipProbe<I> {
116120
let mut current = &mut self.evaluation;
@@ -132,14 +136,16 @@ impl<I: Interner> WipCanonicalGoalEvaluationStep<I> {
132136
}
133137
}
134138

135-
#[derive_where(PartialEq, Eq, Debug; I: Interner)]
139+
#[derive_where(PartialEq, Debug; I: Interner)]
136140
struct WipProbe<I: Interner> {
137141
initial_num_var_values: usize,
138142
steps: Vec<WipProbeStep<I>>,
139143
kind: Option<inspect::ProbeKind<I>>,
140144
final_state: Option<inspect::CanonicalState<I, ()>>,
141145
}
142146

147+
impl<I: Interner> Eq for WipProbe<I> {}
148+
143149
impl<I: Interner> WipProbe<I> {
144150
fn finalize(self) -> inspect::Probe<I> {
145151
inspect::Probe {
@@ -150,14 +156,16 @@ impl<I: Interner> WipProbe<I> {
150156
}
151157
}
152158

153-
#[derive_where(PartialEq, Eq, Debug; I: Interner)]
159+
#[derive_where(PartialEq, Debug; I: Interner)]
154160
enum WipProbeStep<I: Interner> {
155161
AddGoal(GoalSource, inspect::CanonicalState<I, Goal<I, I::Predicate>>),
156162
NestedProbe(WipProbe<I>),
157163
MakeCanonicalResponse { shallow_certainty: Certainty },
158164
RecordImplArgs { impl_args: inspect::CanonicalState<I, I::GenericArgs> },
159165
}
160166

167+
impl<I: Interner> Eq for WipProbeStep<I> {}
168+
161169
impl<I: Interner> WipProbeStep<I> {
162170
fn finalize(self) -> inspect::ProbeStep<I> {
163171
match self {

compiler/rustc_type_ir/src/binder.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::fmt::Debug;
2-
use std::hash::Hash;
31
use std::marker::PhantomData;
42
use std::ops::{ControlFlow, Deref};
53

@@ -23,18 +21,16 @@ use crate::{self as ty, Interner};
2321
/// for more details.
2422
///
2523
/// `Decodable` and `Encodable` are implemented for `Binder<T>` using the `impl_binder_encode_decode!` macro.
26-
#[derive_where(Clone; I: Interner, T: Clone)]
24+
#[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, T)]
2725
#[derive_where(Copy; I: Interner, T: Copy)]
28-
#[derive_where(Hash; I: Interner, T: Hash)]
29-
#[derive_where(PartialEq; I: Interner, T: PartialEq)]
30-
#[derive_where(Eq; I: Interner, T: Eq)]
31-
#[derive_where(Debug; I: Interner, T: Debug)]
3226
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
3327
pub struct Binder<I: Interner, T> {
3428
value: T,
3529
bound_vars: I::BoundVarKinds,
3630
}
3731

32+
impl<I: Interner, T: Eq> Eq for Binder<I, T> {}
33+
3834
// FIXME: We manually derive `Lift` because the `derive(Lift_Generic)` doesn't
3935
// understand how to turn `T` to `T::Lifted` in the output `type Lifted`.
4036
impl<I: Interner, U: Interner, T> Lift<U> for Binder<I, T>
@@ -356,14 +352,9 @@ impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
356352
/// `instantiate`.
357353
///
358354
/// See <https://rustc-dev-guide.rust-lang.org/ty_module/early_binder.html> for more details.
359-
#[derive_where(Clone; I: Interner, T: Clone)]
360-
#[derive_where(Copy; I: Interner, T: Copy)]
361-
#[derive_where(PartialEq; I: Interner, T: PartialEq)]
362-
#[derive_where(Eq; I: Interner, T: Eq)]
363-
#[derive_where(Ord; I: Interner, T: Ord)]
355+
#[derive_where(Clone, PartialEq, Ord, Hash, Debug; I: Interner, T)]
364356
#[derive_where(PartialOrd; I: Interner, T: Ord)]
365-
#[derive_where(Hash; I: Interner, T: Hash)]
366-
#[derive_where(Debug; I: Interner, T: Debug)]
357+
#[derive_where(Copy; I: Interner, T: Copy)]
367358
#[cfg_attr(
368359
feature = "nightly",
369360
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
@@ -374,6 +365,8 @@ pub struct EarlyBinder<I: Interner, T> {
374365
_tcx: PhantomData<fn() -> I>,
375366
}
376367

368+
impl<I: Interner, T: Eq> Eq for EarlyBinder<I, T> {}
369+
377370
/// For early binders, you should first call `instantiate` before using any visitors.
378371
#[cfg(feature = "nightly")]
379372
impl<I: Interner, T> !TypeFoldable<I> for ty::EarlyBinder<I, T> {}

compiler/rustc_type_ir/src/canonical.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ use crate::data_structures::HashMap;
1111
use crate::inherent::*;
1212
use crate::{self as ty, Interner, TypingMode, UniverseIndex};
1313

14-
#[derive_where(Clone; I: Interner, V: Clone)]
15-
#[derive_where(Hash; I: Interner, V: Hash)]
16-
#[derive_where(PartialEq; I: Interner, V: PartialEq)]
17-
#[derive_where(Eq; I: Interner, V: Eq)]
18-
#[derive_where(Debug; I: Interner, V: fmt::Debug)]
14+
#[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, V)]
1915
#[derive_where(Copy; I: Interner, V: Copy)]
2016
#[cfg_attr(
2117
feature = "nightly",
@@ -26,14 +22,12 @@ pub struct CanonicalQueryInput<I: Interner, V> {
2622
pub typing_mode: TypingMode<I>,
2723
}
2824

25+
impl<I: Interner, V: Eq> Eq for CanonicalQueryInput<I, V> {}
26+
2927
/// A "canonicalized" type `V` is one where all free inference
3028
/// variables have been rewritten to "canonical vars". These are
3129
/// numbered starting from 0 in order of first appearance.
32-
#[derive_where(Clone; I: Interner, V: Clone)]
33-
#[derive_where(Hash; I: Interner, V: Hash)]
34-
#[derive_where(PartialEq; I: Interner, V: PartialEq)]
35-
#[derive_where(Eq; I: Interner, V: Eq)]
36-
#[derive_where(Debug; I: Interner, V: fmt::Debug)]
30+
#[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, V)]
3731
#[derive_where(Copy; I: Interner, V: Copy)]
3832
#[cfg_attr(
3933
feature = "nightly",
@@ -45,6 +39,8 @@ pub struct Canonical<I: Interner, V> {
4539
pub variables: I::CanonicalVarKinds,
4640
}
4741

42+
impl<I: Interner, V: Eq> Eq for Canonical<I, V> {}
43+
4844
impl<I: Interner, V> Canonical<I, V> {
4945
/// Allows you to map the `value` of a canonical while keeping the
5046
/// same set of bound variables.
@@ -89,7 +85,7 @@ impl<I: Interner, V: fmt::Display> fmt::Display for Canonical<I, V> {
8985
/// canonical value. This is sufficient information for code to create
9086
/// a copy of the canonical value in some other inference context,
9187
/// with fresh inference variables replacing the canonical values.
92-
#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)]
88+
#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)]
9389
#[cfg_attr(
9490
feature = "nightly",
9591
derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext)
@@ -116,6 +112,8 @@ pub enum CanonicalVarKind<I: Interner> {
116112
PlaceholderConst(I::PlaceholderConst),
117113
}
118114

115+
impl<I: Interner> Eq for CanonicalVarKind<I> {}
116+
119117
impl<I: Interner> CanonicalVarKind<I> {
120118
pub fn universe(self) -> UniverseIndex {
121119
match self {
@@ -223,7 +221,7 @@ pub enum CanonicalTyVarKind {
223221
/// vectors with the original values that were replaced by canonical
224222
/// variables. You will need to supply it later to instantiate the
225223
/// canonicalized query response.
226-
#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)]
224+
#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)]
227225
#[cfg_attr(
228226
feature = "nightly",
229227
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
@@ -233,6 +231,8 @@ pub struct CanonicalVarValues<I: Interner> {
233231
pub var_values: I::GenericArgs,
234232
}
235233

234+
impl<I: Interner> Eq for CanonicalVarValues<I> {}
235+
236236
impl<I: Interner> CanonicalVarValues<I> {
237237
pub fn is_identity(&self) -> bool {
238238
self.var_values.iter().enumerate().all(|(bv, arg)| match arg.kind() {

compiler/rustc_type_ir/src/const_kind.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Gen
1010
use crate::{self as ty, DebruijnIndex, Interner};
1111

1212
/// Represents a constant in Rust.
13-
#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)]
13+
#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)]
1414
#[cfg_attr(
1515
feature = "nightly",
1616
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
@@ -45,6 +45,8 @@ pub enum ConstKind<I: Interner> {
4545
Expr(I::ExprConst),
4646
}
4747

48+
impl<I: Interner> Eq for ConstKind<I> {}
49+
4850
impl<I: Interner> fmt::Debug for ConstKind<I> {
4951
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5052
use ConstKind::*;
@@ -63,7 +65,7 @@ impl<I: Interner> fmt::Debug for ConstKind<I> {
6365
}
6466

6567
/// An unevaluated (potentially generic) constant used in the type-system.
66-
#[derive_where(Clone, Copy, Debug, Hash, PartialEq, Eq; I: Interner)]
68+
#[derive_where(Clone, Copy, Debug, Hash, PartialEq; I: Interner)]
6769
#[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)]
6870
#[cfg_attr(
6971
feature = "nightly",
@@ -74,6 +76,8 @@ pub struct UnevaluatedConst<I: Interner> {
7476
pub args: I::GenericArgs,
7577
}
7678

79+
impl<I: Interner> Eq for UnevaluatedConst<I> {}
80+
7781
impl<I: Interner> UnevaluatedConst<I> {
7882
#[inline]
7983
pub fn new(def: I::DefId, args: I::GenericArgs) -> UnevaluatedConst<I> {

compiler/rustc_type_ir/src/error.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl<T> ExpectedFound<T> {
1818
}
1919

2020
// Data structures used in type unification
21-
#[derive_where(Clone, Copy, PartialEq, Eq, Debug; I: Interner)]
21+
#[derive_where(Clone, Copy, PartialEq, Debug; I: Interner)]
2222
#[derive(TypeVisitable_Generic)]
2323
#[cfg_attr(feature = "nightly", rustc_pass_by_value)]
2424
pub enum TypeError<I: Interner> {
@@ -58,6 +58,8 @@ pub enum TypeError<I: Interner> {
5858
TargetFeatureCast(I::DefId),
5959
}
6060

61+
impl<I: Interner> Eq for TypeError<I> {}
62+
6163
impl<I: Interner> TypeError<I> {
6264
pub fn involves_regions(self) -> bool {
6365
match self {

compiler/rustc_type_ir/src/generic_arg.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContex
44

55
use crate::Interner;
66

7-
#[derive_where(Clone, Copy, PartialEq, Eq, Debug; I: Interner)]
7+
#[derive_where(Clone, Copy, PartialEq, Debug; I: Interner)]
88
#[cfg_attr(
99
feature = "nightly",
1010
derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext)
@@ -15,7 +15,9 @@ pub enum GenericArgKind<I: Interner> {
1515
Const(I::Const),
1616
}
1717

18-
#[derive_where(Clone, Copy, PartialEq, Eq, Debug; I: Interner)]
18+
impl<I: Interner> Eq for GenericArgKind<I> {}
19+
20+
#[derive_where(Clone, Copy, PartialEq, Debug; I: Interner)]
1921
#[cfg_attr(
2022
feature = "nightly",
2123
derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext)
@@ -24,3 +26,5 @@ pub enum TermKind<I: Interner> {
2426
Ty(I::Ty),
2527
Const(I::Const),
2628
}
29+
30+
impl<I: Interner> Eq for TermKind<I> {}

compiler/rustc_type_ir/src/infer_ctxt.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{self as ty, Interner};
1818
///
1919
/// If neither of these functions are available, feel free to reach out to
2020
/// t-types for help.
21-
#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)]
21+
#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)]
2222
#[cfg_attr(
2323
feature = "nightly",
2424
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
@@ -90,6 +90,8 @@ pub enum TypingMode<I: Interner> {
9090
PostAnalysis,
9191
}
9292

93+
impl<I: Interner> Eq for TypingMode<I> {}
94+
9395
impl<I: Interner> TypingMode<I> {
9496
/// Analysis outside of a body does not define any opaque types.
9597
pub fn non_body_analysis() -> TypingMode<I> {

compiler/rustc_type_ir/src/opaque_ty.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_type_ir_macros::{TypeFoldable_Generic, TypeVisitable_Generic};
66
use crate::inherent::*;
77
use crate::{self as ty, Interner};
88

9-
#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)]
9+
#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)]
1010
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
1111
#[cfg_attr(
1212
feature = "nightly",
@@ -17,6 +17,8 @@ pub struct OpaqueTypeKey<I: Interner> {
1717
pub args: I::GenericArgs,
1818
}
1919

20+
impl<I: Interner> Eq for OpaqueTypeKey<I> {}
21+
2022
impl<I: Interner> OpaqueTypeKey<I> {
2123
pub fn iter_captured_args(self, cx: I) -> impl Iterator<Item = (usize, I::GenericArg)> {
2224
let variances = cx.variances_of(self.def_id.into());

compiler/rustc_type_ir/src/pattern.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Gen
55

66
use crate::Interner;
77

8-
#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)]
8+
#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)]
99
#[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)]
1010
#[cfg_attr(
1111
feature = "nightly",
@@ -15,3 +15,5 @@ pub enum PatternKind<I: Interner> {
1515
Range { start: I::Const, end: I::Const },
1616
Or(I::PatList),
1717
}
18+
19+
impl<I: Interner> Eq for PatternKind<I> {}

0 commit comments

Comments
 (0)