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>`.
This commit is contained in:
Nicholas Nethercote
2026-04-08 14:19:21 +10:00
parent 087b422ec7
commit f01d549c29
12 changed files with 38 additions and 84 deletions
+7 -25
View File
@@ -14,17 +14,14 @@
use std::fmt;
#[cfg(feature = "nightly")]
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable};
#[cfg(feature = "nightly")]
use rustc_span::{Symbol, sym};
pub mod visit;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
)]
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
pub enum IntTy {
Isize,
I8,
@@ -100,10 +97,7 @@ impl fmt::Debug for IntTy {
}
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
#[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
)]
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
pub enum UintTy {
Usize,
U8,
@@ -179,10 +173,7 @@ impl fmt::Debug for UintTy {
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
)]
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
pub enum FloatTy {
F16,
F32,
@@ -229,10 +220,7 @@ impl fmt::Debug for FloatTy {
/// The movability of a coroutine / closure literal:
/// whether a coroutine contains self-references, causing it to be `!Unpin`.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
#[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
)]
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
pub enum Movability {
/// May contain self-references, `!Unpin`.
Static,
@@ -241,10 +229,7 @@ pub enum Movability {
}
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
#[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
)]
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
pub enum Mutability {
// N.B. Order is deliberate, so that Not < Mut
Not,
@@ -303,10 +288,7 @@ impl Mutability {
}
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
#[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
)]
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
pub enum Pinnedness {
Not,
Pinned,
@@ -3,7 +3,7 @@
use std::hash::{Hash, Hasher};
use rustc_index::{Idx, IndexVec};
use rustc_macros::HashStable_NoContext;
use rustc_macros::HashStable;
/// An indexed multi-map that preserves insertion order while permitting both *O*(log *n*) lookup of
/// an item by key and *O*(1) lookup by index.
@@ -23,7 +23,7 @@ use rustc_macros::HashStable_NoContext;
/// in-place.
///
/// [`SortedMap`]: super::SortedMap
#[derive(Clone, Debug, HashStable_NoContext)]
#[derive(Clone, Debug, HashStable)]
pub struct SortedIndexMultiMap<I: Idx, K, V> {
/// The elements of the map in insertion order.
items: IndexVec<I, (K, V)>,
+2 -2
View File
@@ -7,7 +7,7 @@
use std::fmt;
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable};
use crate::fingerprint::Fingerprint;
@@ -20,7 +20,7 @@ use crate::fingerprint::Fingerprint;
Encodable_NoContext,
Decodable_NoContext,
Hash,
HashStable_NoContext
HashStable
)]
pub struct Svh {
hash: Fingerprint,
@@ -2,7 +2,7 @@ use std::mem;
use std::ops::ControlFlow;
#[cfg(feature = "nightly")]
use rustc_macros::HashStable_NoContext;
use rustc_macros::HashStable;
use rustc_type_ir::data_structures::{HashMap, HashSet};
use rustc_type_ir::inherent::*;
use rustc_type_ir::relate::Relate;
@@ -137,7 +137,7 @@ where
}
#[derive(PartialEq, Eq, Debug, Hash, Clone, Copy)]
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
#[cfg_attr(feature = "nightly", derive(HashStable))]
pub enum GenerateProofTree {
Yes,
No,
+2 -6
View File
@@ -5,7 +5,7 @@ use std::ops::{ControlFlow, Deref};
use derive_where::derive_where;
#[cfg(feature = "nightly")]
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable, HashStable_NoContext};
use rustc_type_ir_macros::{
GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic,
};
@@ -951,10 +951,7 @@ impl<'a, I: Interner> ArgFolder<'a, I> {
/// solver, canonicalization is hot and there are some pathological cases where
/// this is needed (`post-mono-higher-ranked-hang`).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
)]
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)]
pub enum BoundVarIndexKind {
Bound(DebruijnIndex),
@@ -1009,7 +1006,6 @@ where
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
)]
pub enum BoundRegionKind<I: Interner> {
/// An anonymous region parameter for a given fn (&T)
Anon,
+2 -5
View File
@@ -4,7 +4,7 @@ use derive_where::derive_where;
#[cfg(feature = "nightly")]
use rustc_data_structures::stable_hasher::{HashStable, HashStableContext, StableHasher};
#[cfg(feature = "nightly")]
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable, HashStable_NoContext};
use rustc_type_ir_macros::{
GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic,
};
@@ -201,10 +201,7 @@ impl<I: Interner> ValTreeKind<I> {
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
)]
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
pub enum AnonConstKind {
/// `feature(generic_const_exprs)` anon consts are allowed to use arbitrary generic parameters in scope
GCE,
+2 -5
View File
@@ -11,7 +11,7 @@ use rustc_data_structures::stable_hasher::{
HashStable, HashStableContext, StableHasher, ToStableHashKey,
};
#[cfg(feature = "nightly")]
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable};
use crate::inherent::*;
use crate::visit::TypeVisitableExt as _;
@@ -19,10 +19,7 @@ use crate::{self as ty, Interner};
/// See `simplify_type`.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
)]
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
pub enum SimplifiedType<DefId> {
Bool,
Char,
+3 -3
View File
@@ -15,7 +15,7 @@ use std::hash::Hash;
use rustc_abi::{FieldIdx, VariantIdx};
#[cfg(feature = "nightly")]
use rustc_macros::{Decodable, Encodable, HashStable_NoContext};
use rustc_macros::{Decodable, Encodable, HashStable};
// These modules are `pub` since they are not glob-imported.
pub mod data_structures;
@@ -219,7 +219,7 @@ pub fn debug_bound_var<T: std::fmt::Write>(
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, GenericTypeVisitable)]
#[cfg_attr(feature = "nightly", derive(Decodable, Encodable, HashStable_NoContext))]
#[cfg_attr(feature = "nightly", derive(Decodable, Encodable, HashStable))]
#[cfg_attr(feature = "nightly", rustc_pass_by_value)]
pub enum Variance {
Covariant, // T<A> <: T<B> iff A <: B -- e.g., function return type
@@ -405,7 +405,7 @@ rustc_index::newtype_index! {
/// You can get the environment type of a closure using
/// `tcx.closure_env_ty()`.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable))]
pub enum ClosureKind {
Fn,
FnMut,
+4 -13
View File
@@ -3,7 +3,7 @@ use std::{fmt, iter};
use derive_where::derive_where;
#[cfg(feature = "nightly")]
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable, HashStable_NoContext};
use rustc_type_ir_macros::{
GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic,
};
@@ -270,10 +270,7 @@ impl<I: Interner> fmt::Debug for TraitPredicate<I> {
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[cfg_attr(
feature = "nightly",
derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext)
)]
#[cfg_attr(feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable))]
pub enum ImplPolarity {
/// `impl Trait for Type`
Positive,
@@ -313,10 +310,7 @@ impl ImplPolarity {
/// Distinguished from [`ImplPolarity`] since we never compute goals with
/// "reservation" level.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[cfg_attr(
feature = "nightly",
derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext)
)]
#[cfg_attr(feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable))]
pub enum PredicatePolarity {
/// `Type: Trait`
Positive,
@@ -1054,10 +1048,7 @@ pub struct CoercePredicate<I: Interner> {
impl<I: Interner> Eq for CoercePredicate<I> {}
#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
#[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
)]
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
pub enum BoundConstness {
/// `Type: const Trait`
///
+2 -5
View File
@@ -2,7 +2,7 @@ use std::fmt;
use derive_where::derive_where;
#[cfg(feature = "nightly")]
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable, HashStable_NoContext};
use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic};
use crate::{self as ty, Interner};
@@ -114,10 +114,7 @@ pub enum PredicateKind<I: Interner> {
impl<I: Interner> Eq for PredicateKind<I> {}
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
#[cfg_attr(
feature = "nightly",
derive(HashStable_NoContext, Encodable_NoContext, Decodable_NoContext)
)]
#[cfg_attr(feature = "nightly", derive(HashStable, Encodable_NoContext, Decodable_NoContext))]
pub enum AliasRelationDirection {
Equate,
Subtype,
@@ -21,7 +21,7 @@ use std::marker::PhantomData;
use derive_where::derive_where;
#[cfg(feature = "nightly")]
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable};
use rustc_type_ir::data_structures::HashMap;
use tracing::{debug, instrument, trace};
@@ -118,10 +118,7 @@ pub trait Delegate: Sized {
/// result. In the case we return an initial provisional result depending
/// on the kind of cycle.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(
feature = "nightly",
derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext)
)]
#[cfg_attr(feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable))]
pub enum PathKind {
/// A path consisting of only inductive/unproductive steps. Their initial
/// provisional result is `Err(NoSolution)`. We currently treat them as
+8 -11
View File
@@ -4,7 +4,7 @@ use std::hash::Hash;
use derive_where::derive_where;
#[cfg(feature = "nightly")]
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable, HashStable_NoContext};
use rustc_type_ir_macros::{
GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic,
};
@@ -25,7 +25,7 @@ pub type CanonicalResponse<I> = Canonical<I, Response<I>>;
pub type QueryResult<I> = Result<CanonicalResponse<I>, NoSolution>;
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
#[cfg_attr(feature = "nightly", derive(HashStable))]
pub struct NoSolution;
/// A goal is a statement, i.e. `predicate`, we want to prove
@@ -67,7 +67,7 @@ impl<I: Interner, P> Goal<I, P> {
///
/// It is also used by proof tree visitors, e.g. for diagnostics purposes.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
#[cfg_attr(feature = "nightly", derive(HashStable))]
pub enum GoalSource {
Misc,
/// A nested goal required to prove that types are equal/subtypes.
@@ -217,10 +217,7 @@ pub enum AliasBoundKind {
}
#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
#[cfg_attr(
feature = "nightly",
derive(HashStable_NoContext, Encodable_NoContext, Decodable_NoContext)
)]
#[cfg_attr(feature = "nightly", derive(HashStable, Encodable_NoContext, Decodable_NoContext))]
pub enum BuiltinImplSource {
/// A built-in impl that is considered trivial, without any nested requirements. They
/// are preferred over where-clauses, and we want to track them explicitly.
@@ -286,7 +283,7 @@ impl<I: Interner> NestedNormalizationGoals<I> {
}
#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
#[cfg_attr(feature = "nightly", derive(HashStable))]
pub enum Certainty {
Yes,
Maybe(MaybeInfo),
@@ -353,7 +350,7 @@ impl MaybeInfo {
/// a goal. It is good enough for now and only matters for very rare type inference
/// edge cases. We can improve this later on if necessary.
#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
#[cfg_attr(feature = "nightly", derive(HashStable))]
pub enum OpaqueTypesJank {
AllGood,
ErrorIfRigidSelfTy,
@@ -442,7 +439,7 @@ impl Certainty {
/// Why we failed to evaluate a goal.
#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
#[cfg_attr(feature = "nightly", derive(HashStable))]
pub enum MaybeCause {
/// We failed due to ambiguity. This ambiguity can either
/// be a true ambiguity, i.e. there are multiple different answers,
@@ -515,7 +512,7 @@ pub enum AdtDestructorKind {
/// Which sizedness trait - `Sized`, `MetaSized`? `PointeeSized` is omitted as it is removed during
/// lowering.
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
#[cfg_attr(feature = "nightly", derive(HashStable))]
pub enum SizedTraitKind {
/// `Sized` trait
Sized,