@@ -15,7 +15,7 @@ use rustc_hir::def::{DefKind, Res};
15
15
use rustc_hir:: def_id:: { DefId , LOCAL_CRATE } ;
16
16
use rustc_middle:: mir:: interpret:: { sign_extend, ConstValue , Scalar } ;
17
17
use rustc_middle:: ty:: subst:: { GenericArgKind , SubstsRef } ;
18
- use rustc_middle:: ty:: { self , DefIdTree , Ty } ;
18
+ use rustc_middle:: ty:: { self , DefIdTree , Ty , TyCtxt } ;
19
19
use rustc_span:: symbol:: { kw, sym, Symbol } ;
20
20
use std:: mem;
21
21
@@ -350,8 +350,39 @@ pub fn qpath_to_string(p: &hir::QPath<'_>) -> String {
350
350
s
351
351
}
352
352
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 > {
354
354
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 > ) {
355
386
let tcx = cx. tcx ;
356
387
357
388
for item in items {
@@ -370,33 +401,7 @@ pub fn build_deref_target_impls(cx: &DocContext<'_>, items: &[Item], ret: &mut V
370
401
None => continue ,
371
402
} ,
372
403
} ;
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) ;
400
405
if let Some ( did) = did {
401
406
if !did. is_local ( ) {
402
407
inline:: build_impl ( cx, did, None , ret) ;
0 commit comments