1010
1111use rustc:: hir;
1212use rustc:: traits:: { self , auto_trait as auto} ;
13- use rustc:: ty:: { ToPredicate , TypeFoldable } ;
13+ use rustc:: ty:: { self , ToPredicate , TypeFoldable } ;
1414use rustc:: ty:: subst:: Subst ;
1515use rustc:: infer:: InferOk ;
1616use std:: fmt:: Debug ;
@@ -80,6 +80,33 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
8080 self . get_auto_trait_impls ( did, & def_ctor, Some ( name) )
8181 }
8282
83+ fn get_real_ty < F > ( & self , def_id : DefId , def_ctor : & F , real_name : & Option < Ident > ,
84+ generics : & ty:: Generics ) -> hir:: Ty
85+ where F : Fn ( DefId ) -> Def {
86+ let path = get_path_for_type ( self . cx . tcx , def_id, def_ctor) ;
87+ let mut segments = path. segments . into_vec ( ) ;
88+ let last = segments. pop ( ) . unwrap ( ) ;
89+
90+ segments. push ( hir:: PathSegment :: new (
91+ real_name. unwrap_or ( last. ident ) ,
92+ self . generics_to_path_params ( generics. clone ( ) ) ,
93+ false ,
94+ ) ) ;
95+
96+ let new_path = hir:: Path {
97+ span : path. span ,
98+ def : path. def ,
99+ segments : HirVec :: from_vec ( segments) ,
100+ } ;
101+
102+ hir:: Ty {
103+ id : ast:: DUMMY_NODE_ID ,
104+ node : hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , P ( new_path) ) ) ,
105+ span : DUMMY_SP ,
106+ hir_id : hir:: DUMMY_HIR_ID ,
107+ }
108+ }
109+
83110 pub fn get_auto_trait_impls < F > (
84111 & self ,
85112 def_id : DefId ,
@@ -140,7 +167,8 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
140167 // Require the type the impl is implemented on to match
141168 // our type, and ignore the impl if there was a mismatch.
142169 let cause = traits:: ObligationCause :: dummy ( ) ;
143- let eq_result = infcx. at ( & cause, param_env) . eq ( trait_ref. self_ty ( ) , ty2) ;
170+ let eq_result = infcx. at ( & cause, param_env)
171+ . eq ( trait_ref. self_ty ( ) , ty2) ;
144172 if let Ok ( InferOk { value : ( ) , obligations } ) = eq_result {
145173 // FIXME(eddyb) ignoring `obligations` might cause false positives.
146174 drop ( obligations) ;
@@ -156,36 +184,18 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
156184 self . cx . generated_synthetics . borrow_mut ( )
157185 . insert ( ( def_id, trait_def_id) ) ;
158186 let trait_ = hir:: TraitRef {
159- path : get_path_for_type ( infcx. tcx , trait_def_id, hir:: def:: Def :: Trait ) ,
187+ path : get_path_for_type ( infcx. tcx ,
188+ trait_def_id,
189+ hir:: def:: Def :: Trait ) ,
160190 ref_id : ast:: DUMMY_NODE_ID ,
161191 } ;
162- let provided_trait_methods = infcx. tcx . provided_trait_methods ( impl_def_id)
163- . into_iter ( )
164- . map ( |meth| meth. ident . to_string ( ) )
165- . collect ( ) ;
166-
167- let path = get_path_for_type ( self . cx . tcx , def_id, def_ctor) ;
168- let mut segments = path. segments . into_vec ( ) ;
169- let last = segments. pop ( ) . unwrap ( ) ;
170-
171- segments. push ( hir:: PathSegment :: new (
172- real_name. unwrap_or ( last. ident ) ,
173- self . generics_to_path_params ( generics. clone ( ) ) ,
174- false ,
175- ) ) ;
192+ let provided_trait_methods =
193+ infcx. tcx . provided_trait_methods ( impl_def_id)
194+ . into_iter ( )
195+ . map ( |meth| meth. ident . to_string ( ) )
196+ . collect ( ) ;
176197
177- let new_path = hir:: Path {
178- span : path. span ,
179- def : path. def ,
180- segments : HirVec :: from_vec ( segments) ,
181- } ;
182-
183- let ty = hir:: Ty {
184- id : ast:: DUMMY_NODE_ID ,
185- node : hir:: Ty_ :: TyPath ( hir:: QPath :: Resolved ( None , P ( new_path) ) ) ,
186- span : DUMMY_SP ,
187- hir_id : hir:: DUMMY_HIR_ID ,
188- } ;
198+ let ty = self . get_real_ty ( def_id, def_ctor, & real_name, generics) ;
189199
190200 traits. push ( Item {
191201 source : Span :: empty ( ) ,
@@ -202,7 +212,9 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
202212 provided_trait_methods,
203213 trait_ : Some ( trait_. clean ( self . cx ) ) ,
204214 for_ : ty. clean ( self . cx ) ,
205- items : infcx. tcx . associated_items ( impl_def_id) . collect :: < Vec < _ > > ( ) . clean ( self . cx ) ,
215+ items : infcx. tcx . associated_items ( impl_def_id)
216+ . collect :: < Vec < _ > > ( )
217+ . clean ( self . cx ) ,
206218 polarity : None ,
207219 synthetic : true ,
208220 } ) ,
@@ -312,31 +324,8 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
312324 }
313325 _ => unreachable ! ( ) ,
314326 } ;
315-
316- let path = get_path_for_type ( self . cx . tcx , def_id, def_ctor) ;
317- let mut segments = path. segments . into_vec ( ) ;
318- let last = segments. pop ( ) . unwrap ( ) ;
319-
320327 let real_name = name. map ( |name| Ident :: from_str ( & name) ) ;
321-
322- segments. push ( hir:: PathSegment :: new (
323- real_name. unwrap_or ( last. ident ) ,
324- self . generics_to_path_params ( generics. clone ( ) ) ,
325- false ,
326- ) ) ;
327-
328- let new_path = hir:: Path {
329- span : path. span ,
330- def : path. def ,
331- segments : HirVec :: from_vec ( segments) ,
332- } ;
333-
334- let ty = hir:: Ty {
335- id : ast:: DUMMY_NODE_ID ,
336- node : hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , P ( new_path) ) ) ,
337- span : DUMMY_SP ,
338- hir_id : hir:: DUMMY_HIR_ID ,
339- } ;
328+ let ty = self . get_real_ty ( def_id, def_ctor, & real_name, & generics) ;
340329
341330 return Some ( Item {
342331 source : Span :: empty ( ) ,
0 commit comments