@@ -17,6 +17,7 @@ use rustc_middle::mir::interpret::{sign_extend, ConstValue, Scalar};
1717use rustc_middle:: ty:: subst:: { GenericArgKind , SubstsRef } ;
1818use rustc_middle:: ty:: { self , DefIdTree , Ty , TyCtxt } ;
1919use rustc_span:: symbol:: { kw, sym, Symbol } ;
20+ use smallvec:: SmallVec ;
2021use std:: mem;
2122
2223pub fn krate ( mut cx : & mut DocContext < ' _ > ) -> Crate {
@@ -349,11 +350,14 @@ pub fn qpath_to_string(p: &hir::QPath<'_>) -> String {
349350 s
350351}
351352
352- pub fn impl_for_type ( tcx : TyCtxt < ' _ > , primitive : PrimitiveType ) -> Option < DefId > {
353+ pub fn impl_for_type ( tcx : TyCtxt < ' _ > , primitive : PrimitiveType ) -> SmallVec < [ DefId ; 4 ] > {
353354 use self :: PrimitiveType :: * ;
354355
356+ let both =
357+ |a : Option < DefId > , b : Option < DefId > | -> SmallVec < _ > { a. into_iter ( ) . chain ( b) . collect ( ) } ;
358+
355359 let lang_items = tcx. lang_items ( ) ;
356- match primitive {
360+ let primary_impl = match primitive {
357361 Isize => lang_items. isize_impl ( ) ,
358362 I8 => lang_items. i8_impl ( ) ,
359363 I16 => lang_items. i16_impl ( ) ,
@@ -366,20 +370,38 @@ pub fn impl_for_type(tcx: TyCtxt<'_>, primitive: PrimitiveType) -> Option<DefId>
366370 U32 => lang_items. u32_impl ( ) ,
367371 U64 => lang_items. u64_impl ( ) ,
368372 U128 => lang_items. u128_impl ( ) ,
369- F32 => lang_items. f32_impl ( ) ,
370- F64 => lang_items. f64_impl ( ) ,
373+ F32 => return both ( lang_items. f32_impl ( ) , lang_items . f32_runtime_impl ( ) ) ,
374+ F64 => return both ( lang_items. f64_impl ( ) , lang_items . f64_runtime_impl ( ) ) ,
371375 Char => lang_items. char_impl ( ) ,
372376 Bool => lang_items. bool_impl ( ) ,
373- Str => lang_items. str_impl ( ) ,
374- Slice => lang_items. slice_impl ( ) ,
377+ Str => return both ( lang_items. str_impl ( ) , lang_items. str_alloc_impl ( ) ) ,
378+ Slice => {
379+ return lang_items
380+ . slice_impl ( )
381+ . into_iter ( )
382+ . chain ( lang_items. slice_u8_impl ( ) )
383+ . chain ( lang_items. slice_alloc_impl ( ) )
384+ . chain ( lang_items. slice_u8_alloc_impl ( ) )
385+ . collect ( ) ;
386+ }
375387 Array => lang_items. array_impl ( ) ,
376388 Tuple => None ,
377389 Unit => None ,
378- RawPointer => lang_items. const_ptr_impl ( ) ,
390+ RawPointer => {
391+ return lang_items
392+ . const_ptr_impl ( )
393+ . into_iter ( )
394+ . chain ( lang_items. mut_ptr_impl ( ) )
395+ . chain ( lang_items. const_slice_ptr_impl ( ) )
396+ . chain ( lang_items. mut_slice_ptr_impl ( ) )
397+ . collect ( ) ;
398+ }
379399 Reference => None ,
380400 Fn => None ,
381401 Never => None ,
382- }
402+ } ;
403+
404+ primary_impl. into_iter ( ) . collect ( )
383405}
384406
385407pub fn build_deref_target_impls ( cx : & DocContext < ' _ > , items : & [ Item ] , ret : & mut Vec < Item > ) {
@@ -401,8 +423,7 @@ pub fn build_deref_target_impls(cx: &DocContext<'_>, items: &[Item], ret: &mut V
401423 None => continue ,
402424 } ,
403425 } ;
404- let did = impl_for_type ( tcx, primitive) ;
405- if let Some ( did) = did {
426+ for did in impl_for_type ( tcx, primitive) {
406427 if !did. is_local ( ) {
407428 inline:: build_impl ( cx, did, None , ret) ;
408429 }
0 commit comments