@@ -15,7 +15,7 @@ use rustc_hir::def::{DefKind, Res};
1515use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
1616use rustc_middle:: mir:: interpret:: { sign_extend, ConstValue , Scalar } ;
1717use rustc_middle:: ty:: subst:: { GenericArgKind , SubstsRef } ;
18- use rustc_middle:: ty:: { self , DefIdTree , Ty } ;
18+ use rustc_middle:: ty:: { self , DefIdTree , Ty , TyCtxt } ;
1919use rustc_span:: symbol:: { kw, sym, Symbol } ;
2020use std:: mem;
2121
@@ -349,8 +349,39 @@ pub fn qpath_to_string(p: &hir::QPath<'_>) -> String {
349349 s
350350}
351351
352- pub fn build_deref_target_impls ( cx : & DocContext < ' _ > , items : & [ Item ] , ret : & mut Vec < Item > ) {
352+ pub fn impl_for_type ( tcx : TyCtxt < ' _ > , primitive : PrimitiveType ) -> Option < DefId > {
353353 use self :: PrimitiveType :: * ;
354+
355+ match primitive {
356+ Isize => tcx. lang_items ( ) . isize_impl ( ) ,
357+ I8 => tcx. lang_items ( ) . i8_impl ( ) ,
358+ I16 => tcx. lang_items ( ) . i16_impl ( ) ,
359+ I32 => tcx. lang_items ( ) . i32_impl ( ) ,
360+ I64 => tcx. lang_items ( ) . i64_impl ( ) ,
361+ I128 => tcx. lang_items ( ) . i128_impl ( ) ,
362+ Usize => tcx. lang_items ( ) . usize_impl ( ) ,
363+ U8 => tcx. lang_items ( ) . u8_impl ( ) ,
364+ U16 => tcx. lang_items ( ) . u16_impl ( ) ,
365+ U32 => tcx. lang_items ( ) . u32_impl ( ) ,
366+ U64 => tcx. lang_items ( ) . u64_impl ( ) ,
367+ U128 => tcx. lang_items ( ) . u128_impl ( ) ,
368+ F32 => tcx. lang_items ( ) . f32_impl ( ) ,
369+ F64 => tcx. lang_items ( ) . f64_impl ( ) ,
370+ Char => tcx. lang_items ( ) . char_impl ( ) ,
371+ Bool => tcx. lang_items ( ) . bool_impl ( ) ,
372+ Str => tcx. lang_items ( ) . str_impl ( ) ,
373+ Slice => tcx. lang_items ( ) . slice_impl ( ) ,
374+ Array => tcx. lang_items ( ) . array_impl ( ) ,
375+ Tuple => None ,
376+ Unit => None ,
377+ RawPointer => tcx. lang_items ( ) . const_ptr_impl ( ) ,
378+ Reference => None ,
379+ Fn => None ,
380+ Never => None ,
381+ }
382+ }
383+
384+ pub fn build_deref_target_impls ( cx : & DocContext < ' _ > , items : & [ Item ] , ret : & mut Vec < Item > ) {
354385 let tcx = cx. tcx ;
355386
356387 for item in items {
@@ -369,33 +400,7 @@ pub fn build_deref_target_impls(cx: &DocContext<'_>, items: &[Item], ret: &mut V
369400 None => continue ,
370401 } ,
371402 } ;
372- let did = match primitive {
373- Isize => tcx. lang_items ( ) . isize_impl ( ) ,
374- I8 => tcx. lang_items ( ) . i8_impl ( ) ,
375- I16 => tcx. lang_items ( ) . i16_impl ( ) ,
376- I32 => tcx. lang_items ( ) . i32_impl ( ) ,
377- I64 => tcx. lang_items ( ) . i64_impl ( ) ,
378- I128 => tcx. lang_items ( ) . i128_impl ( ) ,
379- Usize => tcx. lang_items ( ) . usize_impl ( ) ,
380- U8 => tcx. lang_items ( ) . u8_impl ( ) ,
381- U16 => tcx. lang_items ( ) . u16_impl ( ) ,
382- U32 => tcx. lang_items ( ) . u32_impl ( ) ,
383- U64 => tcx. lang_items ( ) . u64_impl ( ) ,
384- U128 => tcx. lang_items ( ) . u128_impl ( ) ,
385- F32 => tcx. lang_items ( ) . f32_impl ( ) ,
386- F64 => tcx. lang_items ( ) . f64_impl ( ) ,
387- Char => tcx. lang_items ( ) . char_impl ( ) ,
388- Bool => tcx. lang_items ( ) . bool_impl ( ) ,
389- Str => tcx. lang_items ( ) . str_impl ( ) ,
390- Slice => tcx. lang_items ( ) . slice_impl ( ) ,
391- Array => tcx. lang_items ( ) . array_impl ( ) ,
392- Tuple => None ,
393- Unit => None ,
394- RawPointer => tcx. lang_items ( ) . const_ptr_impl ( ) ,
395- Reference => None ,
396- Fn => None ,
397- Never => None ,
398- } ;
403+ let did = impl_for_type ( tcx, primitive) ;
399404 if let Some ( did) = did {
400405 if !did. is_local ( ) {
401406 inline:: build_impl ( cx, did, None , ret) ;
0 commit comments