@@ -16,6 +16,7 @@ use rustc_span::hygiene::MacroKind;
16
16
use rustc_span:: symbol:: Ident ;
17
17
use rustc_span:: symbol:: Symbol ;
18
18
use rustc_span:: DUMMY_SP ;
19
+ use smallvec:: SmallVec ;
19
20
20
21
use std:: cell:: Cell ;
21
22
use std:: ops:: Range ;
@@ -270,18 +271,21 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
270
271
. ok_or ( ErrorKind :: ResolutionFailure ) ?;
271
272
272
273
if let Some ( prim) = is_primitive ( & path, TypeNS ) {
273
- let did = primitive_impl ( cx, & path) . ok_or ( ErrorKind :: ResolutionFailure ) ?;
274
- return cx
275
- . tcx
276
- . associated_items ( did)
277
- . filter_by_name_unhygienic ( item_name)
278
- . next ( )
279
- . and_then ( |item| match item. kind {
280
- ty:: AssocKind :: Fn => Some ( "method" ) ,
281
- _ => None ,
282
- } )
283
- . map ( |out| ( prim, Some ( format ! ( "{}#{}.{}" , path, out, item_name) ) ) )
284
- . ok_or ( ErrorKind :: ResolutionFailure ) ;
274
+ for & impl_ in primitive_impl ( cx, & path) . ok_or ( ErrorKind :: ResolutionFailure ) ? {
275
+ let link = cx
276
+ . tcx
277
+ . associated_items ( impl_)
278
+ . find_by_name_and_namespace ( cx. tcx , Ident :: with_dummy_span ( item_name) , ns, impl_)
279
+ . and_then ( |item| match item. kind {
280
+ ty:: AssocKind :: Fn => Some ( "method" ) ,
281
+ _ => None ,
282
+ } )
283
+ . map ( |out| ( prim, Some ( format ! ( "{}#{}.{}" , path, out, item_name) ) ) ) ;
284
+ if let Some ( link) = link {
285
+ return Ok ( link) ;
286
+ }
287
+ }
288
+ return Err ( ErrorKind :: ResolutionFailure ) ;
285
289
}
286
290
287
291
let ( _, ty_res) = cx
@@ -1227,26 +1231,6 @@ fn is_primitive(path_str: &str, ns: Namespace) -> Option<Res> {
1227
1231
if ns == TypeNS { PRIMITIVES . iter ( ) . find ( |x| x. 0 == path_str) . map ( |x| x. 1 ) } else { None }
1228
1232
}
1229
1233
1230
- fn primitive_impl ( cx : & DocContext < ' _ > , path_str : & str ) -> Option < DefId > {
1231
- let tcx = cx. tcx ;
1232
- match path_str {
1233
- "u8" => tcx. lang_items ( ) . u8_impl ( ) ,
1234
- "u16" => tcx. lang_items ( ) . u16_impl ( ) ,
1235
- "u32" => tcx. lang_items ( ) . u32_impl ( ) ,
1236
- "u64" => tcx. lang_items ( ) . u64_impl ( ) ,
1237
- "u128" => tcx. lang_items ( ) . u128_impl ( ) ,
1238
- "usize" => tcx. lang_items ( ) . usize_impl ( ) ,
1239
- "i8" => tcx. lang_items ( ) . i8_impl ( ) ,
1240
- "i16" => tcx. lang_items ( ) . i16_impl ( ) ,
1241
- "i32" => tcx. lang_items ( ) . i32_impl ( ) ,
1242
- "i64" => tcx. lang_items ( ) . i64_impl ( ) ,
1243
- "i128" => tcx. lang_items ( ) . i128_impl ( ) ,
1244
- "isize" => tcx. lang_items ( ) . isize_impl ( ) ,
1245
- "f32" => tcx. lang_items ( ) . f32_impl ( ) ,
1246
- "f64" => tcx. lang_items ( ) . f64_impl ( ) ,
1247
- "str" => tcx. lang_items ( ) . str_impl ( ) ,
1248
- "bool" => tcx. lang_items ( ) . bool_impl ( ) ,
1249
- "char" => tcx. lang_items ( ) . char_impl ( ) ,
1250
- _ => None ,
1251
- }
1234
+ fn primitive_impl ( cx : & DocContext < ' _ > , path_str : & str ) -> Option < & ' static SmallVec < [ DefId ; 4 ] > > {
1235
+ Some ( PrimitiveType :: from_symbol ( Symbol :: intern ( path_str) ) ?. impls ( cx. tcx ) )
1252
1236
}
0 commit comments