Skip to content

Commit 5833e55

Browse files
Use let chains in the new solver
1 parent 3b9d04c commit 5833e55

File tree

8 files changed

+79
-85
lines changed

8 files changed

+79
-85
lines changed

compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,10 @@ where
383383

384384
let mut candidates = vec![];
385385

386-
if let TypingMode::Coherence = self.typing_mode() {
387-
if let Ok(candidate) = self.consider_coherence_unknowable_candidate(goal) {
388-
return vec![candidate];
389-
}
386+
if let TypingMode::Coherence = self.typing_mode()
387+
&& let Ok(candidate) = self.consider_coherence_unknowable_candidate(goal)
388+
{
389+
return vec![candidate];
390390
}
391391

392392
self.assemble_alias_bound_candidates(goal, &mut candidates);

compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -998,10 +998,10 @@ where
998998
}
999999

10001000
fn try_fold_ty(&mut self, ty: I::Ty) -> Result<I::Ty, Ambiguous> {
1001-
if let ty::Alias(ty::Projection, alias_ty) = ty.kind() {
1002-
if let Some(term) = self.try_eagerly_replace_alias(alias_ty.into())? {
1003-
return Ok(term.expect_ty());
1004-
}
1001+
if let ty::Alias(ty::Projection, alias_ty) = ty.kind()
1002+
&& let Some(term) = self.try_eagerly_replace_alias(alias_ty.into())?
1003+
{
1004+
return Ok(term.expect_ty());
10051005
}
10061006

10071007
ty.try_super_fold_with(self)

compiler/rustc_next_trait_solver/src/solve/effect_goals.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,15 @@ where
4242
goal: Goal<I, Self>,
4343
assumption: I::Clause,
4444
) -> Result<(), NoSolution> {
45-
if let Some(host_clause) = assumption.as_host_effect_clause() {
46-
if host_clause.def_id() == goal.predicate.def_id()
47-
&& host_clause.constness().satisfies(goal.predicate.constness)
48-
{
49-
if DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
50-
goal.predicate.trait_ref.args,
51-
host_clause.skip_binder().trait_ref.args,
52-
) {
53-
return Ok(());
54-
}
45+
if let Some(host_clause) = assumption.as_host_effect_clause()
46+
&& host_clause.def_id() == goal.predicate.def_id()
47+
&& host_clause.constness().satisfies(goal.predicate.constness)
48+
{
49+
if DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
50+
goal.predicate.trait_ref.args,
51+
host_clause.skip_binder().trait_ref.args,
52+
) {
53+
return Ok(());
5554
}
5655
}
5756

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -480,22 +480,21 @@ where
480480
// If we have run this goal before, and it was stalled, check that any of the goal's
481481
// args have changed. Otherwise, we don't need to re-run the goal because it'll remain
482482
// stalled, since it'll canonicalize the same way and evaluation is pure.
483-
if let Some(stalled_on) = stalled_on {
484-
if !stalled_on.stalled_vars.iter().any(|value| self.delegate.is_changed_arg(*value))
485-
&& !self
486-
.delegate
487-
.opaque_types_storage_num_entries()
488-
.needs_reevaluation(stalled_on.num_opaques)
489-
{
490-
return Ok((
491-
NestedNormalizationGoals::empty(),
492-
GoalEvaluation {
493-
certainty: Certainty::Maybe(stalled_on.stalled_cause),
494-
has_changed: HasChanged::No,
495-
stalled_on: Some(stalled_on),
496-
},
497-
));
498-
}
483+
if let Some(stalled_on) = stalled_on
484+
&& !stalled_on.stalled_vars.iter().any(|value| self.delegate.is_changed_arg(*value))
485+
&& !self
486+
.delegate
487+
.opaque_types_storage_num_entries()
488+
.needs_reevaluation(stalled_on.num_opaques)
489+
{
490+
return Ok((
491+
NestedNormalizationGoals::empty(),
492+
GoalEvaluation {
493+
certainty: Certainty::Maybe(stalled_on.stalled_cause),
494+
has_changed: HasChanged::No,
495+
stalled_on: Some(stalled_on),
496+
},
497+
));
499498
}
500499

501500
let (orig_values, canonical_goal) = self.canonicalize_goal(goal);
@@ -887,13 +886,12 @@ where
887886

888887
match t.kind() {
889888
ty::Infer(ty::TyVar(vid)) => {
890-
if let ty::TermKind::Ty(term) = self.term.kind() {
891-
if let ty::Infer(ty::TyVar(term_vid)) = term.kind() {
892-
if self.delegate.root_ty_var(vid)
893-
== self.delegate.root_ty_var(term_vid)
894-
{
895-
return ControlFlow::Break(());
896-
}
889+
if let ty::TermKind::Ty(term) = self.term.kind()
890+
&& let ty::Infer(ty::TyVar(term_vid)) = term.kind()
891+
{
892+
if self.delegate.root_ty_var(vid) == self.delegate.root_ty_var(term_vid)
893+
{
894+
return ControlFlow::Break(());
897895
}
898896
}
899897

@@ -914,14 +912,13 @@ where
914912
fn visit_const(&mut self, c: I::Const) -> Self::Result {
915913
match c.kind() {
916914
ty::ConstKind::Infer(ty::InferConst::Var(vid)) => {
917-
if let ty::TermKind::Const(term) = self.term.kind() {
918-
if let ty::ConstKind::Infer(ty::InferConst::Var(term_vid)) = term.kind()
915+
if let ty::TermKind::Const(term) = self.term.kind()
916+
&& let ty::ConstKind::Infer(ty::InferConst::Var(term_vid)) = term.kind()
917+
{
918+
if self.delegate.root_const_var(vid)
919+
== self.delegate.root_const_var(term_vid)
919920
{
920-
if self.delegate.root_const_var(vid)
921-
== self.delegate.root_const_var(term_vid)
922-
{
923-
return ControlFlow::Break(());
924-
}
921+
return ControlFlow::Break(());
925922
}
926923
}
927924

compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ where
112112
goal: Goal<I, Self>,
113113
assumption: I::Clause,
114114
) -> Result<(), NoSolution> {
115-
if let Some(projection_pred) = assumption.as_projection_clause() {
116-
if projection_pred.item_def_id() == goal.predicate.def_id() {
117-
if DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
118-
goal.predicate.alias.args,
119-
projection_pred.skip_binder().projection_term.args,
120-
) {
121-
return Ok(());
122-
}
115+
if let Some(projection_pred) = assumption.as_projection_clause()
116+
&& projection_pred.item_def_id() == goal.predicate.def_id()
117+
{
118+
if DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
119+
goal.predicate.alias.args,
120+
projection_pred.skip_binder().projection_term.args,
121+
) {
122+
return Ok(());
123123
}
124124
}
125125

compiler/rustc_type_ir/src/elaborate.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,10 @@ pub fn supertrait_def_ids<I: Interner>(
320320
let trait_def_id = stack.pop()?;
321321

322322
for (predicate, _) in cx.explicit_super_predicates_of(trait_def_id).iter_identity() {
323-
if let ty::ClauseKind::Trait(data) = predicate.kind().skip_binder() {
324-
if set.insert(data.def_id()) {
325-
stack.push(data.def_id());
326-
}
323+
if let ty::ClauseKind::Trait(data) = predicate.kind().skip_binder()
324+
&& set.insert(data.def_id())
325+
{
326+
stack.push(data.def_id());
327327
}
328328
}
329329

compiler/rustc_type_ir/src/relate/solver_relating.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,12 @@ where
284284
}
285285

286286
// If they have no bound vars, relate normally.
287-
if let Some(a_inner) = a.no_bound_vars() {
288-
if let Some(b_inner) = b.no_bound_vars() {
289-
self.relate(a_inner, b_inner)?;
290-
return Ok(a);
291-
}
292-
};
287+
if let Some(a_inner) = a.no_bound_vars()
288+
&& let Some(b_inner) = b.no_bound_vars()
289+
{
290+
self.relate(a_inner, b_inner)?;
291+
return Ok(a);
292+
}
293293

294294
match self.ambient_variance {
295295
// Checks whether `for<..> sub <: for<..> sup` holds.

compiler/rustc_type_ir/src/search_graph/global_cache.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,29 @@ impl<X: Cx> GlobalCache<X> {
8080
mut candidate_is_applicable: impl FnMut(&NestedGoals<X>) -> bool,
8181
) -> Option<CacheData<'a, X>> {
8282
let entry = self.map.get(&input)?;
83-
if let Some(Success { required_depth, ref nested_goals, ref result }) = entry.success {
84-
if available_depth.cache_entry_is_applicable(required_depth)
85-
&& candidate_is_applicable(nested_goals)
86-
{
87-
return Some(CacheData {
88-
result: cx.get_tracked(&result),
89-
required_depth,
90-
encountered_overflow: false,
91-
nested_goals,
92-
});
93-
}
83+
if let Some(Success { required_depth, ref nested_goals, ref result }) = entry.success
84+
&& available_depth.cache_entry_is_applicable(required_depth)
85+
&& candidate_is_applicable(nested_goals)
86+
{
87+
return Some(CacheData {
88+
result: cx.get_tracked(&result),
89+
required_depth,
90+
encountered_overflow: false,
91+
nested_goals,
92+
});
9493
}
9594

9695
let additional_depth = available_depth.0;
9796
if let Some(WithOverflow { nested_goals, result }) =
9897
entry.with_overflow.get(&additional_depth)
98+
&& candidate_is_applicable(nested_goals)
9999
{
100-
if candidate_is_applicable(nested_goals) {
101-
return Some(CacheData {
102-
result: cx.get_tracked(result),
103-
required_depth: additional_depth,
104-
encountered_overflow: true,
105-
nested_goals,
106-
});
107-
}
100+
return Some(CacheData {
101+
result: cx.get_tracked(result),
102+
required_depth: additional_depth,
103+
encountered_overflow: true,
104+
nested_goals,
105+
});
108106
}
109107

110108
None

0 commit comments

Comments
 (0)