1
Fork 0

Rollup merge of #105174 - chenyukang:yukang/fix-105028-unused, r=eholk

Suggest removing struct field from destructive binding only in shorthand scenario

Fixes #105028
This commit is contained in:
Matthias Krüger 2022-12-06 16:54:53 +01:00 committed by GitHub
commit 90d84ce3a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 2 deletions

View file

@ -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) {