Skip to content

Commit 27e964d

Browse files
committed
fast path for declared_generic_bounds_from_env
1 parent 604f185 commit 27e964d

File tree

1 file changed

+12
-2
lines changed
  • compiler/rustc_infer/src/infer/outlives

1 file changed

+12
-2
lines changed

compiler/rustc_infer/src/infer/outlives/verify.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::infer::outlives::components::{compute_alias_components_recursive, Component};
22
use crate::infer::outlives::env::RegionBoundPairs;
33
use crate::infer::region_constraints::VerifyIfEq;
4-
use crate::infer::VerifyBound;
4+
use crate::infer::{GenericKind, VerifyBound};
55
use rustc_data_structures::sso::SsoHashSet;
66
use rustc_middle::ty::GenericArg;
77
use rustc_middle::ty::{self, OutlivesPredicate, Ty, TyCtxt};
@@ -245,10 +245,20 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
245245
"declared_generic_bounds_from_env_for_erased_ty: region_bound_pair = {:?}",
246246
(r, p)
247247
);
248+
// Fast path for the common case.
249+
match (&p, erased_ty.kind()) {
250+
// In outlive routines, all types are expected to be fully normalized.
251+
// And therefore we can safely use structural equality for alias types.
252+
(GenericKind::Param(p1), ty::Param(p2)) if p1 == p2 => {}
253+
(GenericKind::Placeholder(p1), ty::Placeholder(p2)) if p1 == p2 => {}
254+
(GenericKind::Alias(a1), ty::Alias(_, a2)) if a1.def_id == a2.def_id => {}
255+
_ => return None,
256+
}
257+
248258
let p_ty = p.to_ty(tcx);
249259
let erased_p_ty = self.tcx.erase_regions(p_ty);
250260
(erased_p_ty == erased_ty)
251-
.then_some(ty::Binder::dummy(ty::OutlivesPredicate(p.to_ty(tcx), r)))
261+
.then_some(ty::Binder::dummy(ty::OutlivesPredicate(p_ty, r)))
252262
});
253263

254264
param_bounds

0 commit comments

Comments
 (0)