@@ -485,8 +485,8 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
485485 }
486486
487487 /// Returns `true` if the `node` is inside an `unsafe` context.
488- pub fn is_inside_unsafe ( & self , node : & SyntaxNode ) -> bool {
489- self . imp . is_inside_unsafe ( node )
488+ pub fn is_inside_unsafe ( & self , expr : & ast :: Expr ) -> bool {
489+ self . imp . is_inside_unsafe ( expr )
490490 }
491491}
492492
@@ -1471,17 +1471,18 @@ impl<'db> SemanticsImpl<'db> {
14711471 . unwrap_or ( false )
14721472 }
14731473
1474- fn is_inside_unsafe ( & self , node : & SyntaxNode ) -> bool {
1474+ fn is_inside_unsafe ( & self , expr : & ast :: Expr ) -> bool {
14751475 let item_or_variant = |ancestor : SyntaxNode | {
14761476 if ast:: Item :: can_cast ( ancestor. kind ( ) ) {
14771477 ast:: Item :: cast ( ancestor) . map ( Either :: Left )
14781478 } else {
14791479 ast:: Variant :: cast ( ancestor) . map ( Either :: Right )
14801480 }
14811481 } ;
1482- let Some ( enclosing_item) = node . ancestors ( ) . find_map ( item_or_variant) else { return false } ;
1482+ let Some ( enclosing_item) = expr . syntax ( ) . ancestors ( ) . find_map ( item_or_variant) else { return false } ;
14831483
14841484 let def = match & enclosing_item {
1485+ Either :: Left ( ast:: Item :: Fn ( it) ) if it. unsafe_token ( ) . is_some ( ) => return true ,
14851486 Either :: Left ( ast:: Item :: Fn ( it) ) => {
14861487 self . to_def ( it) . map ( <_ >:: into) . map ( DefWithBodyId :: FunctionId )
14871488 }
@@ -1497,15 +1498,11 @@ impl<'db> SemanticsImpl<'db> {
14971498 let Some ( def) = def else { return false } ;
14981499 let enclosing_node = enclosing_item. as_ref ( ) . either ( |i| i. syntax ( ) , |v| v. syntax ( ) ) ;
14991500
1500- if ast:: Fn :: cast ( enclosing_node. clone ( ) ) . and_then ( |f| f. unsafe_token ( ) ) . is_some ( ) {
1501- return true ;
1502- }
1503-
15041501 let ( body, source_map) = self . db . body_with_source_map ( def) ;
15051502
1506- let file_id = self . find_file ( node ) . file_id ;
1503+ let file_id = self . find_file ( expr . syntax ( ) ) . file_id ;
15071504
1508- let Some ( mut parent) = node . parent ( ) else { return false } ;
1505+ let Some ( mut parent) = expr . syntax ( ) . parent ( ) else { return false } ;
15091506 loop {
15101507 if & parent == enclosing_node {
15111508 break false ;
0 commit comments