Skip to content

Commit 1f133ae

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

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

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

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

295320
impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
@@ -321,23 +346,7 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
321346
| ty::AliasTermKind::ProjectionConst = pred.alias.kind(tcx) =>
322347
{
323348
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-
})?;
349+
self.detect_non_well_formed_alias(goal, pred.alias)?;
341350
}
342351
Some(_) | None => {}
343352
}

0 commit comments

Comments
 (0)