mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
feat: Tag macro calls as unsafe if they expand to unsafe expressions
This commit is contained in:
parent
5a87f09a71
commit
68de7b30e0
25 changed files with 208 additions and 68 deletions
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue