@@ -16,6 +16,7 @@ use rustc_span::hygiene::MacroKind;
1616use rustc_span:: symbol:: Ident ;
1717use rustc_span:: symbol:: Symbol ;
1818use rustc_span:: DUMMY_SP ;
19+ use smallvec:: SmallVec ;
1920
2021use std:: cell:: Cell ;
2122use std:: ops:: Range ;
@@ -270,18 +271,21 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
270271 . ok_or ( ErrorKind :: ResolutionFailure ) ?;
271272
272273 if let Some ( ( path, 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 ) ;
285289 }
286290
287291 let ( _, ty_res) = cx
@@ -1238,26 +1242,6 @@ fn is_primitive(path_str: &str, ns: Namespace) -> Option<(&'static str, Res)> {
12381242 }
12391243}
12401244
1241- fn primitive_impl ( cx : & DocContext < ' _ > , path_str : & str ) -> Option < DefId > {
1242- let tcx = cx. tcx ;
1243- match path_str {
1244- "u8" => tcx. lang_items ( ) . u8_impl ( ) ,
1245- "u16" => tcx. lang_items ( ) . u16_impl ( ) ,
1246- "u32" => tcx. lang_items ( ) . u32_impl ( ) ,
1247- "u64" => tcx. lang_items ( ) . u64_impl ( ) ,
1248- "u128" => tcx. lang_items ( ) . u128_impl ( ) ,
1249- "usize" => tcx. lang_items ( ) . usize_impl ( ) ,
1250- "i8" => tcx. lang_items ( ) . i8_impl ( ) ,
1251- "i16" => tcx. lang_items ( ) . i16_impl ( ) ,
1252- "i32" => tcx. lang_items ( ) . i32_impl ( ) ,
1253- "i64" => tcx. lang_items ( ) . i64_impl ( ) ,
1254- "i128" => tcx. lang_items ( ) . i128_impl ( ) ,
1255- "isize" => tcx. lang_items ( ) . isize_impl ( ) ,
1256- "f32" => tcx. lang_items ( ) . f32_impl ( ) ,
1257- "f64" => tcx. lang_items ( ) . f64_impl ( ) ,
1258- "str" => tcx. lang_items ( ) . str_impl ( ) ,
1259- "bool" => tcx. lang_items ( ) . bool_impl ( ) ,
1260- "char" => tcx. lang_items ( ) . char_impl ( ) ,
1261- _ => None ,
1262- }
1245+ fn primitive_impl ( cx : & DocContext < ' _ > , path_str : & str ) -> Option < & ' static SmallVec < [ DefId ; 4 ] > > {
1246+ Some ( PrimitiveType :: from_symbol ( Symbol :: intern ( path_str) ) ?. impls ( cx. tcx ) )
12631247}
0 commit comments