Skip to content

Commit 61f73e8

Browse files
committed
Reduce derive(HashStable_NoContext).
Thanks to the `HashStable` trait being simplified, `HashStable_NoContext` is only needed when a (near) perfect derive is required. In practice, this means it's only needed for types with a generic `<I: Interner>` parameter. This commit replaces `derive(HashStable_NoContext)` with `derive(HashStable)` for all types that don't have `<I: Interner>`.
1 parent 760b474 commit 61f73e8

12 files changed

Lines changed: 40 additions & 85 deletions

File tree

compiler/rustc_ast_ir/src/lib.rs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@
1414
use std::fmt;
1515

1616
#[cfg(feature = "nightly")]
17-
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
17+
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable};
1818
#[cfg(feature = "nightly")]
1919
use rustc_span::{Symbol, sym};
2020

2121
pub mod visit;
2222

2323
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
24-
#[cfg_attr(
25-
feature = "nightly",
26-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
27-
)]
24+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
2825
pub enum IntTy {
2926
Isize,
3027
I8,
@@ -100,10 +97,7 @@ impl fmt::Debug for IntTy {
10097
}
10198

10299
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
103-
#[cfg_attr(
104-
feature = "nightly",
105-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
106-
)]
100+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
107101
pub enum UintTy {
108102
Usize,
109103
U8,
@@ -179,10 +173,7 @@ impl fmt::Debug for UintTy {
179173
}
180174

181175
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
182-
#[cfg_attr(
183-
feature = "nightly",
184-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
185-
)]
176+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
186177
pub enum FloatTy {
187178
F16,
188179
F32,
@@ -229,10 +220,7 @@ impl fmt::Debug for FloatTy {
229220
/// The movability of a coroutine / closure literal:
230221
/// whether a coroutine contains self-references, causing it to be `!Unpin`.
231222
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
232-
#[cfg_attr(
233-
feature = "nightly",
234-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
235-
)]
223+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
236224
pub enum Movability {
237225
/// May contain self-references, `!Unpin`.
238226
Static,
@@ -241,10 +229,7 @@ pub enum Movability {
241229
}
242230

243231
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
244-
#[cfg_attr(
245-
feature = "nightly",
246-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
247-
)]
232+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
248233
pub enum Mutability {
249234
// N.B. Order is deliberate, so that Not < Mut
250235
Not,
@@ -303,10 +288,7 @@ impl Mutability {
303288
}
304289

305290
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
306-
#[cfg_attr(
307-
feature = "nightly",
308-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
309-
)]
291+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
310292
pub enum Pinnedness {
311293
Not,
312294
Pinned,

compiler/rustc_data_structures/src/sorted_map/index_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::hash::{Hash, Hasher};
44

55
use rustc_index::{Idx, IndexVec};
6-
use rustc_macros::HashStable_NoContext;
6+
use rustc_macros::HashStable;
77

88
/// An indexed multi-map that preserves insertion order while permitting both *O*(log *n*) lookup of
99
/// an item by key and *O*(1) lookup by index.
@@ -23,7 +23,7 @@ use rustc_macros::HashStable_NoContext;
2323
/// in-place.
2424
///
2525
/// [`SortedMap`]: super::SortedMap
26-
#[derive(Clone, Debug, HashStable_NoContext)]
26+
#[derive(Clone, Debug, HashStable)]
2727
pub struct SortedIndexMultiMap<I: Idx, K, V> {
2828
/// The elements of the map in insertion order.
2929
items: IndexVec<I, (K, V)>,

compiler/rustc_data_structures/src/svh.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
use std::fmt;
99

10-
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
10+
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable};
1111

1212
use crate::fingerprint::Fingerprint;
1313

@@ -20,7 +20,7 @@ use crate::fingerprint::Fingerprint;
2020
Encodable_NoContext,
2121
Decodable_NoContext,
2222
Hash,
23-
HashStable_NoContext
23+
HashStable
2424
)]
2525
pub struct Svh {
2626
hash: Fingerprint,

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::mem;
22
use std::ops::ControlFlow;
33

44
#[cfg(feature = "nightly")]
5-
use rustc_macros::HashStable_NoContext;
5+
use rustc_macros::HashStable;
66
use rustc_type_ir::data_structures::{HashMap, HashSet};
77
use rustc_type_ir::inherent::*;
88
use rustc_type_ir::relate::Relate;
@@ -137,7 +137,7 @@ where
137137
}
138138

139139
#[derive(PartialEq, Eq, Debug, Hash, Clone, Copy)]
140-
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
140+
#[cfg_attr(feature = "nightly", derive(HashStable))]
141141
pub enum GenerateProofTree {
142142
Yes,
143143
No,

compiler/rustc_type_ir/src/binder.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::ops::{ControlFlow, Deref};
55

66
use derive_where::derive_where;
77
#[cfg(feature = "nightly")]
8-
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
8+
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable, HashStable_NoContext};
99
use rustc_type_ir_macros::{
1010
GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic,
1111
};
@@ -951,10 +951,7 @@ impl<'a, I: Interner> ArgFolder<'a, I> {
951951
/// solver, canonicalization is hot and there are some pathological cases where
952952
/// this is needed (`post-mono-higher-ranked-hang`).
953953
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
954-
#[cfg_attr(
955-
feature = "nightly",
956-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
957-
)]
954+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
958955
#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)]
959956
pub enum BoundVarIndexKind {
960957
Bound(DebruijnIndex),
@@ -1009,7 +1006,6 @@ where
10091006
feature = "nightly",
10101007
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
10111008
)]
1012-
10131009
pub enum BoundRegionKind<I: Interner> {
10141010
/// An anonymous region parameter for a given fn (&T)
10151011
Anon,

compiler/rustc_type_ir/src/const_kind.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use derive_where::derive_where;
44
#[cfg(feature = "nightly")]
55
use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher};
66
#[cfg(feature = "nightly")]
7-
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
7+
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable, HashStable_NoContext};
88
use rustc_type_ir_macros::{
99
GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic,
1010
};
@@ -201,10 +201,7 @@ impl<I: Interner> ValTreeKind<I> {
201201
}
202202

