Skip to content

Commit 83a4b09

Browse files
committed
Fix formatting of if let chain
1 parent cf182b9 commit 83a4b09

File tree

1 file changed

+47
-46
lines changed

1 file changed

+47
-46
lines changed

clippy_lints/src/manual_let_else.rs

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -77,53 +77,54 @@ impl<'tcx> LateLintPass<'tcx> for ManualLetElse {
7777
local.els.is_none() &&
7878
local.ty.is_none() &&
7979
init.span.ctxt() == stmt.span.ctxt() &&
80-
let Some(if_let_or_match) = IfLetOrMatch::parse(cx, init) {
81-
match if_let_or_match {
82-
IfLetOrMatch::IfLet(if_let_expr, let_pat, if_then, if_else) => if_chain! {
83-
if expr_is_simple_identity(let_pat, if_then);
84-
if let Some(if_else) = if_else;
85-
if expr_diverges(cx, if_else);
86-
then {
87-
emit_manual_let_else(cx, stmt.span, if_let_expr, local.pat, let_pat, if_else);
88-
}
89-
},
90-
IfLetOrMatch::Match(match_expr, arms, source) => {
91-
if self.matches_behaviour == MatchLintBehaviour::Never {
92-
return;
93-
}
94-
if source != MatchSource::Normal {
95-
return;
96-
}
97-
// Any other number than two arms doesn't (necessarily)
98-
// have a trivial mapping to let else.
99-
if arms.len() != 2 {
100-
return;
101-
}
102-
// Guards don't give us an easy mapping either
103-
if arms.iter().any(|arm| arm.guard.is_some()) {
104-
return;
105-
}
106-
let check_types = self.matches_behaviour == MatchLintBehaviour::WellKnownTypes;
107-
let diverging_arm_opt = arms
108-
.iter()
109-
.enumerate()
110-
.find(|(_, arm)| expr_diverges(cx, arm.body) && pat_allowed_for_else(cx, arm.pat, check_types));
111-
let Some((idx, diverging_arm)) = diverging_arm_opt else { return; };
112-
// If the non-diverging arm is the first one, its pattern can be reused in a let/else statement.
113-
// However, if it arrives in second position, its pattern may cover some cases already covered
114-
// by the diverging one.
115-
// TODO: accept the non-diverging arm as a second position if patterns are disjointed.
116-
if idx == 0 {
117-
return;
118-
}
119-
let pat_arm = &arms[1 - idx];
120-
if !expr_is_simple_identity(pat_arm.pat, pat_arm.body) {
121-
return;
122-
}
80+
let Some(if_let_or_match) = IfLetOrMatch::parse(cx, init)
81+
{
82+
match if_let_or_match {
83+
IfLetOrMatch::IfLet(if_let_expr, let_pat, if_then, if_else) => if_chain! {
84+
if expr_is_simple_identity(let_pat, if_then);
85+
if let Some(if_else) = if_else;
86+
if expr_diverges(cx, if_else);
87+
then {
88+
emit_manual_let_else(cx, stmt.span, if_let_expr, local.pat, let_pat, if_else);
89+
}
90+
},
91+
IfLetOrMatch::Match(match_expr, arms, source) => {
92+
if self.matches_behaviour == MatchLintBehaviour::Never {
93+
return;
94+
}
95+
if source != MatchSource::Normal {
96+
return;
97+
}
98+
// Any other number than two arms doesn't (necessarily)
99+
// have a trivial mapping to let else.
100+
if arms.len() != 2 {
101+
return;
102+
}
103+
// Guards don't give us an easy mapping either
104+
if arms.iter().any(|arm| arm.guard.is_some()) {
105+
return;
106+
}
107+
let check_types = self.matches_behaviour == MatchLintBehaviour::WellKnownTypes;
108+
let diverging_arm_opt = arms
109+
.iter()
110+
.enumerate()
111+
.find(|(_, arm)| expr_diverges(cx, arm.body) && pat_allowed_for_else(cx, arm.pat, check_types));
112+
let Some((idx, diverging_arm)) = diverging_arm_opt else { return; };
113+
// If the non-diverging arm is the first one, its pattern can be reused in a let/else statement.
114+
// However, if it arrives in second position, its pattern may cover some cases already covered
115+
// by the diverging one.
116+
// TODO: accept the non-diverging arm as a second position if patterns are disjointed.
117+
if idx == 0 {
118+
return;
119+
}
120+
let pat_arm = &arms[1 - idx];
121+
if !expr_is_simple_identity(pat_arm.pat, pat_arm.body) {
122+
return;
123+
}
123124

124-
emit_manual_let_else(cx, stmt.span, match_expr, local.pat, pat_arm.pat, diverging_arm.body);
125-
},
126-
}
125+
emit_manual_let_else(cx, stmt.span, match_expr, local.pat, pat_arm.pat, diverging_arm.body);
126+
},
127+
}
127128
};
128129
}
129130

0 commit comments

Comments
 (0)