@@ -43,7 +43,7 @@ use rustc_trait_selection::traits::error_reporting::{
43
43
} ;
44
44
use rustc_trait_selection:: traits:: wf:: object_region_bounds;
45
45
46
- use smallvec:: SmallVec ;
46
+ use smallvec:: { smallvec , SmallVec } ;
47
47
use std:: collections:: BTreeSet ;
48
48
use std:: slice;
49
49
@@ -1444,19 +1444,26 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1444
1444
// Verify that `dummy_self` did not leak inside default type parameters. This
1445
1445
// could not be done at path creation, since we need to see through trait aliases.
1446
1446
let mut missing_type_params = vec ! [ ] ;
1447
+ let mut references_self = false ;
1447
1448
let generics = tcx. generics_of ( trait_ref. def_id ) ;
1448
1449
let substs: Vec < _ > = trait_ref
1449
1450
. substs
1450
1451
. iter ( )
1451
1452
. enumerate ( )
1452
1453
. skip ( 1 ) // Remove `Self` for `ExistentialPredicate`.
1453
1454
. map ( |( index, arg) | {
1454
- if let ty:: GenericArgKind :: Type ( ty) = arg. unpack ( )
1455
- && ty == dummy_self
1456
- {
1457
- let param = & generics. params [ index] ;
1458
- missing_type_params. push ( param. name ) ;
1459
- tcx. ty_error ( ) . into ( )
1455
+ if let ty:: GenericArgKind :: Type ( ty) = arg. unpack ( ) {
1456
+ debug ! ( ?ty) ;
1457
+ if ty == dummy_self {
1458
+ let param = & generics. params [ index] ;
1459
+ missing_type_params. push ( param. name ) ;
1460
+ tcx. ty_error ( ) . into ( )
1461
+ } else if ty. walk ( ) . any ( |arg| arg == dummy_self. into ( ) ) {
1462
+ references_self = true ;
1463
+ tcx. ty_error ( ) . into ( )
1464
+ } else {
1465
+ arg
1466
+ }
1460
1467
} else {
1461
1468
arg
1462
1469
}
@@ -1476,6 +1483,23 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1476
1483
empty_generic_args,
1477
1484
) ;
1478
1485
1486
+ if references_self {
1487
+ let def_id = i. bottom ( ) . 0 . def_id ( ) ;
1488
+ let mut err = struct_span_err ! (
1489
+ tcx. sess,
1490
+ i. bottom( ) . 1 ,
1491
+ E0038 ,
1492
+ "the {} `{}` cannot be made into an object" ,
1493
+ tcx. def_kind( def_id) . descr( def_id) ,
1494
+ tcx. item_name( def_id) ,
1495
+ ) ;
1496
+ err. note (
1497
+ rustc_middle:: traits:: ObjectSafetyViolation :: SupertraitSelf ( smallvec ! [ ] )
1498
+ . error_msg ( ) ,
1499
+ ) ;
1500
+ err. emit ( ) ;
1501
+ }
1502
+
1479
1503
ty:: ExistentialTraitRef { def_id : trait_ref. def_id , substs }
1480
1504
} )
1481
1505
} ) ;
0 commit comments