@@ -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;
@@ -1458,16 +1458,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1458
1458
if ty == dummy_self {
1459
1459
let param = & generics. params [ index] ;
1460
1460
missing_type_params. push ( param. name ) ;
1461
- tcx. ty_error ( ) . into ( )
1461
+ return tcx. ty_error ( ) . into ( ) ;
1462
1462
} else if ty. walk ( ) . any ( |arg| arg == dummy_self. into ( ) ) {
1463
1463
references_self = true ;
1464
- tcx. ty_error ( ) . into ( )
1465
- } else {
1466
- arg
1464
+ return tcx. ty_error ( ) . into ( ) ;
1467
1465
}
1468
- } else {
1469
- arg
1470
1466
}
1467
+ arg
1471
1468
} )
1472
1469
. collect ( ) ;
1473
1470
let substs = tcx. intern_substs ( & substs[ ..] ) ;
@@ -1506,13 +1503,36 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1506
1503
} ) ;
1507
1504
1508
1505
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
- ) ;
1506
+ bound. map_bound ( |mut b| {
1507
+ assert_eq ! ( b. projection_ty. self_ty( ) , dummy_self) ;
1508
+
1509
+ // Like for trait refs, verify that `dummy_self` did not leak inside default type
1510
+ // parameters.
1511
+ let references_self = b. projection_ty . substs . iter ( ) . skip ( 1 ) . any ( |arg| {
1512
+ if let ty:: GenericArgKind :: Type ( ty) = arg. unpack ( ) {
1513
+ if ty == dummy_self || ty. walk ( ) . any ( |arg| arg == dummy_self. into ( ) ) {
1514
+ return true ;
1515
+ }
1516
+ }
1517
+ false
1518
+ } ) ;
1519
+ if references_self {
1520
+ tcx. sess
1521
+ . delay_span_bug ( span, "trait object projection bounds reference `Self`" ) ;
1522
+ let substs: Vec < _ > = b
1523
+ . projection_ty
1524
+ . substs
1525
+ . iter ( )
1526
+ . map ( |arg| {
1527
+ if let ty:: GenericArgKind :: Type ( _) = arg. unpack ( ) {
1528
+ return tcx. ty_error ( ) . into ( ) ;
1529
+ }
1530
+ arg
1531
+ } )
1532
+ . collect ( ) ;
1533
+ b. projection_ty . substs = tcx. intern_substs ( & substs[ ..] ) ;
1515
1534
}
1535
+
1516
1536
ty:: ExistentialProjection :: erase_self_ty ( tcx, b)
1517
1537
} )
1518
1538
} ) ;
0 commit comments