about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-10-19 11:03:33 +0800
committerkennytm <kennytm@gmail.com>2018-10-19 16:47:48 +0800
commit9d2eb9b7529321a6c60bf299b48440e259a7d9d9 (patch)
treeb45bc3374cee027ec3462119366a1b4df8821295
parent8d712aa1d82c44f02a8e7cc86835e2bfc95900f8 (diff)
parent40bba70823466eb1458a4fd99a4f644411b4eae4 (diff)
downloadrust-9d2eb9b7529321a6c60bf299b48440e259a7d9d9.tar.gz
rust-9d2eb9b7529321a6c60bf299b48440e259a7d9d9.zip
Rollup merge of #55166 - varkor:ret-parens, r=davidtwco
Don't warn about parentheses on `match (return)`

Fixes #55164.
-rw-r--r--src/librustc_lint/unused.rs13
-rw-r--r--src/test/ui/lint/no-unused-parens-return-block.rs9
2 files changed, 17 insertions, 5 deletions
diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs
index 76717548521..4cf2072e792 100644
--- a/src/librustc_lint/unused.rs
+++ b/src/librustc_lint/unused.rs
@@ -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);
@@ -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),
@@ -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) {
diff --git a/src/test/ui/lint/no-unused-parens-return-block.rs b/src/test/ui/lint/no-unused-parens-return-block.rs
new file mode 100644
index 00000000000..37dc519a204
--- /dev/null
+++ b/src/test/ui/lint/no-unused-parens-return-block.rs
@@ -0,0 +1,9 @@
+// run-pass
+
+#![deny(unused_parens)]
+#![allow(unreachable_code)]
+
+fn main() {
+    match (return) {} // ok
+    if (return) {} // ok
+}