Skip to content

Commit 2140016

Browse files
committed
don't just compare ty::Const
1 parent ab9108b commit 2140016

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

compiler/rustc_infer/src/infer/combine.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
129129
where
130130
R: ConstEquateRelation<'tcx>,
131131
{
132+
let a = self.tcx.expose_default_const_substs(a);
133+
let b = self.tcx.expose_default_const_substs(b);
132134
debug!("{}.consts({:?}, {:?})", relation.tag(), a, b);
133135
if a == b {
134136
return Ok(a);

compiler/rustc_middle/src/ty/fold.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ pub trait TypeFolder<'tcx>: Sized {
213213
c.super_fold_with(self)
214214
}
215215

216+
fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
217+
p.super_fold_with(self)
218+
}
219+
216220
fn fold_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx> {
217221
bug!("most type folders should not be folding MIR datastructures: {:?}", c)
218222
}
@@ -1205,6 +1209,42 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor<'tcx> {
12051209
}
12061210
}
12071211

1212+
impl<'tcx> TyCtxt<'tcx> {
1213+
/// This is a HACK(const_generics) and should probably not be needed.
1214+
/// Might however be perf relevant, so who knows.
1215+
///
1216+
/// FIXME(@lcnr): explain this function a bit more
1217+
pub fn expose_default_const_substs<T: TypeFoldable<'tcx>>(self, v: T) -> T {
1218+
v.fold_with(&mut ExposeDefaultConstSubstsFolder { tcx: self })
1219+
}
1220+
}
1221+
1222+
struct ExposeDefaultConstSubstsFolder<'tcx> {
1223+
tcx: TyCtxt<'tcx>,
1224+
}
1225+
1226+
impl<'tcx> TypeFolder<'tcx> for ExposeDefaultConstSubstsFolder<'tcx> {
1227+
fn tcx(&self) -> TyCtxt<'tcx> {
1228+
self.tcx
1229+
}
1230+
1231+
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
1232+
if ty.flags().intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) {
1233+
ty.super_fold_with(self)
1234+
} else {
1235+
ty
1236+
}
1237+
}
1238+
1239+
fn fold_predicate(&mut self, pred: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
1240+
if pred.inner.flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) {
1241+
pred.super_fold_with(self)
1242+
} else {
1243+
pred
1244+
}
1245+
}
1246+
}
1247+
12081248
/// Collects all the late-bound regions at the innermost binding level
12091249
/// into a hash set.
12101250
struct LateBoundRegionsCollector<'tcx> {

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,10 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
974974
}
975975

976976
impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
977+
fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
978+
folder.fold_predicate(self)
979+
}
980+
977981
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
978982
let new = self.inner.kind.fold_with(folder);
979983
folder.tcx().reuse_or_mk_predicate(self, new)

0 commit comments

Comments
 (0)