Add fast path to eq_opaque_type_and_type
This commit is contained in:
parent
6d9e270a4d
commit
223a2ee306
@ -138,7 +138,7 @@ impl FlagComputation {
|
||||
}
|
||||
|
||||
&ty::Opaque(_, substs) => {
|
||||
self.add_flags(TypeFlags::HAS_PROJECTION);
|
||||
self.add_flags(TypeFlags::HAS_PROJECTION | TypeFlags::HAS_TY_OPAQUE);
|
||||
self.add_substs(substs);
|
||||
}
|
||||
|
||||
|
@ -78,6 +78,9 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
|
||||
fn has_projections(&self) -> bool {
|
||||
self.has_type_flags(TypeFlags::HAS_PROJECTION)
|
||||
}
|
||||
fn has_opaque_types(&self) -> bool {
|
||||
self.has_type_flags(TypeFlags::HAS_TY_OPAQUE)
|
||||
}
|
||||
fn references_error(&self) -> bool {
|
||||
self.has_type_flags(TypeFlags::HAS_TY_ERR)
|
||||
}
|
||||
|
@ -481,6 +481,8 @@ bitflags! {
|
||||
|
||||
const HAS_CT_INFER = 1 << 14;
|
||||
const HAS_CT_PLACEHOLDER = 1 << 15;
|
||||
/// Does this have any [Opaque] types.
|
||||
const HAS_TY_OPAQUE = 1 << 16;
|
||||
|
||||
const NEEDS_SUBST = TypeFlags::HAS_PARAMS.bits |
|
||||
TypeFlags::HAS_RE_EARLY_BOUND.bits;
|
||||
@ -503,7 +505,8 @@ bitflags! {
|
||||
TypeFlags::HAS_RE_ERASED.bits |
|
||||
TypeFlags::HAS_TY_PLACEHOLDER.bits |
|
||||
TypeFlags::HAS_CT_INFER.bits |
|
||||
TypeFlags::HAS_CT_PLACEHOLDER.bits;
|
||||
TypeFlags::HAS_CT_PLACEHOLDER.bits |
|
||||
TypeFlags::HAS_TY_OPAQUE.bits;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -615,7 +615,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
|
||||
if let ty::Opaque(def_id, substs) = t.kind {
|
||||
self.expand_opaque_ty(def_id, substs).unwrap_or(t)
|
||||
} else if t.has_projections() {
|
||||
} else if t.has_opaque_types() {
|
||||
t.super_fold_with(self)
|
||||
} else {
|
||||
t
|
||||
|
@ -1196,6 +1196,22 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
anon_ty={:?})",
|
||||
revealed_ty, anon_ty
|
||||
);
|
||||
|
||||
// Fast path for the common case.
|
||||
if !anon_ty.has_opaque_types() {
|
||||
if let Err(terr) = self.eq_types(anon_ty, revealed_ty, locations, category) {
|
||||
span_mirbug!(
|
||||
self,
|
||||
locations,
|
||||
"eq_opaque_type_and_type: `{:?}=={:?}` failed with `{:?}`",
|
||||
revealed_ty,
|
||||
anon_ty,
|
||||
terr
|
||||
);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let infcx = self.infcx;
|
||||
let tcx = infcx.tcx;
|
||||
let param_env = self.param_env;
|
||||
|
Loading…
Reference in New Issue
Block a user