Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/highlight_related.rs')
-rw-r--r--crates/ide/src/highlight_related.rs60
1 files changed, 37 insertions, 23 deletions
diff --git a/crates/ide/src/highlight_related.rs b/crates/ide/src/highlight_related.rs
index 356bd69aa4..04ce5a7567 100644
--- a/crates/ide/src/highlight_related.rs
+++ b/crates/ide/src/highlight_related.rs
@@ -277,7 +277,7 @@ fn highlight_references(
Definition::Module(module) => {
NavigationTarget::from_module_to_decl(sema.db, module)
}
- def => match def.try_to_nav(sema.db) {
+ def => match def.try_to_nav(sema) {
Some(it) => it,
None => continue,
},
@@ -722,20 +722,19 @@ impl<'a> WalkExpandedExprCtx<'a> {
self.depth += 1;
}
- if let ast::Expr::MacroExpr(expr) = expr {
- if let Some(expanded) =
+ if let ast::Expr::MacroExpr(expr) = expr
+ && let Some(expanded) =
expr.macro_call().and_then(|call| self.sema.expand_macro_call(&call))
- {
- match_ast! {
- match (expanded.value) {
- ast::MacroStmts(it) => {
- self.handle_expanded(it, cb);
- },
- ast::Expr(it) => {
- self.walk(&it, cb);
- },
- _ => {}
- }
+ {
+ match_ast! {
+ match (expanded.value) {
+ ast::MacroStmts(it) => {
+ self.handle_expanded(it, cb);
+ },
+ ast::Expr(it) => {
+ self.walk(&it, cb);
+ },
+ _ => {}
}
}
}
@@ -755,10 +754,10 @@ impl<'a> WalkExpandedExprCtx<'a> {
}
for stmt in expanded.statements() {
- if let ast::Stmt::ExprStmt(stmt) = stmt {
- if let Some(expr) = stmt.expr() {
- self.walk(&expr, cb);
- }
+ if let ast::Stmt::ExprStmt(stmt) = stmt
+ && let Some(expr) = stmt.expr()
+ {
+ self.walk(&expr, cb);
}
}
}
@@ -807,11 +806,9 @@ pub(crate) fn highlight_unsafe_points(
// highlight unsafe operations
if let Some(block) = block_expr {
- if let Some(body) = sema.body_for(InFile::new(unsafe_token_file_id, block.syntax())) {
- let unsafe_ops = sema.get_unsafe_ops(body);
- for unsafe_op in unsafe_ops {
- push_to_highlights(unsafe_op.file_id, Some(unsafe_op.value.text_range()));
- }
+ let unsafe_ops = sema.get_unsafe_ops_for_unsafe_block(block);
+ for unsafe_op in unsafe_ops {
+ push_to_highlights(unsafe_op.file_id, Some(unsafe_op.value.text_range()));
}
}
@@ -2536,4 +2533,21 @@ fn foo() {
"#,
);
}
+
+ #[test]
+ fn different_unsafe_block() {
+ check(
+ r#"
+fn main() {
+ unsafe$0 {
+ // ^^^^^^
+ *(0 as *const u8)
+ // ^^^^^^^^^^^^^^^^^
+ };
+ unsafe { *(1 as *const u8) };
+ unsafe { *(2 as *const u8) };
+}
+ "#,
+ );
+ }
}