@@ -35,7 +35,7 @@ use rustc_session::lint::builtin::{AMBIGUOUS_ASSOCIATED_ITEMS, BARE_TRAIT_OBJECT
3535use rustc_span:: edition:: Edition ;
3636use rustc_span:: lev_distance:: find_best_match_for_name;
3737use rustc_span:: symbol:: { kw, Ident , Symbol } ;
38- use rustc_span:: { Span , DUMMY_SP } ;
38+ use rustc_span:: Span ;
3939use rustc_target:: spec:: abi;
4040use rustc_trait_selection:: traits;
4141use rustc_trait_selection:: traits:: astconv_object_safety_violations;
@@ -1453,21 +1453,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
14531453 . enumerate ( )
14541454 . skip ( 1 ) // Remove `Self` for `ExistentialPredicate`.
14551455 . map ( |( index, arg) | {
1456- if let ty:: GenericArgKind :: Type ( ty) = arg. unpack ( ) {
1457- debug ! ( ?ty) ;
1458- if ty == dummy_self {
1459- let param = & generics. params [ index] ;
1460- missing_type_params. push ( param. name ) ;
1461- tcx. ty_error ( ) . into ( )
1462- } else if ty. walk ( ) . any ( |arg| arg == dummy_self. into ( ) ) {
1463- references_self = true ;
1464- tcx. ty_error ( ) . into ( )
1465- } else {
1466- arg
1467- }
1468- } else {
1469- arg
1456+ if arg == dummy_self. into ( ) {
1457+ let param = & generics. params [ index] ;
1458+ missing_type_params. push ( param. name ) ;
1459+ return tcx. ty_error ( ) . into ( ) ;
1460+ } else if arg. walk ( ) . any ( |arg| arg == dummy_self. into ( ) ) {
1461+ references_self = true ;
1462+ return tcx. ty_error ( ) . into ( ) ;
14701463 }
1464+ arg
14711465 } )
14721466 . collect ( ) ;
14731467 let substs = tcx. intern_substs ( & substs[ ..] ) ;
@@ -1506,13 +1500,34 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
15061500 } ) ;
15071501
15081502 let existential_projections = bounds. projection_bounds . iter ( ) . map ( |( bound, _) | {
1509- bound. map_bound ( |b| {
1510- if b. projection_ty . self_ty ( ) != dummy_self {
1511- tcx. sess . delay_span_bug (
1512- DUMMY_SP ,
1513- & format ! ( "trait_ref_to_existential called on {:?} with non-dummy Self" , b) ,
1514- ) ;
1503+ bound. map_bound ( |mut b| {
1504+ assert_eq ! ( b. projection_ty. self_ty( ) , dummy_self) ;
1505+
1506+ // Like for trait refs, verify that `dummy_self` did not leak inside default type
1507+ // parameters.
1508+ let references_self = b. projection_ty . substs . iter ( ) . skip ( 1 ) . any ( |arg| {
1509+ if arg. walk ( ) . any ( |arg| arg == dummy_self. into ( ) ) {
1510+ return true ;
1511+ }
1512+ false
1513+ } ) ;
1514+ if references_self {
1515+ tcx. sess
1516+ . delay_span_bug ( span, "trait object projection bounds reference `Self`" ) ;
1517+ let substs: Vec < _ > = b
1518+ . projection_ty
1519+ . substs
1520+ . iter ( )
1521+ . map ( |arg| {
1522+ if arg. walk ( ) . any ( |arg| arg == dummy_self. into ( ) ) {
1523+ return tcx. ty_error ( ) . into ( ) ;
1524+ }
1525+ arg
1526+ } )
1527+ . collect ( ) ;
1528+ b. projection_ty . substs = tcx. intern_substs ( & substs[ ..] ) ;
15151529 }
1530+
15161531 ty:: ExistentialProjection :: erase_self_ty ( tcx, b)
15171532 } )
15181533 } ) ;
0 commit comments