about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-08-15 03:21:47 +0000
committerbors <bors@rust-lang.org>2023-08-15 03:21:47 +0000
commitd7e751006cb3691d1384b74196a9cb45447acfa8 (patch)
tree5adf3ef635340f054eb909666885c41edba73774 /compiler
parentffaa32b7b646c208f20c827655bb98ff9868852e (diff)
parentc44b35e1c37f819327861b9f4d77e1469b33f457 (diff)
downloadrust-d7e751006cb3691d1384b74196a9cb45447acfa8.tar.gz
rust-d7e751006cb3691d1384b74196a9cb45447acfa8.zip
Auto merge of #113679 - chenyukang:yukang-fix-lint-113459, r=cjgillot
Match scrutinee need necessary parentheses for structs

Fixes #113459
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_lint/src/unused.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs
index 3db6b302790..6041f80753b 100644
--- a/compiler/rustc_lint/src/unused.rs
+++ b/compiler/rustc_lint/src/unused.rs
@@ -666,6 +666,24 @@ trait UnusedDelimLint {
         if !followed_by_block {
             return false;
         }
+
+        // Check if we need parens for `match &( Struct { feild:  }) {}`.
+        {
+            let mut innermost = inner;
+            loop {
+                innermost = match &innermost.kind {
+                    ExprKind::AddrOf(_, _, expr) => expr,
+                    _ => {
+                        if parser::contains_exterior_struct_lit(&innermost) {
+                            return true;
+                        } else {
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+
         let mut innermost = inner;
         loop {
             innermost = match &innermost.kind {