10
10
11
11
use rustc:: hir;
12
12
use rustc:: traits:: { self , auto_trait as auto} ;
13
- use rustc:: ty:: { ToPredicate , TypeFoldable } ;
13
+ use rustc:: ty:: { self , ToPredicate , TypeFoldable } ;
14
14
use rustc:: ty:: subst:: Subst ;
15
15
use rustc:: infer:: InferOk ;
16
16
use std:: fmt:: Debug ;
@@ -80,6 +80,33 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
80
80
self . get_auto_trait_impls ( did, & def_ctor, Some ( name) )
81
81
}
82
82
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
+
83
110
pub fn get_auto_trait_impls < F > (
84
111
& self ,
85
112
def_id : DefId ,
@@ -140,7 +167,8 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
140
167
// Require the type the impl is implemented on to match
141
168
// our type, and ignore the impl if there was a mismatch.
142
169
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) ;
144
172
if let Ok ( InferOk { value : ( ) , obligations } ) = eq_result {
145
173
// FIXME(eddyb) ignoring `obligations` might cause false positives.
146
174
drop ( obligations) ;
@@ -156,36 +184,18 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
156
184
self . cx . generated_synthetics . borrow_mut ( )
157
185
. insert ( ( def_id, trait_def_id) ) ;
158
186
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 ) ,
160
190
ref_id : ast:: DUMMY_NODE_ID ,
161
191
} ;
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 ( ) ;
176
197
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) ;
189
199
190
200
traits. push ( Item {
191
201
source : Span :: empty ( ) ,
@@ -202,7 +212,9 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
202
212
provided_trait_methods,
203
213
trait_ : Some ( trait_. clean ( self . cx ) ) ,
204
214
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 ) ,
206
218
polarity : None ,
207
219
synthetic : true ,
208
220
} ) ,
@@ -312,31 +324,8 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
312
324
}
313
325
_ => unreachable ! ( ) ,
314
326
} ;
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
-
320
327
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) ;
340
329
341
330
return Some ( Item {
342
331
source : Span :: empty ( ) ,
0 commit comments