@@ -1519,9 +1519,21 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
1519
1519
for missing in & self . missing_named_lifetime_spots {
1520
1520
match missing {
1521
1521
MissingLifetimeSpot :: Generics ( generics) => {
1522
- let ( span, sugg) = match & generics. params {
1523
- [ ] => ( generics. span , format ! ( "<{}>" , lifetime_ref) ) ,
1524
- [ param, ..] => ( param. span . shrink_to_lo ( ) , format ! ( "{}, " , lifetime_ref) ) ,
1522
+ let ( span, sugg) = if let Some ( param) = generics
1523
+ . params
1524
+ . iter ( )
1525
+ . filter ( |p| match p. kind {
1526
+ hir:: GenericParamKind :: Type {
1527
+ synthetic : Some ( hir:: SyntheticTyParamKind :: ImplTrait ) ,
1528
+ ..
1529
+ } => false ,
1530
+ _ => true ,
1531
+ } )
1532
+ . next ( )
1533
+ {
1534
+ ( param. span . shrink_to_lo ( ) , format ! ( "{}, " , lifetime_ref) )
1535
+ } else {
1536
+ ( generics. span , format ! ( "<{}>" , lifetime_ref) )
1525
1537
} ;
1526
1538
err. span_suggestion (
1527
1539
span,
@@ -1592,20 +1604,28 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
1592
1604
Applicability :: MaybeIncorrect ,
1593
1605
) ;
1594
1606
} ;
1595
- let suggest_new = |err : & mut DiagnosticBuilder < ' _ > , sugg : & str | {
1596
- err. span_label ( span, "expected named lifetime parameter" ) ;
1597
-
1598
- for missing in self . missing_named_lifetime_spots . iter ( ) . rev ( ) {
1599
- let mut introduce_suggestion = vec ! [ ] ;
1600
- let msg;
1601
- let should_break;
1602
- introduce_suggestion. push ( match missing {
1607
+ let suggest_new =
1608
+ |err : & mut DiagnosticBuilder < ' _ > , sugg : & str | {
1609
+ err. span_label ( span, "expected named lifetime parameter" ) ;
1610
+
1611
+ for missing in self . missing_named_lifetime_spots . iter ( ) . rev ( ) {
1612
+ let mut introduce_suggestion = vec ! [ ] ;
1613
+ let msg;
1614
+ let should_break;
1615
+ introduce_suggestion. push ( match missing {
1603
1616
MissingLifetimeSpot :: Generics ( generics) => {
1604
1617
msg = "consider introducing a named lifetime parameter" . to_string ( ) ;
1605
1618
should_break = true ;
1606
- match & generics. params {
1607
- [ ] => ( generics. span , "<'a>" . to_string ( ) ) ,
1608
- [ param, ..] => ( param. span . shrink_to_lo ( ) , "'a, " . to_string ( ) ) ,
1619
+ if let Some ( param) = generics. params . iter ( ) . filter ( |p| match p. kind {
1620
+ hir:: GenericParamKind :: Type {
1621
+ synthetic : Some ( hir:: SyntheticTyParamKind :: ImplTrait ) ,
1622
+ ..
1623
+ } => false ,
1624
+ _ => true ,
1625
+ } ) . next ( ) {
1626
+ ( param. span . shrink_to_lo ( ) , "'a, " . to_string ( ) )
1627
+ } else {
1628
+ ( generics. span , "<'a>" . to_string ( ) )
1609
1629
}
1610
1630
}
1611
1631
MissingLifetimeSpot :: HigherRanked { span, span_type } => {
@@ -1621,29 +1641,30 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
1621
1641
( * span, span_type. suggestion ( "'a" ) )
1622
1642
}
1623
1643
} ) ;
1624
- for param in params {
1625
- if let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( param. span )
1626
- {
1627
- if snippet. starts_with ( "&" ) && !snippet. starts_with ( "&'" ) {
1628
- introduce_suggestion
1629
- . push ( ( param. span , format ! ( "&'a {}" , & snippet[ 1 ..] ) ) ) ;
1630
- } else if snippet. starts_with ( "&'_ " ) {
1631
- introduce_suggestion
1632
- . push ( ( param. span , format ! ( "&'a {}" , & snippet[ 4 ..] ) ) ) ;
1644
+ for param in params {
1645
+ if let Ok ( snippet) =
1646
+ self . tcx . sess . source_map ( ) . span_to_snippet ( param. span )
1647
+ {
1648
+ if snippet. starts_with ( "&" ) && !snippet. starts_with ( "&'" ) {
1649
+ introduce_suggestion
1650
+ . push ( ( param. span , format ! ( "&'a {}" , & snippet[ 1 ..] ) ) ) ;
1651
+ } else if snippet. starts_with ( "&'_ " ) {
1652
+ introduce_suggestion
1653
+ . push ( ( param. span , format ! ( "&'a {}" , & snippet[ 4 ..] ) ) ) ;
1654
+ }
1633
1655
}
1634
1656
}
1657
+ introduce_suggestion. push ( ( span, sugg. to_string ( ) ) ) ;
1658
+ err. multipart_suggestion (
1659
+ & msg,
1660
+ introduce_suggestion,
1661
+ Applicability :: MaybeIncorrect ,
1662
+ ) ;
1663
+ if should_break {
1664
+ break ;
1665
+ }
1635
1666
}
1636
- introduce_suggestion. push ( ( span, sugg. to_string ( ) ) ) ;
1637
- err. multipart_suggestion (
1638
- & msg,
1639
- introduce_suggestion,
1640
- Applicability :: MaybeIncorrect ,
1641
- ) ;
1642
- if should_break {
1643
- break ;
1644
- }
1645
- }
1646
- } ;
1667
+ } ;
1647
1668
1648
1669
match (
1649
1670
lifetime_names. len ( ) ,
0 commit comments