Skip to content

Commit ef3043d

Browse files
Simplify
1 parent a7b4a9a commit ef3043d

File tree

1 file changed

+23
-31
lines changed

1 file changed

+23
-31
lines changed

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

+23-31
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
360360
(true, Ok(Certainty::Maybe(MaybeCause::Ambiguity))) | (false, Err(_)) => {}
361361
_ => return ControlFlow::Continue(()),
362362
}
363-
let pred_kind = goal.goal().predicate.kind();
363+
364+
let pred = goal.goal().predicate;
364365

365366
let candidates = self.non_trivial_candidates(goal);
366367
let candidate = match candidates.as_slice() {
@@ -382,20 +383,20 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
382383

383384
// FIXME: Also, what about considering >1 layer up the stack? May be necessary
384385
// for normalizes-to.
385-
let child_mode = match pred_kind.skip_binder() {
386-
ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => {
387-
ChildMode::Trait(pred_kind.rebind(pred))
386+
let child_mode = match pred.kind().skip_binder() {
387+
ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_pred)) => {
388+
ChildMode::Trait(pred.kind().rebind(trait_pred))
388389
}
389-
ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(pred)) => {
390-
ChildMode::Host(pred_kind.rebind(pred))
390+
ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(host_pred)) => {
391+
ChildMode::Host(pred.kind().rebind(host_pred))
391392
}
392393
ty::PredicateKind::NormalizesTo(normalizes_to)
393394
if matches!(
394395
normalizes_to.alias.kind(tcx),
395396
ty::AliasTermKind::ProjectionTy | ty::AliasTermKind::ProjectionConst
396397
) =>
397398
{
398-
ChildMode::Trait(pred_kind.rebind(ty::TraitPredicate {
399+
ChildMode::Trait(pred.kind().rebind(ty::TraitPredicate {
399400
trait_ref: normalizes_to.alias.trait_ref(tcx),
400401
polarity: ty::PredicatePolarity::Positive,
401402
}))
@@ -429,10 +430,12 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
429430
for nested_goal in nested_goals {
430431
trace!(nested_goal = ?(nested_goal.goal(), nested_goal.source(), nested_goal.result()));
431432

433+
let nested_pred = nested_goal.goal().predicate;
434+
432435
let make_obligation = |cause| Obligation {
433436
cause,
434437
param_env: nested_goal.goal().param_env,
435-
predicate: nested_goal.goal().predicate,
438+
predicate: nested_pred,
436439
recursion_depth: self.obligation.recursion_depth + 1,
437440
};
438441

@@ -482,28 +485,17 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
482485

483486
// alias-relate may fail because the lhs or rhs can't be normalized,
484487
// and therefore is treated as rigid.
485-
if let Some(ty::PredicateKind::AliasRelate(lhs, rhs, _)) = pred_kind.no_bound_vars() {
486-
if let Some(obligation) = goal
487-
.infcx()
488-
.visit_proof_tree_at_depth(
489-
goal.goal().with(tcx, ty::ClauseKind::WellFormed(lhs.into())),
490-
goal.depth() + 1,
491-
self,
492-
)
493-
.break_value()
494-
{
495-
return ControlFlow::Break(obligation);
496-
} else if let Some(obligation) = goal
497-
.infcx()
498-
.visit_proof_tree_at_depth(
499-
goal.goal().with(tcx, ty::ClauseKind::WellFormed(rhs.into())),
500-
goal.depth() + 1,
501-
self,
502-
)
503-
.break_value()
504-
{
505-
return ControlFlow::Break(obligation);
506-
}
488+
if let Some(ty::PredicateKind::AliasRelate(lhs, rhs, _)) = pred.kind().no_bound_vars() {
489+
goal.infcx().visit_proof_tree_at_depth(
490+
goal.goal().with(tcx, ty::ClauseKind::WellFormed(lhs.into())),
491+
goal.depth() + 1,
492+
self,
493+
)?;
494+
goal.infcx().visit_proof_tree_at_depth(
495+
goal.goal().with(tcx, ty::ClauseKind::WellFormed(rhs.into())),
496+
goal.depth() + 1,
497+
self,
498+
)?;
507499
}
508500

509501
// HACK: When a higher-ranked projection goal fails, check that the corresponding
@@ -512,7 +504,7 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
512504
// to see that the leak check failed in the nested `NormalizesTo` goal, so we don't
513505
// fall back to the regular machinery that should catch when a projection goal fails
514506
// due to an unsatisfied trait goal.
515-
if let Some(projection_clause) = goal.goal().predicate.as_projection_clause()
507+
if let Some(projection_clause) = pred.as_projection_clause()
516508
&& !projection_clause.bound_vars().is_empty()
517509
{
518510
let pred = projection_clause.map_bound(|proj| proj.projection_term.trait_ref(tcx));

0 commit comments

Comments
 (0)