mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-03 05:13:35 +00:00
In highlight_related, when on an unsafe block, don't highlight unsafe operations of other unsafe blocks
This commit is contained in:
parent
1f4e5e82ff
commit
1efff4677e
4 changed files with 44 additions and 10 deletions
|
|
@ -28,13 +28,13 @@ use hir_expand::{
|
|||
mod_path::{ModPath, PathKind},
|
||||
name::AsName,
|
||||
};
|
||||
use hir_ty::diagnostics::unsafe_operations_for_body;
|
||||
use hir_ty::diagnostics::{unsafe_operations, unsafe_operations_for_body};
|
||||
use intern::{Interned, Symbol, sym};
|
||||
use itertools::Itertools;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use span::{Edition, FileId, SyntaxContext};
|
||||
use stdx::TupleExt;
|
||||
use stdx::{TupleExt, always};
|
||||
use syntax::{
|
||||
AstNode, AstToken, Direction, SyntaxKind, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange,
|
||||
TextSize,
|
||||
|
|
@ -1765,6 +1765,25 @@ impl<'db> SemanticsImpl<'db> {
|
|||
res
|
||||
}
|
||||
|
||||
pub fn get_unsafe_ops_for_unsafe_block(&self, block: ast::BlockExpr) -> Vec<ExprOrPatSource> {
|
||||
always!(block.unsafe_token().is_some());
|
||||
let block = self.wrap_node_infile(ast::Expr::from(block));
|
||||
let Some(def) = self.body_for(block.syntax()) else { return Vec::new() };
|
||||
let def = def.into();
|
||||
let (body, source_map) = self.db.body_with_source_map(def);
|
||||
let infer = self.db.infer(def);
|
||||
let Some(ExprOrPatId::ExprId(block)) = source_map.node_expr(block.as_ref()) else {
|
||||
return Vec::new();
|
||||
};
|
||||
let mut res = Vec::default();
|
||||
unsafe_operations(self.db, &infer, def, &body, block, &mut |node, _| {
|
||||
if let Ok(node) = source_map.expr_or_pat_syntax(node) {
|
||||
res.push(node);
|
||||
}
|
||||
});
|
||||
res
|
||||
}
|
||||
|
||||
pub fn is_unsafe_macro_call(&self, macro_call: &ast::MacroCall) -> bool {
|
||||
let Some(mac) = self.resolve_macro_call(macro_call) else { return false };
|
||||
if mac.is_asm_like(self.db) {
|
||||
|
|
|
|||
|
|
@ -1283,7 +1283,7 @@ impl<'db> SourceAnalyzer<'db> {
|
|||
{
|
||||
let mut is_unsafe = false;
|
||||
let mut walk_expr = |expr_id| {
|
||||
unsafe_operations(db, infer, def, body, expr_id, &mut |inside_unsafe_block| {
|
||||
unsafe_operations(db, infer, def, body, expr_id, &mut |_, inside_unsafe_block| {
|
||||
is_unsafe |= inside_unsafe_block == InsideUnsafeBlock::No
|
||||
})
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue