@@ -35,10 +35,29 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
3535 AdtKind :: Enum => Def :: Enum ,
3636 AdtKind :: Union => Def :: Union ,
3737 }
38- _ => panic ! ( "Unexpected type {:?}" , def_id) ,
38+ ty:: TyInt ( _) |
39+ ty:: TyUint ( _) |
40+ ty:: TyFloat ( _) |
41+ ty:: TyStr |
42+ ty:: TyBool |
43+ ty:: TyChar => return self . get_auto_trait_impls ( def_id, & move |_: DefId | {
44+ match ty. sty {
45+ ty:: TyInt ( x) => Def :: PrimTy ( hir:: TyInt ( x) ) ,
46+ ty:: TyUint ( x) => Def :: PrimTy ( hir:: TyUint ( x) ) ,
47+ ty:: TyFloat ( x) => Def :: PrimTy ( hir:: TyFloat ( x) ) ,
48+ ty:: TyStr => Def :: PrimTy ( hir:: TyStr ) ,
49+ ty:: TyBool => Def :: PrimTy ( hir:: TyBool ) ,
50+ ty:: TyChar => Def :: PrimTy ( hir:: TyChar ) ,
51+ _ => unreachable ! ( ) ,
52+ }
53+ } , None ) ,
54+ _ => {
55+ debug ! ( "Unexpected type {:?}" , def_id) ;
56+ return Vec :: new ( )
57+ }
3958 } ;
4059
41- self . get_auto_trait_impls ( def_id, def_ctor, None )
60+ self . get_auto_trait_impls ( def_id, & def_ctor, None )
4261 }
4362
4463 pub fn get_with_node_id ( & self , id : ast:: NodeId , name : String ) -> Vec < Item > {
@@ -52,25 +71,26 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
5271 _ => panic ! ( "Unexpected type {:?} {:?}" , item, id) ,
5372 } ;
5473
55- self . get_auto_trait_impls ( did, def_ctor, Some ( name) )
74+ self . get_auto_trait_impls ( did, & def_ctor, Some ( name) )
5675 }
5776
58- pub fn get_auto_trait_impls (
77+ pub fn get_auto_trait_impls < F > (
5978 & self ,
6079 def_id : DefId ,
61- def_ctor : fn ( DefId ) -> Def ,
80+ def_ctor : & F ,
6281 name : Option < String > ,
63- ) -> Vec < Item > {
82+ ) -> Vec < Item >
83+ where F : Fn ( DefId ) -> Def {
6484 if self . cx
6585 . tcx
6686 . get_attrs ( def_id)
6787 . lists ( "doc" )
6888 . has_word ( "hidden" )
6989 {
7090 debug ! (
71- "get_auto_trait_impls(def_id={:?}, def_ctor={:?} ): item has doc('hidden'), \
91+ "get_auto_trait_impls(def_id={:?}, def_ctor=... ): item has doc('hidden'), \
7292 aborting",
73- def_id, def_ctor
93+ def_id
7494 ) ;
7595 return Vec :: new ( ) ;
7696 }
@@ -79,8 +99,8 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
7999 let generics = self . cx . tcx . generics_of ( def_id) ;
80100
81101 debug ! (
82- "get_auto_trait_impls(def_id={:?}, def_ctor={:?} , generics={:?}" ,
83- def_id, def_ctor , generics
102+ "get_auto_trait_impls(def_id={:?}, def_ctor=... , generics={:?}" ,
103+ def_id, generics
84104 ) ;
85105 let auto_traits: Vec < _ > = self . cx
86106 . send_trait
@@ -110,23 +130,24 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
110130 auto_traits
111131 }
112132
113- fn get_auto_trait_impl_for (
133+ fn get_auto_trait_impl_for < F > (
114134 & self ,
115135 def_id : DefId ,
116136 name : Option < String > ,
117137 generics : ty:: Generics ,
118- def_ctor : fn ( DefId ) -> Def ,
138+ def_ctor : & F ,
119139 trait_def_id : DefId ,
120- ) -> Option < Item > {
140+ ) -> Option < Item >
141+ where F : Fn ( DefId ) -> Def {
121142 if !self . cx
122143 . generated_synthetics
123144 . borrow_mut ( )
124145 . insert ( ( def_id, trait_def_id) )
125146 {
126147 debug ! (
127- "get_auto_trait_impl_for(def_id={:?}, generics={:?}, def_ctor={:?} , \
148+ "get_auto_trait_impl_for(def_id={:?}, generics={:?}, def_ctor=... , \
128149 trait_def_id={:?}): already generated, aborting",
129- def_id, generics, def_ctor , trait_def_id
150+ def_id, generics, trait_def_id
130151 ) ;
131152 return None ;
132153 }
0 commit comments