@@ -1319,48 +1319,48 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
13191319 && !self . tcx . features ( ) . anonymous_lifetime_in_impl_trait
13201320 {
13211321
1322+
1323+ let mut diag = rustc_session:: parse:: feature_err (
1324+ & self . tcx . sess . parse_sess ,
1325+ sym:: anonymous_lifetime_in_impl_trait,
1326+ lifetime_ref. span ,
1327+ "anonymous lifetimes in `impl Trait` are unstable" ,
1328+ ) ;
1329+
13221330 match self . tcx . hir ( ) . get_generics ( lifetime_ref. hir_id . owner . def_id ) {
13231331 Some ( generics) => {
1324- for i in 0 ..generics. params . len ( ) {
13251332
1326- if !generics . span . contains ( generics . params [ i ] . span ) {
1333+ let mut new_param_sugg_tuple = None ;
13271334
1328- let mut diag = rustc_session:: parse:: feature_err (
1329- & self . tcx . sess . parse_sess ,
1330- sym:: anonymous_lifetime_in_impl_trait,
1331- lifetime_ref. span ,
1332- "anonymous lifetimes in `impl Trait` are unstable" ,
1333- ) ;
1334-
1335- diag. span_label ( lifetime_ref. span , "expected named lifetime parameter" ) ;
1336- diag. multipart_suggestion ( "consider introducing a named lifetime parameter" ,
1337- vec ! [
1338- ( lifetime_ref. span. shrink_to_hi( ) , "'a " . to_owned( ) ) ,
1339- match generics. span_for_param_suggestion( ) {
1340- Some ( _) => {
1341- ( self . tcx. sess. source_map( ) . span_through_char( generics. span, '<' ) . shrink_to_hi( ) , "'a, " . to_owned( ) )
1342- }
1343- None => ( generics. span, "<'a>" . to_owned( ) ) ,
1344-
1345- }
1346- ] , rustc_errors:: Applicability :: MaybeIncorrect ) ;
1347- diag. emit ( ) ;
1348-
1349- return ;
1335+ for i in 0 ..generics. params . len ( ) {
1336+ if !generics. span . contains ( generics. params [ i] . span ) {
1337+ new_param_sugg_tuple = match generics. span_for_param_suggestion ( ) {
1338+ Some ( _) => {
1339+ Some ( ( self . tcx . sess . source_map ( ) . span_through_char ( generics. span , '<' ) . shrink_to_hi ( ) , "'a, " . to_owned ( ) ) )
1340+ } ,
1341+ None => Some ( ( generics. span , "<'a>" . to_owned ( ) ) )
1342+ }
13501343 }
13511344 }
1345+
1346+ let mut multi_sugg_vec = vec ! [ ( lifetime_ref. span. shrink_to_hi( ) , "'a " . to_owned( ) ) ] ;
1347+
1348+ if let Some ( new_tuple) = new_param_sugg_tuple{
1349+ multi_sugg_vec. push ( new_tuple) ;
1350+ }
1351+
1352+ diag. span_label ( lifetime_ref. span , "expected named lifetime parameter" ) ;
1353+ diag. multipart_suggestion ( "consider introducing a named lifetime parameter" ,
1354+ multi_sugg_vec,
1355+ rustc_errors:: Applicability :: MaybeIncorrect ) ;
1356+
13521357 } ,
1353- None => {
1354- rustc_session:: parse:: feature_err (
1355- & self . tcx . sess . parse_sess ,
1356- sym:: anonymous_lifetime_in_impl_trait,
1357- lifetime_ref. span ,
1358- "anonymous lifetimes in `impl Trait` are unstable" ,
1359- ) . emit ( ) ;
1360- return ;
1361- }
1358+ None => { continue ; }
13621359 }
13631360
1361+ diag. emit ( ) ;
1362+ return ;
1363+
13641364 }
13651365 scope = s;
13661366 }
0 commit comments