Skip to content

Commit 75e196e

Browse files
committed
Allow also allow bool literals as first item of let chain
1 parent c6c8159 commit 75e196e

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/pairs.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,14 @@ struct PairList<'a, 'b, T: Rewrite> {
266266
span: Span,
267267
}
268268

269-
fn is_ident(expr: &ast::Expr) -> bool {
269+
fn is_ident_or_lit(expr: &ast::Expr) -> bool {
270270
match &expr.kind {
271271
ast::ExprKind::Path(None, path) if path.segments.len() == 1 => true,
272+
ast::ExprKind::Lit(_) => true,
272273
ast::ExprKind::Unary(_, expr)
273274
| ast::ExprKind::AddrOf(_, _, expr)
274275
| ast::ExprKind::Paren(expr)
275-
| ast::ExprKind::Try(expr) => is_ident(expr),
276+
| ast::ExprKind::Try(expr) => is_ident_or_lit(expr),
276277
_ => false,
277278
}
278279
}
@@ -290,10 +291,10 @@ impl<'a, 'b> PairList<'a, 'b, ast::Expr> {
290291
return false;
291292
}
292293

293-
let fist_item_is_ident = is_ident(self.list[0].0);
294+
let fist_item_is_ident_or_lit = is_ident_or_lit(self.list[0].0);
294295
let second_item_is_let_chain = matches!(self.list[1].0.kind, ast::ExprKind::Let(..));
295296

296-
fist_item_is_ident && second_item_is_let_chain
297+
fist_item_is_ident_or_lit && second_item_is_let_chain
297298
}
298299
}
299300

tests/source/let_chains.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ fn test_single_line_let_chain() {
2020
if a && let Some(b) = foo() {
2121
}
2222

23+
// first item in let-chain is a bool literal
24+
if true && let Some(x) = y {
25+
26+
}
27+
2328
// first item in let-chain is a unary ! with an ident
2429
let unary_not = if !from_hir_call
2530
&& let Some(p) = parent
@@ -94,11 +99,6 @@ fn test_multi_line_let_chain() {
9499

95100
}
96101

97-
// bool literal
98-
if true && let Some(x) = y {
99-
100-
}
101-
102102
// cast to a bool
103103
if 1 as bool && let Some(x) = y {
104104

tests/target/let_chains.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ fn test_single_line_let_chain() {
5050
// first item in let-chain is an ident
5151
if a && let Some(b) = foo() {}
5252

53+
// first item in let-chain is a bool literal
54+
if true && let Some(x) = y {}
55+
5356
// first item in let-chain is a unary ! with an ident
5457
let unary_not = if !from_hir_call && let Some(p) = parent {};
5558

@@ -102,11 +105,6 @@ fn test_multi_line_let_chain() {
102105
&& let Some(x) = y
103106
{}
104107

105-
// bool literal
106-
if true
107-
&& let Some(x) = y
108-
{}
109-
110108
// cast to a bool
111109
if 1 as bool
112110
&& let Some(x) = y

0 commit comments

Comments
 (0)