Skip to content

Commit fcffac5

Browse files
committed
let_chains: Handle in unused parenthesis lint.
1 parent 70a65e9 commit fcffac5

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/librustc_lint/unused.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -324,20 +324,28 @@ impl UnusedParens {
324324
value: &ast::Expr,
325325
msg: &str,
326326
followed_by_block: bool) {
327-
if let ast::ExprKind::Paren(ref inner) = value.node {
328-
let necessary = followed_by_block && match inner.node {
329-
ast::ExprKind::Ret(_) | ast::ExprKind::Break(..) => true,
330-
_ => parser::contains_exterior_struct_lit(&inner),
331-
};
332-
if !necessary {
333-
let expr_text = if let Ok(snippet) = cx.sess().source_map()
334-
.span_to_snippet(value.span) {
335-
snippet
336-
} else {
337-
pprust::expr_to_string(value)
338-
};
339-
Self::remove_outer_parens(cx, value.span, &expr_text, msg);
327+
match value.node {
328+
ast::ExprKind::Paren(ref inner) => {
329+
let necessary = followed_by_block && match inner.node {
330+
ast::ExprKind::Ret(_) | ast::ExprKind::Break(..) => true,
331+
_ => parser::contains_exterior_struct_lit(&inner),
332+
};
333+
if !necessary {
334+
let expr_text = if let Ok(snippet) = cx.sess().source_map()
335+
.span_to_snippet(value.span) {
336+
snippet
337+
} else {
338+
pprust::expr_to_string(value)
339+
};
340+
Self::remove_outer_parens(cx, value.span, &expr_text, msg);
341+
}
342+
}
343+
ast::ExprKind::Let(_, ref expr) => {
344+
// FIXME(#60336): Properly handle `let true = (false && true)`
345+
// actually needing the parenthesis.
346+
self.check_unused_parens_expr(cx, expr, "`let` scrutinee", followed_by_block);
340347
}
348+
_ => {}
341349
}
342350
}
343351

@@ -399,8 +407,6 @@ impl EarlyLintPass for UnusedParens {
399407
let (value, msg, followed_by_block) = match e.node {
400408
If(ref cond, ..) => (cond, "`if` condition", true),
401409
While(ref cond, ..) => (cond, "`while` condition", true),
402-
IfLet(_, ref cond, ..) => (cond, "`if let` head expression", true),
403-
WhileLet(_, ref cond, ..) => (cond, "`while let` head expression", true),
404410
ForLoop(_, ref cond, ..) => (cond, "`for` head expression", true),
405411
Match(ref head, _) => (head, "`match` head expression", true),
406412
Ret(Some(ref value)) => (value, "`return` value", false),

0 commit comments

Comments
 (0)