203203
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
204-
#[cfg_attr(
205-
feature = "nightly",
206-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
207-
)]
204+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
208205
pub enum AnonConstKind {
209206
/// `feature(generic_const_exprs)` anon consts are allowed to use arbitrary generic parameters in scope
210207
GCE,

compiler/rustc_type_ir/src/fast_reject.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,15 @@ use rustc_data_structures::stable_hasher::{
1111
HashStable, HashStableContext, StableHasher, ToStableHashKey,
1212
};
1313
#[cfg(feature = "nightly")]
14-
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
14+
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable};
1515

1616
use crate::inherent::*;
1717
use crate::visit::TypeVisitableExt as _;
1818
use crate::{self as ty, Interner};
1919

2020
/// See `simplify_type`.
2121
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
22-
#[cfg_attr(
23-
feature = "nightly",
24-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
25-
)]
22+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
2623
pub enum SimplifiedType<DefId> {
2724
Bool,
2825
Char,

compiler/rustc_type_ir/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::hash::Hash;
1515

1616
use rustc_abi::{FieldIdx, VariantIdx};
1717
#[cfg(feature = "nightly")]
18-
use rustc_macros::{Decodable, Encodable, HashStable_NoContext};
18+
use rustc_macros::{Decodable, Encodable, HashStable};
1919

2020
// These modules are `pub` since they are not glob-imported.
2121
pub mod data_structures;
@@ -219,7 +219,7 @@ pub fn debug_bound_var<T: std::fmt::Write>(
219219
}
220220

221221
#[derive(Copy, Clone, PartialEq, Eq, Hash, GenericTypeVisitable)]
222-
#[cfg_attr(feature = "nightly", derive(Decodable, Encodable, HashStable_NoContext))]
222+
#[cfg_attr(feature = "nightly", derive(Decodable, Encodable, HashStable))]
223223
#[cfg_attr(feature = "nightly", rustc_pass_by_value)]
224224
pub enum Variance {
225225
Covariant, // T<A> <: T<B> iff A <: B -- e.g., function return type
@@ -405,7 +405,7 @@ rustc_index::newtype_index! {
405405
/// You can get the environment type of a closure using
406406
/// `tcx.closure_env_ty()`.
407407
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
408-
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
408+
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable))]
409409
pub enum ClosureKind {
410410
Fn,
411411
FnMut,

compiler/rustc_type_ir/src/predicate.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use std::{fmt, iter};
44
use derive_where::derive_where;
55
#[cfg(feature = "nightly")]
66
use rustc_macros::{
7-
Decodable, Decodable_NoContext, Encodable, Encodable_NoContext, HashStable_NoContext,
7+
Decodable, Decodable_NoContext, Encodable, Encodable_NoContext, HashStable,
8+
HashStable_NoContext,
89
};
910
use rustc_type_ir_macros::{
1011
GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic,
@@ -272,10 +273,7 @@ impl<I: Interner> fmt::Debug for TraitPredicate<I> {
272273
}
273274

274275
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
275-
#[cfg_attr(
276-
feature = "nightly",
277-
derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext)
278-
)]
276+
#[cfg_attr(feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable))]
279277
pub enum ImplPolarity {
280278
/// `impl Trait for Type`
281279
Positive,
@@ -315,10 +313,7 @@ impl ImplPolarity {
315313
/// Distinguished from [`ImplPolarity`] since we never compute goals with
316314
/// "reservation" level.
317315
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
318-
#[cfg_attr(
319-
feature = "nightly",
320-
derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext)
321-
)]
316+
#[cfg_attr(feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable))]
322317
pub enum PredicatePolarity {
323318
/// `Type: Trait`
324319
Positive,
@@ -563,7 +558,7 @@ impl<I: Interner> ty::Binder<I, ExistentialProjection<I>> {
563558
}
564559

565560
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
566-
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
561+
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable))]
567562
pub enum AliasTermKind {
568563
/// A projection `<Type as Trait>::AssocType`.
569564
///
@@ -1009,10 +1004,7 @@ pub struct CoercePredicate<I: Interner> {
10091004
impl<I: Interner> Eq for CoercePredicate<I> {}
10101005

10111006
#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
1012-
#[cfg_attr(
1013-
feature = "nightly",
1014-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
1015-
)]
1007+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
10161008
pub enum BoundConstness {
10171009
/// `Type: const Trait`
10181010
///

compiler/rustc_type_ir/src/predicate_kind.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt;
22

33
use derive_where::derive_where;
44
#[cfg(feature = "nightly")]
5-
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
5+
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable, HashStable_NoContext};
66
use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic};
77

88
use crate::{self as ty, Interner};
@@ -114,10 +114,7 @@ pub enum PredicateKind<I: Interner> {
114114
impl<I: Interner> Eq for PredicateKind<I> {}
115115

116116
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
117-
#[cfg_attr(
118-
feature = "nightly",
119-
derive(HashStable_NoContext, Encodable_NoContext, Decodable_NoContext)
120-
)]
117+
#[cfg_attr(feature = "nightly", derive(HashStable, Encodable_NoContext, Decodable_NoContext))]
121118
pub enum AliasRelationDirection {
122119
Equate,
123120
Subtype,

0 commit comments

Comments
 (0)