@@ -139,94 +139,92 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
139139 let mut traits = Vec :: new ( ) ;
140140 if self . cx . crate_name != Some ( "core" . to_string ( ) ) &&
141141 self . cx . access_levels . borrow ( ) . is_doc_reachable ( def_id) {
142- if let ty:: TyAdt ( _adt, _) = ty. sty {
143- let real_name = name. clone ( ) . map ( |name| Ident :: from_str ( & name) ) ;
144- let param_env = self . cx . tcx . param_env ( def_id) ;
145- for & trait_def_id in self . cx . all_traits . iter ( ) {
146- if !self . cx . access_levels . borrow ( ) . is_doc_reachable ( trait_def_id) ||
147- self . cx . generated_synthetics
148- . borrow_mut ( )
149- . get ( & ( def_id, trait_def_id) )
150- . is_some ( ) {
151- continue
152- }
153- self . cx . tcx . for_each_relevant_impl ( trait_def_id, ty, |impl_def_id| {
154- self . cx . tcx . infer_ctxt ( ) . enter ( |infcx| {
155- let t_generics = infcx. tcx . generics_of ( impl_def_id) ;
156- let trait_ref = infcx. tcx . impl_trait_ref ( impl_def_id) . unwrap ( ) ;
157-
158- match infcx. tcx . type_of ( impl_def_id) . sty {
159- :: rustc:: ty:: TypeVariants :: TyParam ( _) => { } ,
160- _ => return ,
161- }
142+ let real_name = name. clone ( ) . map ( |name| Ident :: from_str ( & name) ) ;
143+ let param_env = self . cx . tcx . param_env ( def_id) ;
144+ for & trait_def_id in self . cx . all_traits . iter ( ) {
145+ if !self . cx . access_levels . borrow ( ) . is_doc_reachable ( trait_def_id) ||
146+ self . cx . generated_synthetics
147+ . borrow_mut ( )
148+ . get ( & ( def_id, trait_def_id) )
149+ . is_some ( ) {
150+ continue
151+ }
152+ self . cx . tcx . for_each_relevant_impl ( trait_def_id, ty, |impl_def_id| {
153+ self . cx . tcx . infer_ctxt ( ) . enter ( |infcx| {
154+ let t_generics = infcx. tcx . generics_of ( impl_def_id) ;
155+ let trait_ref = infcx. tcx . impl_trait_ref ( impl_def_id) . unwrap ( ) ;
156+
157+ match infcx. tcx . type_of ( impl_def_id) . sty {
158+ :: rustc:: ty:: TypeVariants :: TyParam ( _) => { } ,
159+ _ => return ,
160+ }
162161
163- let substs = infcx. fresh_substs_for_item ( DUMMY_SP , def_id) ;
164- let ty = ty. subst ( infcx. tcx , substs) ;
165- let param_env = param_env. subst ( infcx. tcx , substs) ;
166-
167- let impl_substs = infcx. fresh_substs_for_item ( DUMMY_SP , impl_def_id) ;
168- let trait_ref = trait_ref. subst ( infcx. tcx , impl_substs) ;
169-
170- // Require the type the impl is implemented on to match
171- // our type, and ignore the impl if there was a mismatch.
172- let cause = traits:: ObligationCause :: dummy ( ) ;
173- let eq_result = infcx. at ( & cause, param_env)
174- . eq ( trait_ref. self_ty ( ) , ty) ;
175- if let Ok ( InferOk { value : ( ) , obligations } ) = eq_result {
176- // FIXME(eddyb) ignoring `obligations` might cause false positives.
177- drop ( obligations) ;
178-
179- let may_apply = infcx. predicate_may_hold ( & traits:: Obligation :: new (
180- cause. clone ( ) ,
181- param_env,
182- trait_ref. to_predicate ( ) ,
183- ) ) ;
184- if !may_apply {
185- return
186- }
187- self . cx . generated_synthetics . borrow_mut ( )
188- . insert ( ( def_id, trait_def_id) ) ;
189- let trait_ = hir:: TraitRef {
190- path : get_path_for_type ( infcx. tcx ,
191- trait_def_id,
192- hir:: def:: Def :: Trait ) ,
193- ref_id : ast:: DUMMY_NODE_ID ,
194- } ;
195- let provided_trait_methods =
196- infcx. tcx . provided_trait_methods ( trait_def_id)
197- . into_iter ( )
198- . map ( |meth| meth. ident . to_string ( ) )
199- . collect ( ) ;
200-
201- let ty = self . get_real_ty ( def_id, def_ctor, & real_name, generics) ;
202- let predicates = infcx. tcx . predicates_of ( def_id) ;
203-
204- traits. push ( Item {
205- source : infcx. tcx . def_span ( impl_def_id) . clean ( self . cx ) ,
206- name : None ,
207- attrs : Default :: default ( ) ,
208- visibility : None ,
209- def_id : self . next_def_id ( impl_def_id. krate ) ,
210- stability : None ,
211- deprecation : None ,
212- inner : ImplItem ( Impl {
213- unsafety : hir:: Unsafety :: Normal ,
214- generics : ( t_generics, & predicates) . clean ( self . cx ) ,
215- provided_trait_methods,
216- trait_ : Some ( trait_. clean ( self . cx ) ) ,
217- for_ : ty. clean ( self . cx ) ,
218- items : infcx. tcx . associated_items ( impl_def_id)
219- . collect :: < Vec < _ > > ( )
220- . clean ( self . cx ) ,
221- polarity : None ,
222- synthetic : true ,
223- } ) ,
224- } ) ;
225- debug ! ( "{:?} => {}" , trait_ref, may_apply) ;
162+ let substs = infcx. fresh_substs_for_item ( DUMMY_SP , def_id) ;
163+ let ty = ty. subst ( infcx. tcx , substs) ;
164+ let param_env = param_env. subst ( infcx. tcx , substs) ;
165+
166+ let impl_substs = infcx. fresh_substs_for_item ( DUMMY_SP , impl_def_id) ;
167+ let trait_ref = trait_ref. subst ( infcx. tcx , impl_substs) ;
168+
169+ // Require the type the impl is implemented on to match
170+ // our type, and ignore the impl if there was a mismatch.
171+ let cause = traits:: ObligationCause :: dummy ( ) ;
172+ let eq_result = infcx. at ( & cause, param_env)
173+ . eq ( trait_ref. self_ty ( ) , ty) ;
174+ if let Ok ( InferOk { value : ( ) , obligations } ) = eq_result {
175+ // FIXME(eddyb) ignoring `obligations` might cause false positives.
176+ drop ( obligations) ;
177+
178+ let may_apply = infcx. predicate_may_hold ( & traits:: Obligation :: new (
179+ cause. clone ( ) ,
180+ param_env,
181+ trait_ref. to_predicate ( ) ,
182+ ) ) ;
183+ if !may_apply {
184+ return
226185 }
227- } ) ;
186+ self . cx . generated_synthetics . borrow_mut ( )
187+ . insert ( ( def_id, trait_def_id) ) ;
188+ let trait_ = hir:: TraitRef {
189+ path : get_path_for_type ( infcx. tcx ,
190+ trait_def_id,
191+ hir:: def:: Def :: Trait ) ,
192+ ref_id : ast:: DUMMY_NODE_ID ,
193+ } ;
194+ let provided_trait_methods =
195+ infcx. tcx . provided_trait_methods ( trait_def_id)
196+ . into_iter ( )
197+ . map ( |meth| meth. ident . to_string ( ) )
198+ . collect ( ) ;
199+
200+ let ty = self . get_real_ty ( def_id, def_ctor, & real_name, generics) ;
201+ let predicates = infcx. tcx . predicates_of ( def_id) ;
202+
203+ traits. push ( Item {
204+ source : infcx. tcx . def_span ( impl_def_id) . clean ( self . cx ) ,
205+ name : None ,
206+ attrs : Default :: default ( ) ,
207+ visibility : None ,
208+ def_id : self . next_def_id ( impl_def_id. krate ) ,
209+ stability : None ,
210+ deprecation : None ,
211+ inner : ImplItem ( Impl {
212+ unsafety : hir:: Unsafety :: Normal ,
213+ generics : ( t_generics, & predicates) . clean ( self . cx ) ,
214+ provided_trait_methods,
215+ trait_ : Some ( trait_. clean ( self . cx ) ) ,
216+ for_ : ty. clean ( self . cx ) ,
217+ items : infcx. tcx . associated_items ( impl_def_id)
218+ . collect :: < Vec < _ > > ( )
219+ . clean ( self . cx ) ,
220+ polarity : None ,
221+ synthetic : true ,
222+ } ) ,
223+ } ) ;
224+ debug ! ( "{:?} => {}" , trait_ref, may_apply) ;
225+ }
228226 } ) ;
229- }
227+ } ) ;
230228 }
231229 }
232230
0 commit comments