make rustc_public types derive Hash

This commit is contained in:
AlexanderPortland 2025-08-06 12:02:38 -07:00
parent dc0bae1db7
commit 56d5aab31d
2 changed files with 42 additions and 32 deletions

View file

@ -349,7 +349,7 @@ impl AssertMessage {
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum BinOp {
Add,
AddUnchecked,
@ -384,7 +384,7 @@ impl BinOp {
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum UnOp {
Not,
Neg,
@ -490,7 +490,7 @@ pub enum StatementKind {
Nop,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum Rvalue {
/// Creates a pointer with the indicated mutability to the place.
///
@ -666,7 +666,7 @@ impl Rvalue {
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum AggregateKind {
Array(Ty),
Tuple,
@ -677,14 +677,14 @@ pub enum AggregateKind {
RawPtr(Ty, Mutability),
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum Operand {
Copy(Place),
Move(Place),
Constant(ConstOperand),
}
#[derive(Clone, Eq, PartialEq, Serialize)]
#[derive(Clone, Eq, PartialEq, Hash, Serialize)]
pub struct Place {
pub local: Local,
/// projection out of a place (access a field, deref a pointer, etc)
@ -697,7 +697,7 @@ impl From<Local> for Place {
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub struct ConstOperand {
pub span: Span,
pub user_ty: Option<UserTypeAnnotationIndex>,
@ -770,7 +770,7 @@ pub enum VarDebugInfoContents {
// ProjectionElem<Local, Ty>) and user-provided type annotations (for which the projection elements
// are of type ProjectionElem<(), ()>).
// In rustc_public's IR we don't need this generality, so we just use ProjectionElem for Places.
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum ProjectionElem {
/// Dereference projections (e.g. `*_1`) project to the address referenced by the base place.
Deref,
@ -913,7 +913,7 @@ impl SwitchTargets {
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum BorrowKind {
/// Data must be immutable and is aliasable.
Shared,
@ -940,7 +940,7 @@ impl BorrowKind {
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum RawPtrKind {
Mut,
Const,
@ -958,14 +958,14 @@ impl RawPtrKind {
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum MutBorrowKind {
Default,
TwoPhaseBorrow,
ClosureCapture,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum FakeBorrowKind {
/// A shared (deep) borrow. Data must be immutable and is aliasable.
Deep,
@ -982,13 +982,13 @@ pub enum Mutability {
Mut,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum Safety {
Safe,
Unsafe,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum PointerCoercion {
/// Go from a fn-item type to a fn-pointer type.
ReifyFnPointer,
@ -1015,7 +1015,7 @@ pub enum PointerCoercion {
Unsize,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum CastKind {
// FIXME(smir-rename): rename this to PointerExposeProvenance
PointerExposeAddress,
@ -1030,7 +1030,7 @@ pub enum CastKind {
Transmute,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum NullOp {
/// Returns the size of a value of that type.
SizeOf,

View file

@ -113,7 +113,7 @@ pub enum Pattern {
}
/// Represents a constant in the type system
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub struct TyConst {
pub(crate) kind: TyConstKind,
pub id: TyConstId,
@ -140,7 +140,7 @@ impl TyConst {
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum TyConstKind {
Param(ParamConst),
Bound(DebruijnIndex, BoundVar),
@ -151,11 +151,11 @@ pub enum TyConstKind {
ZSTValue(Ty),
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub struct TyConstId(usize);
/// Represents a constant in MIR
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub struct MirConst {
/// The constant kind.
pub(crate) kind: ConstantKind,
@ -212,17 +212,17 @@ impl MirConst {
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize)]
pub struct MirConstId(usize);
type Ident = Opaque;
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub struct Region {
pub kind: RegionKind,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum RegionKind {
ReEarlyParam(EarlyParamRegion),
ReBound(DebruijnIndex, BoundRegion),
@ -233,7 +233,7 @@ pub enum RegionKind {
pub(crate) type DebruijnIndex = u32;
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub struct EarlyParamRegion {
pub index: u32,
pub name: Symbol,
@ -241,7 +241,7 @@ pub struct EarlyParamRegion {
pub(crate) type BoundVar = u32;
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub struct BoundRegion {
pub var: BoundVar,
pub kind: BoundRegionKind,
@ -255,7 +255,17 @@ pub struct Placeholder<T> {
pub bound: T,
}
#[derive(Clone, Copy, PartialEq, Eq, Serialize)]
impl<T: std::hash::Hash> std::hash::Hash for Placeholder<T> {
fn hash<H>(&self, state: &mut H)
where
H: std::hash::Hasher,
{
self.universe.hash(state);
self.bound.hash(state);
}
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, Serialize)]
pub struct Span(usize);
impl Debug for Span {
@ -997,7 +1007,7 @@ crate_def! {
}
/// A list of generic arguments.
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub struct GenericArgs(pub Vec<GenericArgKind>);
impl std::ops::Index<ParamTy> for GenericArgs {
@ -1016,7 +1026,7 @@ impl std::ops::Index<ParamConst> for GenericArgs {
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum GenericArgKind {
Lifetime(Region),
Type(Ty),
@ -1199,7 +1209,7 @@ pub enum BoundTyKind {
Param(ParamDef, String),
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum BoundRegionKind {
BrAnon,
BrNamed(BrNamedDef, String),
@ -1354,7 +1364,7 @@ impl Allocation {
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum ConstantKind {
Ty(TyConst),
Allocated(Allocation),
@ -1365,13 +1375,13 @@ pub enum ConstantKind {
ZeroSized,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub struct ParamConst {
pub index: u32,
pub name: String,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub struct UnevaluatedConst {
pub def: ConstDef,
pub args: GenericArgs,