@@ -89,7 +89,7 @@ pub(crate) fn highlight_related(
89
89
T ! [ break ] | T ! [ loop ] | T ! [ while ] | T ! [ continue ] if config. break_points => {
90
90
highlight_break_points ( sema, token) . remove ( & file_id)
91
91
}
92
- T ! [ unsafe ] if token. parent_ancestors ( ) . find_map ( ast:: BlockExpr :: cast) . is_some ( ) => {
92
+ T ! [ unsafe ] if token. parent ( ) . and_then ( ast:: BlockExpr :: cast) . is_some ( ) => {
93
93
highlight_unsafe_points ( sema, token) . remove ( & file_id)
94
94
}
95
95
T ! [ |] if config. closure_captures => {
@@ -715,7 +715,7 @@ pub(crate) fn highlight_unsafe_points(
715
715
) -> FxHashMap < EditionedFileId , Vec < HighlightedRange > > {
716
716
fn hl (
717
717
sema : & Semantics < ' _ , RootDatabase > ,
718
- unsafe_token : Option < SyntaxToken > ,
718
+ unsafe_token : & SyntaxToken ,
719
719
block_expr : Option < ast:: BlockExpr > ,
720
720
) -> Option < FxHashMap < EditionedFileId , Vec < HighlightedRange > > > {
721
721
let mut highlights: FxHashMap < EditionedFileId , Vec < _ > > = FxHashMap :: default ( ) ;
@@ -728,39 +728,23 @@ pub(crate) fn highlight_unsafe_points(
728
728
} ;
729
729
730
730
// highlight unsafe keyword itself
731
- let unsafe_token = unsafe_token?;
732
731
let unsafe_token_file_id = sema. hir_file_for ( & unsafe_token. parent ( ) ?) ;
733
732
push_to_highlights ( unsafe_token_file_id, Some ( unsafe_token. text_range ( ) ) ) ;
734
733
734
+ // highlight unsafe operations
735
735
if let Some ( block) = block_expr {
736
- if let Some ( node) = block. syntax ( ) . ancestors ( ) . find ( |n| ast:: Fn :: can_cast ( n. kind ( ) ) ) {
737
- if let Some ( function) = ast:: Fn :: cast ( node) {
738
- // highlight unsafe keyword of the function
739
- if let Some ( unsafe_token) = function. unsafe_token ( ) {
740
- push_to_highlights ( unsafe_token_file_id, Some ( unsafe_token. text_range ( ) ) ) ;
741
- }
742
- // highlight unsafe operations
743
- if let Some ( f) = sema. to_def ( & function) {
744
- let unsafe_ops = sema. get_unsafe_ops ( f. into ( ) ) ;
745
- for unsafe_op in unsafe_ops {
746
- push_to_highlights (
747
- unsafe_op. file_id ,
748
- Some ( unsafe_op. value . text_range ( ) ) ,
749
- ) ;
750
- }
751
- }
736
+ if let Some ( body) = sema. body_for ( InFile :: new ( unsafe_token_file_id, block. syntax ( ) ) ) {
737
+ let unsafe_ops = sema. get_unsafe_ops ( body) ;
738
+ for unsafe_op in unsafe_ops {
739
+ push_to_highlights ( unsafe_op. file_id , Some ( unsafe_op. value . text_range ( ) ) ) ;
752
740
}
753
741
}
754
742
}
755
743
756
744
Some ( highlights)
757
745
}
758
746
759
- let Some ( block_expr) = token. parent ( ) . and_then ( ast:: BlockExpr :: cast) else {
760
- return FxHashMap :: default ( ) ;
761
- } ;
762
-
763
- hl ( sema, Some ( token) , Some ( block_expr) ) . unwrap_or_default ( )
747
+ hl ( sema, & token, token. parent ( ) . and_then ( ast:: BlockExpr :: cast) ) . unwrap_or_default ( )
764
748
}
765
749
766
750
#[ cfg( test) ]
0 commit comments