@@ -35,10 +35,29 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
35
35
AdtKind :: Enum => Def :: Enum ,
36
36
AdtKind :: Union => Def :: Union ,
37
37
}
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
+ }
39
58
} ;
40
59
41
- self . get_auto_trait_impls ( def_id, def_ctor, None )
60
+ self . get_auto_trait_impls ( def_id, & def_ctor, None )
42
61
}
43
62
44
63
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> {
52
71
_ => panic ! ( "Unexpected type {:?} {:?}" , item, id) ,
53
72
} ;
54
73
55
- self . get_auto_trait_impls ( did, def_ctor, Some ( name) )
74
+ self . get_auto_trait_impls ( did, & def_ctor, Some ( name) )
56
75
}
57
76
58
- pub fn get_auto_trait_impls (
77
+ pub fn get_auto_trait_impls < F > (
59
78
& self ,
60
79
def_id : DefId ,
61
- def_ctor : fn ( DefId ) -> Def ,
80
+ def_ctor : & F ,
62
81
name : Option < String > ,
63
- ) -> Vec < Item > {
82
+ ) -> Vec < Item >
83
+ where F : Fn ( DefId ) -> Def {
64
84
if self . cx
65
85
. tcx
66
86
. get_attrs ( def_id)
67
87
. lists ( "doc" )
68
88
. has_word ( "hidden" )
69
89
{
70
90
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'), \
72
92
aborting",
73
- def_id, def_ctor
93
+ def_id
74
94
) ;
75
95
return Vec :: new ( ) ;
76
96
}
@@ -79,8 +99,8 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
79
99
let generics = self . cx . tcx . generics_of ( def_id) ;
80
100
81
101
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
84
104
) ;
85
105
let auto_traits: Vec < _ > = self . cx
86
106
. send_trait
@@ -110,23 +130,24 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
110
130
auto_traits
111
131
}
112
132
113
- fn get_auto_trait_impl_for (
133
+ fn get_auto_trait_impl_for < F > (
114
134
& self ,
115
135
def_id : DefId ,
116
136
name : Option < String > ,
117
137
generics : ty:: Generics ,
118
- def_ctor : fn ( DefId ) -> Def ,
138
+ def_ctor : & F ,
119
139
trait_def_id : DefId ,
120
- ) -> Option < Item > {
140
+ ) -> Option < Item >
141
+ where F : Fn ( DefId ) -> Def {
121
142
if !self . cx
122
143
. generated_synthetics
123
144
. borrow_mut ( )
124
145
. insert ( ( def_id, trait_def_id) )
125
146
{
126
147
debug ! (
127
- "get_auto_trait_impl_for(def_id={:?}, generics={:?}, def_ctor={:?} , \
148
+ "get_auto_trait_impl_for(def_id={:?}, generics={:?}, def_ctor=... , \
128
149
trait_def_id={:?}): already generated, aborting",
129
- def_id, generics, def_ctor , trait_def_id
150
+ def_id, generics, trait_def_id
130
151
) ;
131
152
return None ;
132
153
}
0 commit comments