@@ -174,21 +174,31 @@ impl<'a, 'gcx, 'tcx> TranslationContext<'a, 'gcx, 'tcx> {
174
174
TyDynamic ( preds, region) => {
175
175
// hacky error catching mechanism
176
176
use rustc:: hir:: def_id:: { CRATE_DEF_INDEX , DefId } ;
177
- let mut success = true ;
177
+ use std:: cell:: Cell ;
178
+
179
+ let success = Cell :: new ( true ) ;
178
180
let err_pred = AutoTrait ( DefId :: local ( CRATE_DEF_INDEX ) ) ;
179
181
180
- let target_preds = self . tcx . mk_existential_predicates ( preds. iter ( ) . map ( |p| {
182
+ let res: Vec < _ > = preds. iter ( ) . map ( |p| {
183
+ debug ! ( "pred: {:?}" , p) ;
181
184
match * p. skip_binder ( ) {
182
- Trait ( ExistentialTraitRef { def_id : did, substs } ) => {
185
+ Trait ( existential_trait_ref) => {
186
+ let trait_ref = Binder ( existential_trait_ref)
187
+ . with_self_ty ( self . tcx , self . tcx . types . err ) ;
188
+ let did = trait_ref. skip_binder ( ) . def_id ;
189
+ let substs = trait_ref. skip_binder ( ) . substs ;
190
+
183
191
if let Some ( ( target_def_id, target_substs) ) =
184
192
self . translate_orig_substs ( index_map, did, substs)
185
193
{
186
- Trait ( ExistentialTraitRef {
194
+ let target_trait_ref = TraitRef {
187
195
def_id : target_def_id,
188
- substs : target_substs
189
- } )
190
- } else {
191
- success = false ;
196
+ substs : target_substs,
197
+ } ;
198
+ Trait ( ExistentialTraitRef :: erase_self_ty ( self . tcx ,
199
+ target_trait_ref) )
200
+ } else {
201
+ success. set ( false ) ;
192
202
err_pred
193
203
}
194
204
} ,
@@ -202,17 +212,18 @@ impl<'a, 'gcx, 'tcx> TranslationContext<'a, 'gcx, 'tcx> {
202
212
ty : ty,
203
213
} )
204
214
} else {
205
- success = false ;
215
+ success. set ( false ) ;
206
216
err_pred
207
217
}
208
218
} ,
209
219
AutoTrait ( did) => {
210
220
AutoTrait ( self . translate_orig ( did) )
211
221
} ,
212
222
}
213
- } ) ) ;
223
+ } ) . collect ( ) ;
214
224
215
- if success {
225
+ if success. get ( ) {
226
+ let target_preds = self . tcx . mk_existential_predicates ( res. iter ( ) ) ;
216
227
self . tcx . mk_dynamic ( Binder ( target_preds) , region)
217
228
} else {
218
229
ty
0 commit comments