@@ -1319,48 +1319,48 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1319
1319
&& !self . tcx . features ( ) . anonymous_lifetime_in_impl_trait
1320
1320
{
1321
1321
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
+
1322
1330
match self . tcx . hir ( ) . get_generics ( lifetime_ref. hir_id . owner . def_id ) {
1323
1331
Some ( generics) => {
1324
- for i in 0 ..generics. params . len ( ) {
1325
1332
1326
- if !generics . span . contains ( generics . params [ i ] . span ) {
1333
+ let mut new_param_sugg_tuple = None ;
1327
1334
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
+ }
1350
1343
}
1351
1344
}
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
+
1352
1357
} ,
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 ; }
1362
1359
}
1363
1360
1361
+ diag. emit ( ) ;
1362
+ return ;
1363
+
1364
1364
}
1365
1365
scope = s;
1366
1366
}
0 commit comments