@@ -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
@@ -350,8 +350,39 @@ pub fn qpath_to_string(p: &hir::QPath<'_>) -> String {
350350 s
351351}
352352
353- pub fn build_deref_target_impls ( cx : & DocContext < ' _ > , items : & [ Item ] , ret : & mut Vec < Item > ) {
353+ pub fn impl_for_type ( tcx : TyCtxt < ' _ > , primitive : PrimitiveType ) -> Option < DefId > {
354354 use self :: PrimitiveType :: * ;
355+
356+ match primitive {
357+ Isize => tcx. lang_items ( ) . isize_impl ( ) ,
358+ I8 => tcx. lang_items ( ) . i8_impl ( ) ,
359+ I16 => tcx. lang_items ( ) . i16_impl ( ) ,
360+ I32 => tcx. lang_items ( ) . i32_impl ( ) ,
361+ I64 => tcx. lang_items ( ) . i64_impl ( ) ,
362+ I128 => tcx. lang_items ( ) . i128_impl ( ) ,
363+ Usize => tcx. lang_items ( ) . usize_impl ( ) ,
364+ U8 => tcx. lang_items ( ) . u8_impl ( ) ,
365+ U16 => tcx. lang_items ( ) . u16_impl ( ) ,
366+ U32 => tcx. lang_items ( ) . u32_impl ( ) ,
367+ U64 => tcx. lang_items ( ) . u64_impl ( ) ,
368+ U128 => tcx. lang_items ( ) . u128_impl ( ) ,
369+ F32 => tcx. lang_items ( ) . f32_impl ( ) ,
370+ F64 => tcx. lang_items ( ) . f64_impl ( ) ,
371+ Char => tcx. lang_items ( ) . char_impl ( ) ,
372+ Bool => tcx. lang_items ( ) . bool_impl ( ) ,
373+ Str => tcx. lang_items ( ) . str_impl ( ) ,
374+ Slice => tcx. lang_items ( ) . slice_impl ( ) ,
375+ Array => tcx. lang_items ( ) . array_impl ( ) ,
376+ Tuple => None ,
377+ Unit => None ,
378+ RawPointer => tcx. lang_items ( ) . const_ptr_impl ( ) ,
379+ Reference => None ,
380+ Fn => None ,
381+ Never => None ,
382+ }
383+ }
384+
385+ pub fn build_deref_target_impls ( cx : & DocContext < ' _ > , items : & [ Item ] , ret : & mut Vec < Item > ) {
355386 let tcx = cx. tcx ;
356387
357388 for item in items {
@@ -370,33 +401,7 @@ pub fn build_deref_target_impls(cx: &DocContext<'_>, items: &[Item], ret: &mut V
370401 None => continue ,
371402 } ,
372403 } ;
373- let did = match primitive {
374- Isize => tcx. lang_items ( ) . isize_impl ( ) ,
375- I8 => tcx. lang_items ( ) . i8_impl ( ) ,
376- I16 => tcx. lang_items ( ) . i16_impl ( ) ,
377- I32 => tcx. lang_items ( ) . i32_impl ( ) ,
378- I64 => tcx. lang_items ( ) . i64_impl ( ) ,
379- I128 => tcx. lang_items ( ) . i128_impl ( ) ,
380- Usize => tcx. lang_items ( ) . usize_impl ( ) ,
381- U8 => tcx. lang_items ( ) . u8_impl ( ) ,
382- U16 => tcx. lang_items ( ) . u16_impl ( ) ,
383- U32 => tcx. lang_items ( ) . u32_impl ( ) ,
384- U64 => tcx. lang_items ( ) . u64_impl ( ) ,
385- U128 => tcx. lang_items ( ) . u128_impl ( ) ,
386- F32 => tcx. lang_items ( ) . f32_impl ( ) ,
387- F64 => tcx. lang_items ( ) . f64_impl ( ) ,
388- Char => tcx. lang_items ( ) . char_impl ( ) ,
389- Bool => tcx. lang_items ( ) . bool_impl ( ) ,
390- Str => tcx. lang_items ( ) . str_impl ( ) ,
391- Slice => tcx. lang_items ( ) . slice_impl ( ) ,
392- Array => tcx. lang_items ( ) . array_impl ( ) ,
393- Tuple => None ,
394- Unit => None ,
395- RawPointer => tcx. lang_items ( ) . const_ptr_impl ( ) ,
396- Reference => None ,
397- Fn => None ,
398- Never => None ,
399- } ;
404+ let did = impl_for_type ( tcx, primitive) ;
400405 if let Some ( did) = did {
401406 if !did. is_local ( ) {
402407 inline:: build_impl ( cx, did, None , ret) ;
0 commit comments