Rollup merge of #113599 - chenyukang:yukang-fix-use-maybe_body_owned_by, r=cjgillot
Use maybe_body_owned_by for multiple suggestions This is a continued work from https://github.com/rust-lang/rust/pull/113567 We have several other suggestions not working for closure, this PR use `maybe_body_owned_by` to fix them and add test cases for them.
This commit is contained in:
commit
f6dbf7d69b
15 changed files with 280 additions and 118 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