Skip to content

Commit

Permalink
uwu
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Markeffsky committed Feb 7, 2025
1 parent 79f82ad commit bc51bb2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
14 changes: 12 additions & 2 deletions compiler/rustc_middle/src/ty/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ impl<'tcx> rustc_type_ir::inherent::IntoKind for Const<'tcx> {
}
}

impl<'tcx> rustc_type_ir::inherent::IntoKindRef for Const<'tcx> {
fn kind_ref(&self) -> &ConstKind<'tcx> {
(*self).kind_ref()
}
}

impl<'tcx> rustc_type_ir::visit::Flags for Const<'tcx> {
fn flags(&self) -> TypeFlags {
self.0.flags
Expand All @@ -47,8 +53,12 @@ impl<'tcx> rustc_type_ir::visit::Flags for Const<'tcx> {
impl<'tcx> Const<'tcx> {
#[inline]
pub fn kind(self) -> ConstKind<'tcx> {
let a: &ConstKind<'tcx> = self.0.0;
*a
*self.kind_ref()
}

#[inline]
pub fn kind_ref(self) -> &'tcx ConstKind<'tcx> {
self.0.0
}

// FIXME(compiler-errors): Think about removing this.
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/ty/consts/valtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ impl<'tcx> Value<'tcx> {
}

impl<'tcx> rustc_type_ir::inherent::ValueConst<TyCtxt<'tcx>> for Value<'tcx> {
fn ty(self) -> Ty<'tcx> {
fn ty(&self) -> Ty<'tcx> {
self.ty
}

fn valtree(self) -> ValTree<'tcx> {
self.valtree
fn valtree(&self) -> &ValTree<'tcx> {
&self.valtree
}
}
14 changes: 8 additions & 6 deletions compiler/rustc_type_ir/src/fast_reject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ impl<I: Interner, const INSTANTIATE_LHS_WITH_INFER: bool, const INSTANTIATE_RHS_
// Unlike `types_may_unify_inner`, this does not take a depth as
// we never recurse from this function.
fn consts_may_unify_inner(self, lhs: I::Const, rhs: I::Const) -> bool {
match rhs.kind() {
let rhs_kind = rhs.kind_ref();
match *rhs_kind {
ty::ConstKind::Param(_) => {
if INSTANTIATE_RHS_WITH_INFER {
return true;
Expand All @@ -482,23 +483,24 @@ impl<I: Interner, const INSTANTIATE_LHS_WITH_INFER: bool, const INSTANTIATE_RHS_
ty::ConstKind::Value(..) | ty::ConstKind::Placeholder(_) => {}
};

match lhs.kind() {
ty::ConstKind::Value(lhs_val) => match rhs.kind() {
ty::ConstKind::Value(rhs_val) => lhs_val.valtree() == rhs_val.valtree(),
let lhs_kind = lhs.kind_ref();
match *lhs_kind {
ty::ConstKind::Value(ref lhs_val) => match *rhs_kind {
ty::ConstKind::Value(ref rhs_val) => lhs_val.valtree() == rhs_val.valtree(),
_ => false,
},

ty::ConstKind::Param(lhs) => {
INSTANTIATE_LHS_WITH_INFER
|| match rhs.kind() {
|| match *rhs_kind {
ty::ConstKind::Param(rhs) => lhs == rhs,
_ => false,
}
}

// Placeholder consts don't unify with anything on their own
ty::ConstKind::Placeholder(lhs) => {
matches!(rhs.kind(), ty::ConstKind::Placeholder(rhs) if lhs == rhs)
matches!(*rhs_kind, ty::ConstKind::Placeholder(rhs) if lhs == rhs)
}

// As we don't necessarily eagerly evaluate constants,
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_type_ir/src/inherent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ pub trait Const<I: Interner<Const = Self>>:
+ Eq
+ Into<I::GenericArg>
+ Into<I::Term>
+ IntoKind<Kind = ty::ConstKind<I>>
+ IntoKindRef<Kind = ty::ConstKind<I>>
+ TypeSuperVisitable<I>
+ TypeSuperFoldable<I>
+ Relate<I>
Expand Down Expand Up @@ -287,8 +287,8 @@ pub trait Const<I: Interner<Const = Self>>:
}

pub trait ValueConst<I: Interner<ValueConst = Self>>: Copy + Debug + Hash + Eq {
fn ty(self) -> I::Ty;
fn valtree(self) -> I::ValTree;
fn ty(&self) -> I::Ty;
fn valtree(&self) -> &I::ValTree;
}

pub trait ExprConst<I: Interner<ExprConst = Self>>: Copy + Debug + Hash + Eq + Relate<I> {
Expand Down Expand Up @@ -518,6 +518,10 @@ pub trait IntoKind {
fn kind(self) -> Self::Kind;
}

pub trait IntoKindRef: IntoKind {
fn kind_ref(&self) -> &Self::Kind;
}

pub trait BoundVarLike<I: Interner> {
fn var(self) -> ty::BoundVar;

Expand Down

0 comments on commit bc51bb2

Please sign in to comment.