@@ -45,10 +45,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
45
45
dummy_self,
46
46
& mut bounds,
47
47
false ,
48
- // FIXME: This should be `true`, but we don't really handle
49
- // associated type bounds or type aliases in objects in a way
50
- // that makes this meaningful, I think.
51
- OnlySelfBounds ( false ) ,
48
+ // True so we don't populate `bounds` with associated type bounds, even
49
+ // though they're disallowed from object types.
50
+ OnlySelfBounds ( true ) ,
52
51
) {
53
52
potential_assoc_types. extend ( cur_potential_assoc_types) ;
54
53
}
@@ -83,9 +82,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
83
82
let expanded_traits =
84
83
traits:: expand_trait_aliases ( tcx, trait_bounds. iter ( ) . map ( |& ( a, b) | ( a, b) ) ) ;
85
84
86
- let ( mut auto_traits, regular_traits) : ( Vec < _ > , Vec < _ > ) = expanded_traits
87
- . filter ( |i| i. trait_ref ( ) . self_ty ( ) . skip_binder ( ) == dummy_self)
88
- . partition ( |i| tcx. trait_is_auto ( i. trait_ref ( ) . def_id ( ) ) ) ;
85
+ let ( mut auto_traits, regular_traits) : ( Vec < _ > , Vec < _ > ) =
86
+ expanded_traits. partition ( |i| tcx. trait_is_auto ( i. trait_ref ( ) . def_id ( ) ) ) ;
89
87
if regular_traits. len ( ) > 1 {
90
88
let first_trait = & regular_traits[ 0 ] ;
91
89
let additional_trait = & regular_traits[ 1 ] ;
@@ -158,7 +156,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
158
156
159
157
for ( base_trait_ref, span) in regular_traits_refs_spans {
160
158
let base_pred: ty:: Predicate < ' tcx > = base_trait_ref. to_predicate ( tcx) ;
161
- for pred in traits:: elaborate ( tcx, [ base_pred] ) {
159
+ for pred in traits:: elaborate ( tcx, [ base_pred] ) . filter_only_self ( ) {
162
160
debug ! ( "conv_object_ty_poly_trait_ref: observing object predicate `{:?}`" , pred) ;
163
161
164
162
let bound_predicate = pred. kind ( ) ;
@@ -312,45 +310,39 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
312
310
} )
313
311
} ) ;
314
312
315
- let existential_projections = projection_bounds
316
- . iter ( )
317
- // We filter out traits that don't have `Self` as their self type above,
318
- // we need to do the same for projections.
319
- . filter ( |( bound, _) | bound. skip_binder ( ) . self_ty ( ) == dummy_self)
320
- . map ( |( bound, _) | {
321
- bound. map_bound ( |mut b| {
322
- assert_eq ! ( b. projection_ty. self_ty( ) , dummy_self) ;
313
+ let existential_projections = projection_bounds. iter ( ) . map ( |( bound, _) | {
314
+ bound. map_bound ( |mut b| {
315
+ assert_eq ! ( b. projection_ty. self_ty( ) , dummy_self) ;
323
316
324
- // Like for trait refs, verify that `dummy_self` did not leak inside default type
325
- // parameters.
326
- let references_self = b. projection_ty . args . iter ( ) . skip ( 1 ) . any ( |arg| {
327
- if arg. walk ( ) . any ( |arg| arg == dummy_self. into ( ) ) {
328
- return true ;
329
- }
330
- false
331
- } ) ;
332
- if references_self {
333
- let guar = tcx. dcx ( ) . span_delayed_bug (
334
- span,
335
- "trait object projection bounds reference `Self`" ,
336
- ) ;
337
- let args: Vec < _ > = b
338
- . projection_ty
339
- . args
340
- . iter ( )
341
- . map ( |arg| {
342
- if arg. walk ( ) . any ( |arg| arg == dummy_self. into ( ) ) {
343
- return Ty :: new_error ( tcx, guar) . into ( ) ;
344
- }
345
- arg
346
- } )
347
- . collect ( ) ;
348
- b. projection_ty . args = tcx. mk_args ( & args) ;
317
+ // Like for trait refs, verify that `dummy_self` did not leak inside default type
318
+ // parameters.
319
+ let references_self = b. projection_ty . args . iter ( ) . skip ( 1 ) . any ( |arg| {
320
+ if arg. walk ( ) . any ( |arg| arg == dummy_self. into ( ) ) {
321
+ return true ;
349
322
}
323
+ false
324
+ } ) ;
325
+ if references_self {
326
+ let guar = tcx
327
+ . dcx ( )
328
+ . span_delayed_bug ( span, "trait object projection bounds reference `Self`" ) ;
329
+ let args: Vec < _ > = b
330
+ . projection_ty
331
+ . args
332
+ . iter ( )
333
+ . map ( |arg| {
334
+ if arg. walk ( ) . any ( |arg| arg == dummy_self. into ( ) ) {
335
+ return Ty :: new_error ( tcx, guar) . into ( ) ;
336
+ }
337
+ arg
338
+ } )
339
+ . collect ( ) ;
340
+ b. projection_ty . args = tcx. mk_args ( & args) ;
341
+ }
350
342
351
- ty:: ExistentialProjection :: erase_self_ty ( tcx, b)
352
- } )
353
- } ) ;
343
+ ty:: ExistentialProjection :: erase_self_ty ( tcx, b)
344
+ } )
345
+ } ) ;
354
346
355
347
let regular_trait_predicates = existential_trait_refs
356
348
. map ( |trait_ref| trait_ref. map_bound ( ty:: ExistentialPredicate :: Trait ) ) ;
0 commit comments