Skip to content

Commit 55c85b1

Browse files
committed
obligations_for_self_ty: skip irrelevant goals
1 parent ed6a7b1 commit 55c85b1

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3737
) -> bool {
3838
match predicate.kind().skip_binder() {
3939
ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => {
40-
self.type_matches_expected_vid(expected_vid, data.self_ty())
40+
self.type_matches_expected_vid(data.self_ty(), expected_vid)
4141
}
4242
ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) => {
43-
self.type_matches_expected_vid(expected_vid, data.projection_term.self_ty())
43+
self.type_matches_expected_vid(data.projection_term.self_ty(), expected_vid)
4444
}
4545
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
4646
| ty::PredicateKind::Subtype(..)
@@ -60,7 +60,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
6060
}
6161

6262
#[instrument(level = "debug", skip(self), ret)]
63-
fn type_matches_expected_vid(&self, expected_vid: ty::TyVid, ty: Ty<'tcx>) -> bool {
63+
fn type_matches_expected_vid(&self, ty: Ty<'tcx>, expected_vid: ty::TyVid) -> bool {
6464
let ty = self.shallow_resolve(ty);
6565
debug!(?ty);
6666

@@ -125,6 +125,18 @@ impl<'a, 'tcx> ProofTreeVisitor<'tcx> for NestedObligationsForSelfTy<'a, 'tcx> {
125125
return;
126126
}
127127

128+
// We don't care about any pending goals which don't actually
129+
// use the self type.
130+
if !inspect_goal
131+
.orig_values()
132+
.iter()
133+
.filter_map(|arg| arg.as_type())
134+
.any(|ty| self.fcx.type_matches_expected_vid(ty, self.self_ty))
135+
{
136+
debug!(goal = ?inspect_goal.goal(), "goal does not mention self type");
137+
return;
138+
}
139+
128140
let tcx = self.fcx.tcx;
129141
let goal = inspect_goal.goal();
130142
if self.fcx.predicate_has_self_ty(goal.predicate, self.self_ty)

compiler/rustc_trait_selection/src/solve/inspect/analyse.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
317317
self.depth
318318
}
319319

320+
pub fn orig_values(&self) -> &[ty::GenericArg<'tcx>] {
321+
&self.orig_values
322+
}
323+
320324
fn candidates_recur(
321325
&'a self,
322326
candidates: &mut Vec<InspectCandidate<'a, 'tcx>>,

0 commit comments

Comments
 (0)