@@ -91,18 +91,13 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
91
91
let ty = self . cx . tcx . type_of ( def_id) ;
92
92
let mut traits = FxHashMap ( ) ;
93
93
if let ty:: TyAdt ( _adt, _) = ty. sty {
94
- use std:: rc:: Rc ;
95
-
96
- let name = Rc :: new ( name. clone ( ) ) ;
97
94
let param_env = self . cx . tcx . param_env ( def_id) ;
98
95
for & trait_def_id in self . cx . tcx . all_traits ( LOCAL_CRATE ) . iter ( ) {
99
- let name = name. clone ( ) ;
100
96
self . cx . tcx . for_each_relevant_impl ( trait_def_id, ty, |impl_def_id| {
101
- let name = name. clone ( ) ;
102
97
self . cx . tcx . infer_ctxt ( ) . enter ( |infcx| {
103
98
let trait_ref = infcx. tcx . impl_trait_ref ( impl_def_id) . unwrap ( ) ;
104
99
let substs = infcx. fresh_substs_for_item ( DUMMY_SP , def_id) ;
105
- let ty = ty. subst ( infcx. tcx , substs) ;
100
+ let ty2 = ty. subst ( infcx. tcx , substs) ;
106
101
let param_env = param_env. subst ( infcx. tcx , substs) ;
107
102
108
103
let impl_substs = infcx. fresh_substs_for_item ( DUMMY_SP , impl_def_id) ;
@@ -111,7 +106,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
111
106
// Require the type the impl is implemented on to match
112
107
// our type, and ignore the impl if there was a mismatch.
113
108
let cause = traits:: ObligationCause :: dummy ( ) ;
114
- let eq_result = infcx. at ( & cause, param_env) . eq ( trait_ref. self_ty ( ) , ty ) ;
109
+ let eq_result = infcx. at ( & cause, param_env) . eq ( trait_ref. self_ty ( ) , ty2 ) ;
115
110
if let Ok ( InferOk { value : ( ) , obligations } ) = eq_result {
116
111
// FIXME(eddyb) ignoring `obligations` might cause false positives.
117
112
drop ( obligations) ;
@@ -137,57 +132,40 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
137
132
traits.insert(trait_name, i);
138
133
}*/
139
134
140
- let path = get_path_for_type ( infcx. tcx , def_id, def_ctor) ;
141
- let mut segments = path. clone ( ) . segments . into_vec ( ) ;
142
- let last = segments. pop ( ) . unwrap ( ) ;
143
-
144
- use std:: ops:: Deref ;
145
- let t_name: Option < String > = name. deref ( ) . clone ( ) ;
146
- let real_name = t_name. map ( |name| Ident :: from_str ( & name) ) . unwrap_or ( last. ident ) ;
147
-
148
- segments. push ( hir:: PathSegment :: new (
149
- real_name,
150
- self . generics_to_path_params ( generics. clone ( ) ) ,
151
- false ,
152
- ) ) ;
153
- let new_path = hir:: Path {
154
- span : path. span ,
155
- def : path. def ,
156
- segments : HirVec :: from_vec ( segments) ,
157
- } ;
158
- let ty = hir:: Ty {
159
- id : ast:: DUMMY_NODE_ID ,
160
- node : hir:: Ty_ :: TyPath ( hir:: QPath :: Resolved ( None , P ( new_path) ) ) ,
161
- span : DUMMY_SP ,
162
- hir_id : hir:: DUMMY_HIR_ID ,
163
- } ;
164
- traits. insert ( trait_def_id, Item {
165
- source : Span :: empty ( ) ,
166
- name : None ,
167
- attrs : Default :: default ( ) ,
168
- visibility : None ,
169
- def_id : self . next_def_id ( def_id. krate ) ,
170
- stability : None ,
171
- deprecation : None ,
172
- inner : ImplItem ( Impl {
173
- unsafety : hir:: Unsafety :: Normal ,
174
- generics : Generics {
175
- params : generics. params . clean ( self . cx ) ,
176
- where_predicates : Vec :: new ( ) ,
177
- } ,
178
- provided_trait_methods : FxHashSet ( ) ,
179
- trait_ : Some ( hir:: TraitRef {
180
- path,
181
- ref_id : ast:: DUMMY_NODE_ID ,
182
- } . clean ( self . cx ) ) ,
183
-
184
- //Some(trait_ref.clean(self.cx)),
185
- for_ : ty. clean ( self . cx ) ,
186
- items : Vec :: new ( ) ,
187
- polarity : None ,
188
- synthetic : true ,
189
- } )
135
+ let mut impls = Vec :: new ( ) ;
136
+ :: clean:: inline:: build_impl ( & self . cx , impl_def_id, & mut impls) ;
137
+ /*if ::std::env::var("LOL").is_ok() {
138
+ println!("=> {} ::> {}",
139
+ infcx.tcx.item_name(trait_def_id).to_string(),
140
+ impls.len());
141
+ println!("{:?}", impls);
142
+ }*/
143
+ for impl_ in & mut impls {
144
+ if let ImplItem ( ref mut i) = impl_. inner {
145
+ i. synthetic = true ;
146
+ i. for_ = ty. clean ( & self . cx ) ;
147
+ }
148
+ }
149
+ traits. insert ( trait_def_id, impls) ;
150
+
151
+ /*use ::clean::{self, inline::*};
152
+
153
+ let mut ret = Vec::with_capacity(2);
154
+ record_extern_fqn(self.cx, trait_def_id, clean::TypeKind::Trait);
155
+ ret.extend(build_impls(self.cx, trait_def_id, false));
156
+ let inner = clean::TraitItem(build_external_trait(self.cx, trait_def_id));
157
+ let cx = self.cx;
158
+ ret.push(clean::Item {
159
+ source: infcx.tcx.def_span(trait_def_id).clean(cx),
160
+ name: Some(infcx.tcx.item_name(trait_def_id).to_string()),
161
+ attrs: load_attrs(cx, trait_def_id),
162
+ inner,
163
+ visibility: Some(clean::Public),
164
+ stability: cx.tcx.lookup_stability(trait_def_id).clean(cx),
165
+ deprecation: cx.tcx.lookup_deprecation(trait_def_id).clean(cx),
166
+ def_id: trait_def_id,
190
167
});
168
+ traits.insert(trait_def_id, ret);*/
191
169
}
192
170
//println!("=> {}", infcx.tcx.item_name(trait_def_id).to_string());
193
171
}
@@ -236,13 +214,18 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
236
214
def_ctor,
237
215
tcx. require_lang_item ( lang_items:: SyncTraitLangItem ) ,
238
216
) . into_iter ( ) )
239
- . chain ( traits. into_iter ( ) . map ( |( _, v) | v) )
217
+ . chain ( traits. into_iter ( ) . flat_map ( |( _, v) | v. into_iter ( ) ) )
240
218
. collect ( ) ;
241
219
242
220
debug ! (
243
221
"get_auto_traits: type {:?} auto_traits {:?}" ,
244
222
def_id, auto_traits
245
223
) ;
224
+ if :: std:: env:: var ( "LOL" ) . is_ok ( ) {
225
+ for x in & auto_traits {
226
+ println ! ( "\n => {:?}" , x) ;
227
+ }
228
+ }
246
229
auto_traits
247
230
}
248
231
0 commit comments