@@ -63,7 +63,7 @@ pub(super) fn token(
6363
6464pub ( super ) fn name_like (
6565 sema : & Semantics < ' _ , RootDatabase > ,
66- krate : hir:: Crate ,
66+ krate : Option < hir:: Crate > ,
6767 bindings_shadow_count : Option < & mut FxHashMap < hir:: Name , u32 > > ,
6868 is_unsafe_node : & impl Fn ( AstPtr < Either < ast:: Expr , ast:: Pat > > ) -> bool ,
6969 syntactic_name_ref_highlighting : bool ,
@@ -272,7 +272,7 @@ fn keyword(token: SyntaxToken, kind: SyntaxKind) -> Highlight {
272272
273273fn highlight_name_ref (
274274 sema : & Semantics < ' _ , RootDatabase > ,
275- krate : hir:: Crate ,
275+ krate : Option < hir:: Crate > ,
276276 bindings_shadow_count : Option < & mut FxHashMap < hir:: Name , u32 > > ,
277277 binding_hash : & mut Option < u64 > ,
278278 is_unsafe_node : & impl Fn ( AstPtr < Either < ast:: Expr , ast:: Pat > > ) -> bool ,
@@ -401,9 +401,10 @@ fn highlight_name_ref(
401401 NameRefClass :: ExternCrateShorthand { decl, krate : resolved_krate } => {
402402 let mut h = HlTag :: Symbol ( SymbolKind :: Module ) . into ( ) ;
403403
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 ;
406406 }
407+
407408 let is_public = decl. visibility ( db) == hir:: Visibility :: Public ;
408409 if is_public {
409410 h |= HlMod :: Public
@@ -431,7 +432,7 @@ fn highlight_name(
431432 bindings_shadow_count : Option < & mut FxHashMap < hir:: Name , u32 > > ,
432433 binding_hash : & mut Option < u64 > ,
433434 is_unsafe_node : & impl Fn ( AstPtr < Either < ast:: Expr , ast:: Pat > > ) -> bool ,
434- krate : hir:: Crate ,
435+ krate : Option < hir:: Crate > ,
435436 name : ast:: Name ,
436437 edition : Edition ,
437438) -> Highlight {
@@ -476,7 +477,7 @@ fn calc_binding_hash(name: &hir::Name, shadow_count: u32) -> u64 {
476477
477478pub ( super ) fn highlight_def (
478479 sema : & Semantics < ' _ , RootDatabase > ,
479- krate : hir:: Crate ,
480+ krate : Option < hir:: Crate > ,
480481 def : Definition ,
481482 edition : Edition ,
482483 is_ref : bool ,
@@ -660,7 +661,7 @@ pub(super) fn highlight_def(
660661 } ;
661662
662663 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;
664665 let is_from_builtin_crate = def_crate. is_some_and ( |def_crate| def_crate. is_builtin ( db) ) ;
665666 let is_builtin = matches ! (
666667 def,
@@ -681,7 +682,7 @@ pub(super) fn highlight_def(
681682
682683fn highlight_method_call_by_name_ref (
683684 sema : & Semantics < ' _ , RootDatabase > ,
684- krate : hir:: Crate ,
685+ krate : Option < hir:: Crate > ,
685686 name_ref : & ast:: NameRef ,
686687 is_unsafe_node : & impl Fn ( AstPtr < Either < ast:: Expr , ast:: Pat > > ) -> bool ,
687688) -> Option < Highlight > {
@@ -691,7 +692,7 @@ fn highlight_method_call_by_name_ref(
691692
692693fn highlight_method_call (
693694 sema : & Semantics < ' _ , RootDatabase > ,
694- krate : hir:: Crate ,
695+ krate : Option < hir:: Crate > ,
695696 method_call : & ast:: MethodCallExpr ,
696697 is_unsafe_node : & impl Fn ( AstPtr < Either < ast:: Expr , ast:: Pat > > ) -> bool ,
697698) -> Option < Highlight > {
@@ -718,7 +719,7 @@ fn highlight_method_call(
718719 }
719720
720721 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) ;
722723 let is_from_builtin_crate = def_crate. is_builtin ( sema. db ) ;
723724 let is_public = func. visibility ( sema. db ) == hir:: Visibility :: Public ;
724725
@@ -791,7 +792,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
791792fn highlight_name_ref_by_syntax (
792793 name : ast:: NameRef ,
793794 sema : & Semantics < ' _ , RootDatabase > ,
794- krate : hir:: Crate ,
795+ krate : Option < hir:: Crate > ,
795796 is_unsafe_node : & impl Fn ( AstPtr < Either < ast:: Expr , ast:: Pat > > ) -> bool ,
796797) -> Highlight {
797798 let default = HlTag :: UnresolvedReference ;
0 commit comments