Use shorthand record syntax when renaming struct initializer field

This commit is contained in:
Lukas Wirth 2020-11-14 17:49:36 +01:00
parent 99fa139bea
commit e55a44a831
4 changed files with 68 additions and 19 deletions

View file

@ -22,6 +22,18 @@ impl ast::Expr {
_ => false,
}
}
pub fn name_ref(&self) -> Option<ast::NameRef> {
if let ast::Expr::PathExpr(expr) = self {
let path = expr.path()?;
let segment = path.segment()?;
let name_ref = segment.name_ref()?;
if path.qualifier().is_none() {
return Some(name_ref);
}
}
None
}
}
#[derive(Debug, Clone, PartialEq, Eq)]