Skip to content

Commit 66ea349

Browse files
Use let chains in the new solver
1 parent 13c46fd commit 66ea349

File tree

8 files changed

+84
-96
lines changed

8 files changed

+84
-96
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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -997,12 +997,12 @@ where
997997
}
998998

999999
fn try_fold_ty(&mut self, ty: I::Ty) -> Result<I::Ty, Ambiguous> {
1000-
if let ty::Alias(ty::Projection, alias_ty) = ty.kind() {
1001-
if let Some(term) = self.try_eagerly_replace_alias(alias_ty.into())? {
1002-
return Ok(term.expect_ty());
1003-
}
1000+
if let ty::Alias(ty::Projection, alias_ty) = ty.kind()
1001+
&& let Some(term) = self.try_eagerly_replace_alias(alias_ty.into())?
1002+
{
1003+
Ok(term.expect_ty())
1004+
} else {
1005+
ty.try_super_fold_with(self)
10041006
}
1005-
1006-
ty.try_super_fold_with(self)
10071007
}
10081008
}

compiler/rustc_next_trait_solver/src/solve/effect_goals.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,18 @@ 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-
}
55-
}
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+
&& DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
49+
goal.predicate.trait_ref.args,
50+
host_clause.skip_binder().trait_ref.args,
51+
)
52+
{
53+
Ok(())
54+
} else {
55+
Err(NoSolution)
5656
}
57-
58-
Err(NoSolution)
5957
}
6058

6159
fn match_assumption(

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

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -429,22 +429,21 @@ where
429429
// If we have run this goal before, and it was stalled, check that any of the goal's
430430
// args have changed. Otherwise, we don't need to re-run the goal because it'll remain
431431
// stalled, since it'll canonicalize the same way and evaluation is pure.
432-
if let Some(stalled_on) = stalled_on {
433-
if !stalled_on.stalled_vars.iter().any(|value| self.delegate.is_changed_arg(*value))
434-
&& !self
435-
.delegate
436-
.opaque_types_storage_num_entries()
437-
.needs_reevaluation(stalled_on.num_opaques)
438-
{
439-
return Ok((
440-
NestedNormalizationGoals::empty(),
441-
GoalEvaluation {
442-
certainty: Certainty::Maybe(stalled_on.stalled_cause),
443-
has_changed: HasChanged::No,
444-
stalled_on: Some(stalled_on),
445-
},
446-
));
447-
}
432+
if let Some(stalled_on) = stalled_on
433+
&& !stalled_on.stalled_vars.iter().any(|value| self.delegate.is_changed_arg(*value))
434+
&& !self
435+
.delegate
436+
.opaque_types_storage_num_entries()
437+
.needs_reevaluation(stalled_on.num_opaques)
438+
{
439+
return Ok((
440+
NestedNormalizationGoals::empty(),
441+
GoalEvaluation {
442+
certainty: Certainty::Maybe(stalled_on.stalled_cause),
443+
has_changed: HasChanged::No,
444+
stalled_on: Some(stalled_on),
445+
},
446+
));
448447
}
449448

450449
let (orig_values, canonical_goal) = self.canonicalize_goal(goal);
@@ -833,14 +832,11 @@ where
833832

834833
match t.kind() {
835834
ty::Infer(ty::TyVar(vid)) => {
836-
if let ty::TermKind::Ty(term) = self.term.kind() {
837-
if let ty::Infer(ty::TyVar(term_vid)) = term.kind() {
838-
if self.delegate.root_ty_var(vid)
839-
== self.delegate.root_ty_var(term_vid)
840-
{
841-
return ControlFlow::Break(());
842-
}
843-
}
835+
if let ty::TermKind::Ty(term) = self.term.kind()
836+
&& let ty::Infer(ty::TyVar(term_vid)) = term.kind()
837+
&& self.delegate.root_ty_var(vid) == self.delegate.root_ty_var(term_vid)
838+
{
839+
return ControlFlow::Break(());
844840
}
845841

846842
self.check_nameable(self.delegate.universe_of_ty(vid).unwrap())?;
@@ -860,15 +856,12 @@ where
860856
fn visit_const(&mut self, c: I::Const) -> Self::Result {
861857
match c.kind() {
862858
ty::ConstKind::Infer(ty::InferConst::Var(vid)) => {
863-
if let ty::TermKind::Const(term) = self.term.kind() {
864-
if let ty::ConstKind::Infer(ty::InferConst::Var(term_vid)) = term.kind()
865-
{
866-
if self.delegate.root_const_var(vid)
867-
== self.delegate.root_const_var(term_vid)
868-
{
869-
return ControlFlow::Break(());
870-
}
871-
}
859+
if let ty::TermKind::Const(term) = self.term.kind()
860+
&& let ty::ConstKind::Infer(ty::InferConst::Var(term_vid)) = term.kind()
861+
&& self.delegate.root_const_var(vid)
862+
== self.delegate.root_const_var(term_vid)
863+
{
864+
return ControlFlow::Break(());
872865
}
873866

874867
self.check_nameable(self.delegate.universe_of_ct(vid).unwrap())

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,17 @@ 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-
}
123-
}
115+
if let Some(projection_pred) = assumption.as_projection_clause()
116+
&& projection_pred.item_def_id() == goal.predicate.def_id()
117+
&& DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
118+
goal.predicate.alias.args,
119+
projection_pred.skip_binder().projection_term.args,
120+
)
121+
{
122+
Ok(())
123+
} else {
124+
Err(NoSolution)
124125
}
125-
126-
Err(NoSolution)
127126
}
128127

129128
fn match_assumption(

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)