feat: Tag macro calls as unsafe if they expand to unsafe expressions

This commit is contained in:
Lukas Wirth 2022-03-20 19:07:44 +01:00
parent 5a87f09a71
commit 68de7b30e0
25 changed files with 208 additions and 68 deletions

View file

@ -15,6 +15,13 @@ pub fn expr_as_name_ref(expr: &ast::Expr) -> Option<ast::NameRef> {
}
}
pub fn full_path_of_name_ref(name_ref: &ast::NameRef) -> Option<ast::Path> {
let mut ancestors = name_ref.syntax().ancestors();
let _ = ancestors.next()?; // skip self
let _ = ancestors.next().filter(|it| ast::PathSegment::can_cast(it.kind()))?; // skip self
ancestors.take_while(|it| ast::Path::can_cast(it.kind())).last().and_then(ast::Path::cast)
}
pub fn block_as_lone_tail(block: &ast::BlockExpr) -> Option<ast::Expr> {
block.statements().next().is_none().then(|| block.tail_expr()).flatten()
}