Skip to content

Commit

Permalink
Rollup merge of rust-lang#55166 - varkor:ret-parens, r=davidtwco
Browse files Browse the repository at this point in the history
Don't warn about parentheses on `match (return)`

Fixes rust-lang#55164.
  • Loading branch information
kennytm committed Oct 19, 2018
2 parents 8d712aa + 40bba70 commit 9d2eb9b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,13 @@ impl UnusedParens {
cx: &EarlyContext,
value: &ast::Expr,
msg: &str,
struct_lit_needs_parens: bool) {
followed_by_block: bool) {
if let ast::ExprKind::Paren(ref inner) = value.node {
let necessary = struct_lit_needs_parens &&
parser::contains_exterior_struct_lit(&inner);
let necessary = followed_by_block && if let ast::ExprKind::Ret(_) = inner.node {
true
} else {
parser::contains_exterior_struct_lit(&inner)
};
if !necessary {
let pattern = pprust::expr_to_string(value);
Self::remove_outer_parens(cx, value.span, &pattern, msg);
Expand Down Expand Up @@ -343,7 +346,7 @@ impl LintPass for UnusedParens {
impl EarlyLintPass for UnusedParens {
fn check_expr(&mut self, cx: &EarlyContext, e: &ast::Expr) {
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),
While(ref cond, ..) => (cond, "`while` condition", true),
IfLet(_, ref cond, ..) => (cond, "`if let` head expression", true),
Expand Down Expand Up @@ -380,7 +383,7 @@ impl EarlyLintPass for UnusedParens {
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) {
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/lint/no-unused-parens-return-block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// run-pass

#![deny(unused_parens)]
#![allow(unreachable_code)]

fn main() {
match (return) {} // ok
if (return) {} // ok
}

0 comments on commit 9d2eb9b

Please sign in to comment.