fix the issue of shorthand in suggest_cloning
This commit is contained in:
parent
3ddf6f7c17
commit
bdd04a62f9
6 changed files with 53 additions and 46 deletions
|
@ -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> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue