fix the issue of shorthand in suggest_cloning

This commit is contained in:
yukang 2023-07-13 18:55:45 +08:00
parent 3ddf6f7c17
commit bdd04a62f9
6 changed files with 53 additions and 46 deletions

View file

@ -1103,6 +1103,33 @@ impl<'hir> Map<'hir> {
_ => None,
}
}
pub fn maybe_get_struct_pattern_shorthand_field(&self, expr: &Expr<'_>) -> Option<Symbol> {
let local = match expr {
Expr {
kind:
ExprKind::Path(QPath::Resolved(
None,
Path {
res: def::Res::Local(_), segments: [PathSegment { ident, .. }], ..
},
)),
..
} => Some(ident),
_ => None,
}?;
match self.find_parent(expr.hir_id)? {
Node::ExprField(field) => {
if field.ident.name == local.name && field.is_shorthand {
return Some(local.name);
}
}
_ => {}
}
None
}
}
impl<'hir> intravisit::Map<'hir> for Map<'hir> {