@@ -1821,7 +1821,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
1821
1821
crate fn add_missing_lifetime_specifiers_label (
1822
1822
& self ,
1823
1823
err : & mut DiagnosticBuilder < ' _ > ,
1824
- spans_with_counts : Vec < ( Span , usize ) > ,
1824
+ mut spans_with_counts : Vec < ( Span , usize ) > ,
1825
1825
lifetime_names : & FxHashSet < Symbol > ,
1826
1826
lifetime_spans : Vec < Span > ,
1827
1827
params : & [ ElisionFailureInfo ] ,
@@ -1831,13 +1831,21 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
1831
1831
. map ( |( span, _) | self . tcx . sess . source_map ( ) . span_to_snippet ( * span) . ok ( ) )
1832
1832
. collect ( ) ;
1833
1833
1834
- for ( span, count) in & spans_with_counts {
1834
+ // Empty generics are marked with a span of "<", but since from now on
1835
+ // that information is in the snippets it can be removed from the spans.
1836
+ for ( ( span, _) , snippet) in spans_with_counts. iter_mut ( ) . zip ( & snippets) {
1837
+ if snippet. as_deref ( ) == Some ( "<" ) {
1838
+ * span = span. shrink_to_hi ( ) ;
1839
+ }
1840
+ }
1841
+
1842
+ for & ( span, count) in & spans_with_counts {
1835
1843
err. span_label (
1836
- * span,
1844
+ span,
1837
1845
format ! (
1838
1846
"expected {} lifetime parameter{}" ,
1839
- if * count == 1 { "named" . to_string( ) } else { count. to_string( ) } ,
1840
- pluralize!( * count) ,
1847
+ if count == 1 { "named" . to_string( ) } else { count. to_string( ) } ,
1848
+ pluralize!( count) ,
1841
1849
) ,
1842
1850
) ;
1843
1851
}
@@ -1982,6 +1990,14 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
1982
1990
. collect :: < Vec < _ > > ( )
1983
1991
. join ( ", " ) ,
1984
1992
)
1993
+ } else if snippet == "<" || snippet == "(" {
1994
+ (
1995
+ span. shrink_to_hi ( ) ,
1996
+ std:: iter:: repeat ( "'static" )
1997
+ . take ( count)
1998
+ . collect :: < Vec < _ > > ( )
1999
+ . join ( ", " ) ,
2000
+ )
1985
2001
} else {
1986
2002
(
1987
2003
span. shrink_to_hi ( ) ,
@@ -1990,7 +2006,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
1990
2006
std:: iter:: repeat( "'static" )
1991
2007
. take( count)
1992
2008
. collect:: <Vec <_>>( )
1993
- . join( ", " )
2009
+ . join( ", " ) ,
1994
2010
) ,
1995
2011
)
1996
2012
}
@@ -2045,6 +2061,9 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
2045
2061
Some ( "&" ) => Some ( Box :: new ( |name| format ! ( "&{} " , name) ) ) ,
2046
2062
Some ( "'_" ) => Some ( Box :: new ( |n| n. to_string ( ) ) ) ,
2047
2063
Some ( "" ) => Some ( Box :: new ( move |n| format ! ( "{}, " , n) . repeat ( count) ) ) ,
2064
+ Some ( "<" ) => Some ( Box :: new ( move |n| {
2065
+ std:: iter:: repeat ( n) . take ( count) . collect :: < Vec < _ > > ( ) . join ( ", " )
2066
+ } ) ) ,
2048
2067
Some ( snippet) if !snippet. ends_with ( '>' ) => Some ( Box :: new ( move |name| {
2049
2068
format ! (
2050
2069
"{}<{}>" ,
@@ -2071,6 +2090,9 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
2071
2090
Some ( "" ) => {
2072
2091
Some ( std:: iter:: repeat ( "'a, " ) . take ( count) . collect :: < Vec < _ > > ( ) . join ( "" ) )
2073
2092
}
2093
+ Some ( "<" ) => {
2094
+ Some ( std:: iter:: repeat ( "'a" ) . take ( count) . collect :: < Vec < _ > > ( ) . join ( ", " ) )
2095
+ }
2074
2096
Some ( snippet) => Some ( format ! (
2075
2097
"{}<{}>" ,
2076
2098
snippet,
0 commit comments