don't just compare ty::Const
This commit is contained in:
parent
ab9108b70f
commit
2140016d6c
3 changed files with 46 additions and 0 deletions
|
@ -129,6 +129,8 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
|
|||
where
|
||||
R: ConstEquateRelation<'tcx>,
|
||||
{
|
||||
let a = self.tcx.expose_default_const_substs(a);
|
||||
let b = self.tcx.expose_default_const_substs(b);
|
||||
debug!("{}.consts({:?}, {:?})", relation.tag(), a, b);
|
||||
if a == b {
|
||||
return Ok(a);
|
||||
|
|
|
@ -213,6 +213,10 @@ pub trait TypeFolder<'tcx>: Sized {
|
|||
c.super_fold_with(self)
|
||||
}
|
||||
|
||||
fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
|
||||
p.super_fold_with(self)
|
||||
}
|
||||
|
||||
fn fold_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> mir::ConstantKind<'tcx> {
|
||||
bug!("most type folders should not be folding MIR datastructures: {:?}", c)
|
||||
}
|
||||
|
@ -1205,6 +1209,42 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
/// This is a HACK(const_generics) and should probably not be needed.
|
||||
/// Might however be perf relevant, so who knows.
|
||||
///
|
||||
/// FIXME(@lcnr): explain this function a bit more
|
||||
pub fn expose_default_const_substs<T: TypeFoldable<'tcx>>(self, v: T) -> T {
|
||||
v.fold_with(&mut ExposeDefaultConstSubstsFolder { tcx: self })
|
||||
}
|
||||
}
|
||||
|
||||
struct ExposeDefaultConstSubstsFolder<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFolder<'tcx> for ExposeDefaultConstSubstsFolder<'tcx> {
|
||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
||||
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
if ty.flags().intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) {
|
||||
ty.super_fold_with(self)
|
||||
} else {
|
||||
ty
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_predicate(&mut self, pred: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
|
||||
if pred.inner.flags.intersects(TypeFlags::HAS_UNKNOWN_DEFAULT_CONST_SUBSTS) {
|
||||
pred.super_fold_with(self)
|
||||
} else {
|
||||
pred
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Collects all the late-bound regions at the innermost binding level
|
||||
/// into a hash set.
|
||||
struct LateBoundRegionsCollector<'tcx> {
|
||||
|
|
|
@ -974,6 +974,10 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
|
|||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
|
||||
fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
folder.fold_predicate(self)
|
||||
}
|
||||
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
|
||||
let new = self.inner.kind.fold_with(folder);
|
||||
folder.tcx().reuse_or_mk_predicate(self, new)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue