about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-08-04 22:25:02 +0200
committerGitHub <noreply@github.com>2022-08-04 22:25:02 +0200
commit6b938c8491bc8d16a9a1a4d080368485f4454d31 (patch)
tree3b64e51f9b87427d80439f52038e85cecaf74fce
parentd3aa757ff8244f83a7dfe4995fe5d2da78399252 (diff)
parent8dd44f1af4ac49331d0998eebae21d54b0ab5bde (diff)
downloadrust-6b938c8491bc8d16a9a1a4d080368485f4454d31.tar.gz
rust-6b938c8491bc8d16a9a1a4d080368485f4454d31.zip
Rollup merge of #100093 - wcampbell0x2a:unused-parens-for-match-arms, r=petrochenkov
Enable unused_parens for match arms

Fixes: https://github.com/rust-lang/rust/issues/92751

Currently I can't get the `stderr` to work with `./x.py test`, but this should fix the issue. Help would be appreciated!
-rw-r--r--compiler/rustc_ast_pretty/src/pprust/state.rs2
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/region_name.rs2
-rw-r--r--compiler/rustc_lint/src/unused.rs14
-rw-r--r--compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs2
-rw-r--r--src/test/ui/lint/unused/issue-92751.rs9
-rw-r--r--src/test/ui/lint/unused/issue-92751.stderr32
6 files changed, 58 insertions, 3 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs
index 55ddd24c48a..5eb7bf6347f 100644
--- a/compiler/rustc_ast_pretty/src/pprust/state.rs
+++ b/compiler/rustc_ast_pretty/src/pprust/state.rs
@@ -377,7 +377,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
 
     fn print_string(&mut self, st: &str, style: ast::StrStyle) {
         let st = match style {
-            ast::StrStyle::Cooked => (format!("\"{}\"", st.escape_debug())),
+            ast::StrStyle::Cooked => format!("\"{}\"", st.escape_debug()),
             ast::StrStyle::Raw(n) => {
                 format!("r{delim}\"{string}\"{delim}", delim = "#".repeat(n as usize), string = st)
             }
diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs
index f68358ecfe6..a87e8bd5ba1 100644
--- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs
@@ -839,7 +839,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
             hir::Node::Expr(hir::Expr {
                 kind: hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. }),
                 ..
-            }) => (tcx.sess.source_map().end_point(fn_decl_span)),
+            }) => tcx.sess.source_map().end_point(fn_decl_span),
             _ => self.body.span,
         };
 
diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs
index 53269d18527..b6cf182916c 100644
--- a/compiler/rustc_lint/src/unused.rs
+++ b/compiler/rustc_lint/src/unused.rs
@@ -396,6 +396,7 @@ enum UnusedDelimsCtx {
     LetScrutineeExpr,
     ArrayLenExpr,
     AnonConst,
+    MatchArmExpr,
 }
 
 impl From<UnusedDelimsCtx> for &'static str {
@@ -414,6 +415,7 @@ impl From<UnusedDelimsCtx> for &'static str {
             UnusedDelimsCtx::BlockRetValue => "block return value",
             UnusedDelimsCtx::LetScrutineeExpr => "`let` scrutinee expression",
             UnusedDelimsCtx::ArrayLenExpr | UnusedDelimsCtx::AnonConst => "const expression",
+            UnusedDelimsCtx::MatchArmExpr => "match arm expression",
         }
     }
 }
@@ -805,6 +807,18 @@ impl EarlyLintPass for UnusedParens {
                 }
                 return;
             }
+            ExprKind::Match(ref _expr, ref arm) => {
+                for a in arm {
+                    self.check_unused_delims_expr(
+                        cx,
+                        &a.body,
+                        UnusedDelimsCtx::MatchArmExpr,
+                        false,
+                        None,
+                        None,
+                    );
+                }
+            }
             _ => {}
         }
 
diff --git a/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
index 98eb6e170ab..8d6f8efb600 100644
--- a/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
+++ b/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
@@ -617,7 +617,7 @@ impl SplitVarLenSlice {
             // The only admissible fixed-length slice is one of the array size. Whether `max_slice`
             // is fixed-length or variable-length, it will be the only relevant slice to output
             // here.
-            Some(_) => (0..0), // empty range
+            Some(_) => 0..0, // empty range
             // We cover all arities in the range `(self.arity..infinity)`. We split that range into
             // two: lengths smaller than `max_slice.arity()` are treated independently as
             // fixed-lengths slices, and lengths above are captured by `max_slice`.
diff --git a/src/test/ui/lint/unused/issue-92751.rs b/src/test/ui/lint/unused/issue-92751.rs
new file mode 100644
index 00000000000..2fb292736d1
--- /dev/null
+++ b/src/test/ui/lint/unused/issue-92751.rs
@@ -0,0 +1,9 @@
+#[deny(unused)]
+pub fn broken(x: Option<()>) -> i32 {
+    match x {
+        Some(()) => (1), //~ ERROR unnecessary parentheses around match arm expression
+        None => (2), //~ ERROR unnecessary parentheses around match arm expression
+    }
+}
+
+fn main() { }
diff --git a/src/test/ui/lint/unused/issue-92751.stderr b/src/test/ui/lint/unused/issue-92751.stderr
new file mode 100644
index 00000000000..0a8d8e6729c
--- /dev/null
+++ b/src/test/ui/lint/unused/issue-92751.stderr
@@ -0,0 +1,32 @@
+error: unnecessary parentheses around match arm expression
+  --> $DIR/issue-92751.rs:4:21
+   |
+LL |         Some(()) => (1),
+   |                     ^ ^
+   |
+note: the lint level is defined here
+  --> $DIR/issue-92751.rs:1:8
+   |
+LL | #[deny(unused)]
+   |        ^^^^^^
+   = note: `#[deny(unused_parens)]` implied by `#[deny(unused)]`
+help: remove these parentheses
+   |
+LL -         Some(()) => (1),
+LL +         Some(()) => 1,
+   |
+
+error: unnecessary parentheses around match arm expression
+  --> $DIR/issue-92751.rs:5:17
+   |
+LL |         None => (2),
+   |                 ^ ^
+   |
+help: remove these parentheses
+   |
+LL -         None => (2),
+LL +         None => 2,
+   |
+
+error: aborting due to 2 previous errors
+