From 0e24cee063e7e37d31929faaefaf5ded1732e6e1 Mon Sep 17 00:00:00 2001 From: yukang Date: Thu, 1 Dec 2022 02:21:48 +0800 Subject: fix #105028, Only suggest removing struct field from destructive binding in shorthand scenario --- compiler/rustc_passes/src/liveness.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_passes/src') 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) { -- cgit 1.4.1-3-g733a5