Skip to content

Derive Hash for rustc_public types #145018

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

Merged
merged 2 commits into from
Aug 8, 2025
Merged
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
32 changes: 16 additions & 16 deletions compiler/rustc_public/src/mir/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
///
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
34 changes: 17 additions & 17 deletions compiler/rustc_public/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand All @@ -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,
Expand Down Expand Up @@ -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),
Expand All @@ -233,29 +233,29 @@ 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,
}

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,
}

pub(crate) type UniverseIndex = u32;

#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub struct Placeholder<T> {
pub universe: UniverseIndex,
pub bound: T,
}

#[derive(Clone, Copy, PartialEq, Eq, Serialize)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, Serialize)]
pub struct Span(usize);

impl Debug for Span {
Expand Down Expand Up @@ -997,7 +997,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 {
Expand All @@ -1016,7 +1016,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),
Expand Down Expand Up @@ -1199,7 +1199,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),
Expand Down Expand Up @@ -1354,7 +1354,7 @@ impl Allocation {
}
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)]
pub enum ConstantKind {
Ty(TyConst),
Allocated(Allocation),
Expand All @@ -1365,13 +1365,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,
Expand Down
Loading