diff options
| author | Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> | 2023-12-18 16:26:14 +0000 |
|---|---|---|
| committer | Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> | 2023-12-19 16:07:01 +0000 |
| commit | 27e964dbfb9907970e96bd40429563449000bfbe (patch) | |
| tree | e1482313f5106e6654eec0015db78f4f17ce86b4 | |
| parent | 604f185fae9a4b0edf7e28f616a0f53880f8f074 (diff) | |
| download | rust-27e964dbfb9907970e96bd40429563449000bfbe.tar.gz rust-27e964dbfb9907970e96bd40429563449000bfbe.zip | |
fast path for declared_generic_bounds_from_env
| -rw-r--r-- | compiler/rustc_infer/src/infer/outlives/verify.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs index ce619ae8a0d..b0caf1efb45 100644 --- a/compiler/rustc_infer/src/infer/outlives/verify.rs +++ b/compiler/rustc_infer/src/infer/outlives/verify.rs @@ -1,7 +1,7 @@ use crate::infer::outlives::components::{compute_alias_components_recursive, Component}; use crate::infer::outlives::env::RegionBoundPairs; use crate::infer::region_constraints::VerifyIfEq; -use crate::infer::VerifyBound; +use crate::infer::{GenericKind, VerifyBound}; use rustc_data_structures::sso::SsoHashSet; use rustc_middle::ty::GenericArg; use rustc_middle::ty::{self, OutlivesPredicate, Ty, TyCtxt}; @@ -245,10 +245,20 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { "declared_generic_bounds_from_env_for_erased_ty: region_bound_pair = {:?}", (r, p) ); + // Fast path for the common case. + match (&p, erased_ty.kind()) { + // In outlive routines, all types are expected to be fully normalized. + // And therefore we can safely use structural equality for alias types. + (GenericKind::Param(p1), ty::Param(p2)) if p1 == p2 => {} + (GenericKind::Placeholder(p1), ty::Placeholder(p2)) if p1 == p2 => {} + (GenericKind::Alias(a1), ty::Alias(_, a2)) if a1.def_id == a2.def_id => {} + _ => return None, + } + let p_ty = p.to_ty(tcx); let erased_p_ty = self.tcx.erase_regions(p_ty); (erased_p_ty == erased_ty) - .then_some(ty::Binder::dummy(ty::OutlivesPredicate(p.to_ty(tcx), r))) + .then_some(ty::Binder::dummy(ty::OutlivesPredicate(p_ty, r))) }); param_bounds |
