Skip to content

Commit f5ebd71

Browse files
committed
non non-wf alias detection into sub-fn
1 parent 5354da0 commit f5ebd71

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs

+28-17
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,33 @@ impl<'tcx> BestObligation<'tcx> {
290290
ControlFlow::Continue(())
291291
}
292292
}
293+
294+
/// It is likely that `NormalizesTo` failed without any applicable candidates
295+
/// because the alias is not well-formed.
296+
///
297+
/// As we only enter `RigidAlias` candidates if the trait bound of the associated type
298+
/// holds, we discard these candidates in `non_trivial_candidates` and always manually
299+
/// check this here.
300+
fn detect_non_well_formed_assoc_item(
301+
&mut self,
302+
goal: &inspect::InspectGoal<'_, 'tcx>,
303+
alias: ty::AliasTerm<'tcx>,
304+
) -> ControlFlow<PredicateObligation<'tcx>> {
305+
let tcx = goal.infcx().tcx;
306+
let obligation = Obligation::new(
307+
tcx,
308+
self.obligation.cause.clone(),
309+
goal.goal().param_env,
310+
alias.trait_ref(tcx),
311+
);
312+
self.with_derived_obligation(obligation, |this| {
313+
goal.infcx().visit_proof_tree_at_depth(
314+
goal.goal().with(tcx, alias.trait_ref(tcx)),
315+
goal.depth() + 1,
316+
this,
317+
)
318+
})
319+
}
293320
}
294321

295322
impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
@@ -321,23 +348,7 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
321348
| ty::AliasTermKind::ProjectionConst = pred.alias.kind(tcx) =>
322349
{
323350
self.detect_error_in_self_ty_normalization(goal, pred.alias.self_ty())?;
324-
// It is likely that `NormalizesTo` failed because the alias is not well-formed.
325-
// As we only enter `RigidAlias` candidates if the trait bound of the associated type
326-
// holds, we discard these candidates in `non_trivial_candidates` and always manually
327-
// check this here.
328-
let obligation = Obligation::new(
329-
tcx,
330-
self.obligation.cause.clone(),
331-
goal.goal().param_env,
332-
pred.alias.trait_ref(tcx),
333-
);
334-
self.with_derived_obligation(obligation, |this| {
335-
goal.infcx().visit_proof_tree_at_depth(
336-
goal.goal().with(tcx, pred.alias.trait_ref(tcx)),
337-
goal.depth() + 1,
338-
this,
339-
)
340-
})?;
351+
self.detect_non_well_formed_assoc_item(goal, pred.alias)?;
341352
}
342353
Some(_) | None => {}
343354
}

0 commit comments

Comments
 (0)