about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2021-02-26 15:52:33 +0100
committerGitHub <noreply@github.com>2021-02-26 15:52:33 +0100
commit75959fb3566f722dc141d112fab047c4c0dcb5c5 (patch)
tree26125d040910f542e45aa0b54382f0500cdff1b3 /compiler
parentee4129f70c565991c56b1c2f1fdb350c1b148917 (diff)
parentfb24a10ad39e2ed1a312c015b926cdb52ad1cef9 (diff)
downloadrust-75959fb3566f722dc141d112fab047c4c0dcb5c5.tar.gz
rust-75959fb3566f722dc141d112fab047c4c0dcb5c5.zip
Rollup merge of #82506 - estebank:unused_variable_lint, r=lcnr
Properly account for non-shorthand pattern field in unused variable lint

Fix #82488
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_passes/src/liveness.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs
index c11dc231d48..82f19770a12 100644
--- a/compiler/rustc_passes/src/liveness.rs
+++ b/compiler/rustc_passes/src/liveness.rs
@@ -367,12 +367,17 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
     }
 
     fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
-        let is_shorthand = matches!(param.pat.kind, rustc_hir::PatKind::Struct(..));
         param.pat.each_binding(|_bm, hir_id, _x, ident| {
-            let var = if is_shorthand {
-                Local(LocalInfo { id: hir_id, name: ident.name, is_shorthand: true })
-            } else {
-                Param(hir_id, ident.name)
+            let var = match param.pat.kind {
+                rustc_hir::PatKind::Struct(_, fields, _) => Local(LocalInfo {
+                    id: hir_id,
+                    name: ident.name,
+                    is_shorthand: fields
+                        .iter()
+                        .find(|f| f.ident == ident)
+                        .map_or(false, |f| f.is_shorthand),
+                }),
+                _ => Param(hir_id, ident.name),
             };
             self.add_variable(var);
         });