Don't warn about parentheses on match (return)
This commit is contained in:
parent
5ea8eb55cd
commit
0a858dc859
2 changed files with 14 additions and 5 deletions
|
@ -276,10 +276,13 @@ impl UnusedParens {
|
||||||
cx: &EarlyContext,
|
cx: &EarlyContext,
|
||||||
value: &ast::Expr,
|
value: &ast::Expr,
|
||||||
msg: &str,
|
msg: &str,
|
||||||
struct_lit_needs_parens: bool) {
|
followed_by_block: bool) {
|
||||||
if let ast::ExprKind::Paren(ref inner) = value.node {
|
if let ast::ExprKind::Paren(ref inner) = value.node {
|
||||||
let necessary = struct_lit_needs_parens &&
|
let necessary = followed_by_block && if let ast::ExprKind::Ret(_) = inner.node {
|
||||||
parser::contains_exterior_struct_lit(&inner);
|
true
|
||||||
|
} else {
|
||||||
|
parser::contains_exterior_struct_lit(&inner)
|
||||||
|
};
|
||||||
if !necessary {
|
if !necessary {
|
||||||
let pattern = pprust::expr_to_string(value);
|
let pattern = pprust::expr_to_string(value);
|
||||||
Self::remove_outer_parens(cx, value.span, &pattern, msg);
|
Self::remove_outer_parens(cx, value.span, &pattern, msg);
|
||||||
|
@ -343,7 +346,7 @@ impl LintPass for UnusedParens {
|
||||||
impl EarlyLintPass for UnusedParens {
|
impl EarlyLintPass for UnusedParens {
|
||||||
fn check_expr(&mut self, cx: &EarlyContext, e: &ast::Expr) {
|
fn check_expr(&mut self, cx: &EarlyContext, e: &ast::Expr) {
|
||||||
use syntax::ast::ExprKind::*;
|
use syntax::ast::ExprKind::*;
|
||||||
let (value, msg, struct_lit_needs_parens) = 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),
|
IfLet(_, ref cond, ..) => (cond, "`if let` head expression", true),
|
||||||
|
@ -380,7 +383,7 @@ impl EarlyLintPass for UnusedParens {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
self.check_unused_parens_expr(cx, &value, msg, struct_lit_needs_parens);
|
self.check_unused_parens_expr(cx, &value, msg, followed_by_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_pat(&mut self, cx: &EarlyContext, p: &ast::Pat) {
|
fn check_pat(&mut self, cx: &EarlyContext, p: &ast::Pat) {
|
||||||
|
|
6
src/test/ui/lint/no-unused-parens-return-block.rs
Normal file
6
src/test/ui/lint/no-unused-parens-return-block.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
// run-pass
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
match (return) {} // ok
|
||||||
|
if (return) {} // ok
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue