@@ -454,18 +454,6 @@ fn macro_call_range(macro_call: &ast::MacroCall) -> Option<TextRange> {
454
454
Some ( TextRange :: new ( range_start, range_end) )
455
455
}
456
456
457
- fn is_possibly_unsafe ( name_ref : & ast:: NameRef ) -> bool {
458
- name_ref
459
- . syntax ( )
460
- . parent ( )
461
- . and_then ( |parent| {
462
- ast:: FieldExpr :: cast ( parent. clone ( ) )
463
- . map ( |_| true )
464
- . or_else ( || ast:: RecordPatField :: cast ( parent) . map ( |_| true ) )
465
- } )
466
- . unwrap_or ( false )
467
- }
468
-
469
457
fn highlight_element (
470
458
sema : & Semantics < RootDatabase > ,
471
459
bindings_shadow_count : & mut FxHashMap < Name , u32 > ,
@@ -496,9 +484,9 @@ fn highlight_element(
496
484
match name_kind {
497
485
Some ( NameClass :: ExternCrate ( _) ) => HighlightTag :: Module . into ( ) ,
498
486
Some ( NameClass :: Definition ( def) ) => {
499
- highlight_name ( sema, db, def, None , false ) | HighlightModifier :: Definition
487
+ highlight_def ( sema, db, def, None , false ) | HighlightModifier :: Definition
500
488
}
501
- Some ( NameClass :: ConstReference ( def) ) => highlight_name ( sema, db, def, None , false ) ,
489
+ Some ( NameClass :: ConstReference ( def) ) => highlight_def ( sema, db, def, None , false ) ,
502
490
Some ( NameClass :: FieldShorthand { field, .. } ) => {
503
491
let mut h = HighlightTag :: Field . into ( ) ;
504
492
if let Definition :: Field ( field) = field {
@@ -520,7 +508,6 @@ fn highlight_element(
520
508
NAME_REF => {
521
509
let name_ref = element. into_node ( ) . and_then ( ast:: NameRef :: cast) . unwrap ( ) ;
522
510
highlight_func_by_name_ref ( sema, & name_ref) . unwrap_or_else ( || {
523
- let possibly_unsafe = is_possibly_unsafe ( & name_ref) ;
524
511
match classify_name_ref ( sema, & name_ref) {
525
512
Some ( name_kind) => match name_kind {
526
513
NameRefClass :: ExternCrate ( _) => HighlightTag :: Module . into ( ) ,
@@ -532,7 +519,13 @@ fn highlight_element(
532
519
binding_hash = Some ( calc_binding_hash ( & name, * shadow_count) )
533
520
}
534
521
} ;
535
- highlight_name ( sema, db, def, Some ( name_ref) , possibly_unsafe)
522
+ let possibly_unsafe = match name_ref. syntax ( ) . parent ( ) {
523
+ Some ( parent) => {
524
+ matches ! ( parent. kind( ) , FIELD_EXPR | RECORD_PAT_FIELD )
525
+ }
526
+ None => false ,
527
+ } ;
528
+ highlight_def ( sema, db, def, Some ( name_ref) , possibly_unsafe)
536
529
}
537
530
NameRefClass :: FieldShorthand { .. } => HighlightTag :: Field . into ( ) ,
538
531
} ,
@@ -706,8 +699,7 @@ fn highlight_func_by_name_ref(
706
699
sema : & Semantics < RootDatabase > ,
707
700
name_ref : & ast:: NameRef ,
708
701
) -> Option < Highlight > {
709
- let parent = name_ref. syntax ( ) . parent ( ) ?;
710
- let method_call = ast:: MethodCallExpr :: cast ( parent) ?;
702
+ let method_call = name_ref. syntax ( ) . parent ( ) . and_then ( ast:: MethodCallExpr :: cast) ?;
711
703
highlight_method_call ( sema, & method_call)
712
704
}
713
705
@@ -737,7 +729,7 @@ fn highlight_method_call(
737
729
Some ( h)
738
730
}
739
731
740
- fn highlight_name (
732
+ fn highlight_def (
741
733
sema : & Semantics < RootDatabase > ,
742
734
db : & RootDatabase ,
743
735
def : Definition ,
0 commit comments