@@ -6,12 +6,13 @@ use crate::{
66 navigation_target:: { self , ToNav } ,
77} ;
88use hir:: {
9- AsAssocItem , AssocItem , CallableKind , FileRange , HasCrate , InFile , ModuleDef , Semantics , sym,
9+ AsAssocItem , AssocItem , CallableKind , FileRange , HasCrate , InFile , ModuleDef , PathResolution ,
10+ Semantics , sym,
1011} ;
1112use ide_db:: {
1213 RootDatabase , SymbolKind ,
1314 base_db:: { AnchoredPath , SourceDatabase } ,
14- defs:: { Definition , IdentClass } ,
15+ defs:: { Definition , IdentClass , find_std_module } ,
1516 famous_defs:: FamousDefs ,
1617 helpers:: pick_best_token,
1718} ;
@@ -90,6 +91,9 @@ pub(crate) fn goto_definition(
9091 if let Some ( navs) = find_definition_for_known_blanket_dual_impls ( sema, & token. value ) {
9192 return Some ( navs) ;
9293 }
94+ if let Some ( navs) = find_definition_for_builtin_types ( sema, & token. value , edition) {
95+ return Some ( navs) ;
96+ }
9397
9498 let parent = token. value . parent ( ) ?;
9599
@@ -204,6 +208,25 @@ fn find_definition_for_known_blanket_dual_impls(
204208 Some ( def_to_nav ( sema. db , def) )
205209}
206210
211+ // If the token is a builtin type search the definition from the rustdoc module shims.
212+ fn find_definition_for_builtin_types (
213+ sema : & Semantics < ' _ , RootDatabase > ,
214+ original_token : & SyntaxToken ,
215+ edition : Edition ,
216+ ) -> Option < Vec < NavigationTarget > > {
217+ let path = original_token. parent_ancestors ( ) . find_map ( ast:: Path :: cast) ?;
218+ let res = sema. resolve_path ( & path) ?;
219+ let PathResolution :: Def ( ModuleDef :: BuiltinType ( builtin) ) = res else {
220+ return None ;
221+ } ;
222+
223+ let fd = FamousDefs ( sema, sema. scope ( path. syntax ( ) ) ?. krate ( ) ) ;
224+ let primitive_mod = format ! ( "prim_{}" , builtin. name( ) . display( fd. 0 . db, edition) ) ;
225+ let doc_owner = find_std_module ( & fd, & primitive_mod, edition) ?;
226+
227+ Some ( def_to_nav ( sema. db , doc_owner. into ( ) ) )
228+ }
229+
207230fn try_lookup_include_path (
208231 sema : & Semantics < ' _ , RootDatabase > ,
209232 token : InFile < ast:: String > ,
0 commit comments