about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-08-10 10:22:06 +0000
committerbors <bors@rust-lang.org>2024-08-10 10:22:06 +0000
commit48090b11b52bd841fa89082cdaa4c139f11995f7 (patch)
treecaef888903ee0eb3e601d26b9930cf1eed1e13c9 /compiler/rustc_trait_selection/src
parent7347f8e4e007fbb3712364bc174476f5f55a6da4 (diff)
parent79228526bfa37f2f0ee9b91671a4342064e85f73 (diff)
downloadrust-48090b11b52bd841fa89082cdaa4c139f11995f7.tar.gz
rust-48090b11b52bd841fa89082cdaa4c139f11995f7.zip
Auto merge of #128746 - compiler-errors:cache-super-outlives, r=lcnr
Cache supertrait outlives of impl header for soundness check

This caches the results of computing the transitive supertraits of an impl and filtering it to its outlives obligations. This is purely an optimization to improve https://github.com/rust-lang/rust/pull/124336.
Diffstat (limited to 'compiler/rustc_trait_selection/src')
-rw-r--r--compiler/rustc_trait_selection/src/traits/select/mod.rs42
1 files changed, 16 insertions, 26 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs
index 1d9a90f0300..1b2767a6a62 100644
--- a/compiler/rustc_trait_selection/src/traits/select/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs
@@ -17,7 +17,6 @@ use rustc_hir::LangItem;
 use rustc_infer::infer::relate::TypeRelation;
 use rustc_infer::infer::BoundRegionConversionTime::{self, HigherRankedType};
 use rustc_infer::infer::DefineOpaqueTypes;
-use rustc_infer::traits::util::elaborate;
 use rustc_infer::traits::TraitObligation;
 use rustc_middle::bug;
 use rustc_middle::dep_graph::{dep_kinds, DepNodeIndex};
@@ -2801,31 +2800,22 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
         }
 
         // Register any outlives obligations from the trait here, cc #124336.
-        if matches!(self.tcx().def_kind(def_id), DefKind::Impl { of_trait: true })
-            && let Some(header) = self.tcx().impl_trait_header(def_id)
-        {
-            let trait_clause: ty::Clause<'tcx> =
-                header.trait_ref.instantiate(self.tcx(), args).upcast(self.tcx());
-            for clause in elaborate(self.tcx(), [trait_clause]) {
-                if matches!(
-                    clause.kind().skip_binder(),
-                    ty::ClauseKind::TypeOutlives(..) | ty::ClauseKind::RegionOutlives(..)
-                ) {
-                    let clause = normalize_with_depth_to(
-                        self,
-                        param_env,
-                        cause.clone(),
-                        recursion_depth,
-                        clause,
-                        &mut obligations,
-                    );
-                    obligations.push(Obligation {
-                        cause: cause.clone(),
-                        recursion_depth,
-                        param_env,
-                        predicate: clause.as_predicate(),
-                    });
-                }
+        if matches!(tcx.def_kind(def_id), DefKind::Impl { of_trait: true }) {
+            for clause in tcx.impl_super_outlives(def_id).iter_instantiated(tcx, args) {
+                let clause = normalize_with_depth_to(
+                    self,
+                    param_env,
+                    cause.clone(),
+                    recursion_depth,
+                    clause,
+                    &mut obligations,
+                );
+                obligations.push(Obligation {
+                    cause: cause.clone(),
+                    recursion_depth,
+                    param_env,
+                    predicate: clause.as_predicate(),
+                });
             }
         }