let_chains: Handle in unused parenthesis lint.

This commit is contained in:
Mazdak Farrokhzad 2019-05-15 16:03:43 +02:00
parent 70a65e9d1f
commit fcffac5eea

View File

@ -324,20 +324,28 @@ fn check_unused_parens_expr(&self,
value: &ast::Expr, value: &ast::Expr,
msg: &str, msg: &str,
followed_by_block: bool) { followed_by_block: bool) {
if let ast::ExprKind::Paren(ref inner) = value.node { match value.node {
let necessary = followed_by_block && match inner.node { ast::ExprKind::Paren(ref inner) => {
ast::ExprKind::Ret(_) | ast::ExprKind::Break(..) => true, let necessary = followed_by_block && match inner.node {
_ => parser::contains_exterior_struct_lit(&inner), ast::ExprKind::Ret(_) | ast::ExprKind::Break(..) => true,
}; _ => parser::contains_exterior_struct_lit(&inner),
if !necessary { };
let expr_text = if let Ok(snippet) = cx.sess().source_map() if !necessary {
.span_to_snippet(value.span) { let expr_text = if let Ok(snippet) = cx.sess().source_map()
snippet .span_to_snippet(value.span) {
} else { snippet
pprust::expr_to_string(value) } else {
}; pprust::expr_to_string(value)
Self::remove_outer_parens(cx, value.span, &expr_text, msg); };
Self::remove_outer_parens(cx, value.span, &expr_text, msg);
}
} }
ast::ExprKind::Let(_, ref expr) => {
// FIXME(#60336): Properly handle `let true = (false && true)`
// actually needing the parenthesis.
self.check_unused_parens_expr(cx, expr, "`let` scrutinee", followed_by_block);
}
_ => {}
} }
} }
@ -399,8 +407,6 @@ fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
let (value, msg, followed_by_block) = match e.node { let (value, msg, followed_by_block) = match e.node {
If(ref cond, ..) => (cond, "`if` condition", true), If(ref cond, ..) => (cond, "`if` condition", true),
While(ref cond, ..) => (cond, "`while` condition", true), While(ref cond, ..) => (cond, "`while` condition", true),
IfLet(_, ref cond, ..) => (cond, "`if let` head expression", true),
WhileLet(_, ref cond, ..) => (cond, "`while let` head expression", true),
ForLoop(_, ref cond, ..) => (cond, "`for` head expression", true), ForLoop(_, ref cond, ..) => (cond, "`for` head expression", true),
Match(ref head, _) => (head, "`match` head expression", true), Match(ref head, _) => (head, "`match` head expression", true),
Ret(Some(ref value)) => (value, "`return` value", false), Ret(Some(ref value)) => (value, "`return` value", false),