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