@@ -6,12 +6,13 @@ use crate::{
6
6
navigation_target:: { self , ToNav } ,
7
7
} ;
8
8
use hir:: {
9
- AsAssocItem , AssocItem , CallableKind , FileRange , HasCrate , InFile , ModuleDef , Semantics , sym,
9
+ AsAssocItem , AssocItem , CallableKind , FileRange , HasCrate , InFile , ModuleDef , PathResolution ,
10
+ Semantics , sym,
10
11
} ;
11
12
use ide_db:: {
12
13
RootDatabase , SymbolKind ,
13
14
base_db:: { AnchoredPath , SourceDatabase } ,
14
- defs:: { Definition , IdentClass } ,
15
+ defs:: { Definition , IdentClass , find_std_module } ,
15
16
famous_defs:: FamousDefs ,
16
17
helpers:: pick_best_token,
17
18
} ;
@@ -90,6 +91,9 @@ pub(crate) fn goto_definition(
90
91
if let Some ( navs) = find_definition_for_known_blanket_dual_impls ( sema, & token. value ) {
91
92
return Some ( navs) ;
92
93
}
94
+ if let Some ( navs) = find_definition_for_builtin_types ( sema, & token. value , edition) {
95
+ return Some ( navs) ;
96
+ }
93
97
94
98
let parent = token. value . parent ( ) ?;
95
99
@@ -204,6 +208,25 @@ fn find_definition_for_known_blanket_dual_impls(
204
208
Some ( def_to_nav ( sema. db , def) )
205
209
}
206
210
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
+
207
230
fn try_lookup_include_path (
208
231
sema : & Semantics < ' _ , RootDatabase > ,
209
232
token : InFile < ast:: String > ,
0 commit comments