about summary refs log tree commit diff
path: root/compiler/rustc_passes/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-12-06 16:54:53 +0100
committerGitHub <noreply@github.com>2022-12-06 16:54:53 +0100
commit90d84ce3a23063a9c9e10705138e7c9fbcbb24f8 (patch)
tree38fc601947ec08a2338ed63a945a91d5ce04127e /compiler/rustc_passes/src
parentb29a4f9bac50d1b1e24b90cc6de28af366825763 (diff)
parent0e24cee063e7e37d31929faaefaf5ded1732e6e1 (diff)
downloadrust-90d84ce3a23063a9c9e10705138e7c9fbcbb24f8.tar.gz
rust-90d84ce3a23063a9c9e10705138e7c9fbcbb24f8.zip
Rollup merge of #105174 - chenyukang:yukang/fix-105028-unused, r=eholk
Suggest removing struct field from destructive binding only in shorthand scenario

Fixes #105028
Diffstat (limited to 'compiler/rustc_passes/src')
-rw-r--r--compiler/rustc_passes/src/liveness.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs
index 2234837050b..1f65cc8b609 100644
--- a/compiler/rustc_passes/src/liveness.rs
+++ b/compiler/rustc_passes/src/liveness.rs
@@ -1548,7 +1548,13 @@ impl<'tcx> Liveness<'_, 'tcx> {
                 .or_insert_with(|| (ln, var, vec![id_and_sp]));
         });
 
-        let can_remove = matches!(&pat.kind, hir::PatKind::Struct(_, _, true));
+        let can_remove = match pat.kind {
+            hir::PatKind::Struct(_, fields, true) => {
+                // if all fields are shorthand, remove the struct field, otherwise, mark with _ as prefix
+                fields.iter().all(|f| f.is_shorthand)
+            }
+            _ => false,
+        };
 
         for (_, (ln, var, hir_ids_and_spans)) in vars {
             if self.used_on_entry(ln, var) {