@@ -35,7 +35,7 @@ use rustc_session::lint::builtin::{AMBIGUOUS_ASSOCIATED_ITEMS, BARE_TRAIT_OBJECT
35
35
use rustc_span:: edition:: Edition ;
36
36
use rustc_span:: lev_distance:: find_best_match_for_name;
37
37
use rustc_span:: symbol:: { kw, Ident , Symbol } ;
38
- use rustc_span:: { Span , DUMMY_SP } ;
38
+ use rustc_span:: Span ;
39
39
use rustc_target:: spec:: abi;
40
40
use rustc_trait_selection:: traits;
41
41
use rustc_trait_selection:: traits:: astconv_object_safety_violations;
@@ -1453,21 +1453,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1453
1453
. enumerate ( )
1454
1454
. skip ( 1 ) // Remove `Self` for `ExistentialPredicate`.
1455
1455
. 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 ( ) ;
1470
1463
}
1464
+ arg
1471
1465
} )
1472
1466
. collect ( ) ;
1473
1467
let substs = tcx. intern_substs ( & substs[ ..] ) ;
@@ -1506,13 +1500,34 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1506
1500
} ) ;
1507
1501
1508
1502
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[ ..] ) ;
1515
1529
}
1530
+
1516
1531
ty:: ExistentialProjection :: erase_self_ty ( tcx, b)
1517
1532
} )
1518
1533
} ) ;
0 commit comments