@@ -1458,15 +1458,20 @@ impl TypeAliasBounds {
1458
1458
1459
1459
impl < ' tcx > LateLintPass < ' tcx > for TypeAliasBounds {
1460
1460
fn check_item ( & mut self , cx : & LateContext < ' _ > , item : & hir:: Item < ' _ > ) {
1461
- let hir:: ItemKind :: TyAlias ( ty, type_alias_generics) = & item. kind else { return } ;
1462
- if cx. tcx . type_of ( item. owner_id . def_id ) . skip_binder ( ) . has_opaque_types ( ) {
1463
- // Bounds are respected for `type X = impl Trait` and `type X = (impl Trait, Y);`
1461
+ let hir:: ItemKind :: TyAlias ( hir_ty, type_alias_generics) = & item. kind else { return } ;
1462
+
1463
+ if cx. tcx . features ( ) . lazy_type_alias {
1464
+ // Bounds of lazy type aliases are respected.
1464
1465
return ;
1465
1466
}
1466
- if cx. tcx . type_of ( item. owner_id ) . skip_binder ( ) . has_inherent_projections ( ) {
1467
- // Bounds are respected for `type X = … Type::Inherent …`
1467
+
1468
+ let ty = cx. tcx . type_of ( item. owner_id ) . skip_binder ( ) ;
1469
+ if ty. has_opaque_types ( ) || ty. has_inherent_projections ( ) {
1470
+ // Bounds of type aliases that contain opaque types or inherent projections are respected.
1471
+ // E.g: `type X = impl Trait;`, `type X = (impl Trait, Y);`, `type X = Type::Inherent;`.
1468
1472
return ;
1469
1473
}
1474
+
1470
1475
// There must not be a where clause
1471
1476
if type_alias_generics. predicates . is_empty ( ) {
1472
1477
return ;
@@ -1491,7 +1496,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
1491
1496
if !where_spans. is_empty ( ) {
1492
1497
let sub = ( !suggested_changing_assoc_types) . then ( || {
1493
1498
suggested_changing_assoc_types = true ;
1494
- SuggestChangingAssocTypes { ty }
1499
+ SuggestChangingAssocTypes { ty : hir_ty }
1495
1500
} ) ;
1496
1501
cx. emit_spanned_lint (
1497
1502
TYPE_ALIAS_BOUNDS ,
@@ -1507,7 +1512,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
1507
1512
let suggestion = BuiltinTypeAliasGenericBoundsSuggestion { suggestions : inline_sugg } ;
1508
1513
let sub = ( !suggested_changing_assoc_types) . then ( || {
1509
1514
suggested_changing_assoc_types = true ;
1510
- SuggestChangingAssocTypes { ty }
1515
+ SuggestChangingAssocTypes { ty : hir_ty }
1511
1516
} ) ;
1512
1517
cx. emit_spanned_lint (
1513
1518
TYPE_ALIAS_BOUNDS ,
0 commit comments