@@ -63,7 +63,7 @@ pub(super) fn token(
63
63
64
64
pub ( super ) fn name_like (
65
65
sema : & Semantics < ' _ , RootDatabase > ,
66
- krate : hir:: Crate ,
66
+ krate : Option < hir:: Crate > ,
67
67
bindings_shadow_count : Option < & mut FxHashMap < hir:: Name , u32 > > ,
68
68
is_unsafe_node : & impl Fn ( AstPtr < Either < ast:: Expr , ast:: Pat > > ) -> bool ,
69
69
syntactic_name_ref_highlighting : bool ,
@@ -272,7 +272,7 @@ fn keyword(token: SyntaxToken, kind: SyntaxKind) -> Highlight {
272
272
273
273
fn highlight_name_ref (
274
274
sema : & Semantics < ' _ , RootDatabase > ,
275
- krate : hir:: Crate ,
275
+ krate : Option < hir:: Crate > ,
276
276
bindings_shadow_count : Option < & mut FxHashMap < hir:: Name , u32 > > ,
277
277
binding_hash : & mut Option < u64 > ,
278
278
is_unsafe_node : & impl Fn ( AstPtr < Either < ast:: Expr , ast:: Pat > > ) -> bool ,
@@ -401,9 +401,10 @@ fn highlight_name_ref(
401
401
NameRefClass :: ExternCrateShorthand { decl, krate : resolved_krate } => {
402
402
let mut h = HlTag :: Symbol ( SymbolKind :: Module ) . into ( ) ;
403
403
404
- if resolved_krate != krate {
405
- h |= HlMod :: Library
404
+ if krate . as_ref ( ) . is_some_and ( |krate| resolved_krate != * krate) {
405
+ h |= HlMod :: Library ;
406
406
}
407
+
407
408
let is_public = decl. visibility ( db) == hir:: Visibility :: Public ;
408
409
if is_public {
409
410
h |= HlMod :: Public
@@ -431,7 +432,7 @@ fn highlight_name(
431
432
bindings_shadow_count : Option < & mut FxHashMap < hir:: Name , u32 > > ,
432
433
binding_hash : & mut Option < u64 > ,
433
434
is_unsafe_node : & impl Fn ( AstPtr < Either < ast:: Expr , ast:: Pat > > ) -> bool ,
434
- krate : hir:: Crate ,
435
+ krate : Option < hir:: Crate > ,
435
436
name : ast:: Name ,
436
437
edition : Edition ,
437
438
) -> Highlight {
@@ -476,7 +477,7 @@ fn calc_binding_hash(name: &hir::Name, shadow_count: u32) -> u64 {
476
477
477
478
pub ( super ) fn highlight_def (
478
479
sema : & Semantics < ' _ , RootDatabase > ,
479
- krate : hir:: Crate ,
480
+ krate : Option < hir:: Crate > ,
480
481
def : Definition ,
481
482
edition : Edition ,
482
483
is_ref : bool ,
@@ -660,7 +661,7 @@ pub(super) fn highlight_def(
660
661
} ;
661
662
662
663
let def_crate = def. krate ( db) ;
663
- let is_from_other_crate = def_crate != Some ( krate) ;
664
+ let is_from_other_crate = def_crate != krate;
664
665
let is_from_builtin_crate = def_crate. is_some_and ( |def_crate| def_crate. is_builtin ( db) ) ;
665
666
let is_builtin = matches ! (
666
667
def,
@@ -681,7 +682,7 @@ pub(super) fn highlight_def(
681
682
682
683
fn highlight_method_call_by_name_ref (
683
684
sema : & Semantics < ' _ , RootDatabase > ,
684
- krate : hir:: Crate ,
685
+ krate : Option < hir:: Crate > ,
685
686
name_ref : & ast:: NameRef ,
686
687
is_unsafe_node : & impl Fn ( AstPtr < Either < ast:: Expr , ast:: Pat > > ) -> bool ,
687
688
) -> Option < Highlight > {
@@ -691,7 +692,7 @@ fn highlight_method_call_by_name_ref(
691
692
692
693
fn highlight_method_call (
693
694
sema : & Semantics < ' _ , RootDatabase > ,
694
- krate : hir:: Crate ,
695
+ krate : Option < hir:: Crate > ,
695
696
method_call : & ast:: MethodCallExpr ,
696
697
is_unsafe_node : & impl Fn ( AstPtr < Either < ast:: Expr , ast:: Pat > > ) -> bool ,
697
698
) -> Option < Highlight > {
@@ -718,7 +719,7 @@ fn highlight_method_call(
718
719
}
719
720
720
721
let def_crate = func. module ( sema. db ) . krate ( ) ;
721
- let is_from_other_crate = def_crate != krate;
722
+ let is_from_other_crate = krate . as_ref ( ) . map_or ( false , |krate| def_crate != * krate) ;
722
723
let is_from_builtin_crate = def_crate. is_builtin ( sema. db ) ;
723
724
let is_public = func. visibility ( sema. db ) == hir:: Visibility :: Public ;
724
725
@@ -791,7 +792,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
791
792
fn highlight_name_ref_by_syntax (
792
793
name : ast:: NameRef ,
793
794
sema : & Semantics < ' _ , RootDatabase > ,
794
- krate : hir:: Crate ,
795
+ krate : Option < hir:: Crate > ,
795
796
is_unsafe_node : & impl Fn ( AstPtr < Either < ast:: Expr , ast:: Pat > > ) -> bool ,
796
797
) -> Highlight {
797
798
let default = HlTag :: UnresolvedReference ;
0 commit comments