8
8
9
9
use rustc_ast:: walk_list;
10
10
use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap , FxIndexSet } ;
11
- use rustc_errors:: { struct_span_err} ;
11
+ use rustc_errors:: struct_span_err;
12
12
use rustc_hir as hir;
13
13
use rustc_hir:: def:: { DefKind , Res } ;
14
14
use rustc_hir:: def_id:: LocalDefId ;
@@ -24,7 +24,6 @@ use rustc_span::symbol::{sym, Ident};
24
24
use rustc_span:: Span ;
25
25
use std:: fmt;
26
26
27
-
28
27
trait RegionExt {
29
28
fn early ( hir_map : Map < ' _ > , param : & GenericParam < ' _ > ) -> ( LocalDefId , Region ) ;
30
29
@@ -1320,21 +1319,29 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1320
1319
&& !self . tcx . features ( ) . anonymous_lifetime_in_impl_trait
1321
1320
{
1322
1321
1323
- match self . tcx . hir ( ) . get_generics ( lifetime_ref. hir_id . owner . to_def_id ( ) . as_local ( ) . unwrap ( ) ) {
1322
+ match self . tcx . hir ( ) . get_generics ( lifetime_ref. hir_id . owner . def_id ) {
1324
1323
Some ( generics) => {
1325
1324
for i in 0 ..generics. params . len ( ) {
1326
1325
1327
1326
if !generics. span . contains ( generics. params [ i] . span ) {
1328
- struct_span_err ! (
1329
- self . tcx. sess,
1327
+
1328
+ let mut diag = rustc_session:: parse:: feature_err (
1329
+ & self . tcx . sess . parse_sess ,
1330
+ sym:: anonymous_lifetime_in_impl_trait,
1330
1331
lifetime_ref. span ,
1331
- E0106 ,
1332
- "missing lifetime specifier"
1333
- )
1334
- . span_label ( lifetime_ref. span , "expected named lifetime parameter" )
1335
- . span_help ( generics. span , "consider introducing a named lifetime parameter" )
1336
- . emit ( ) ;
1337
- return ;
1332
+ "anonymous lifetimes in `impl Trait` are unstable" ,
1333
+ ) ;
1334
+
1335
+ diag. span_label ( lifetime_ref. span , "expected named lifetime parameter" ) ;
1336
+
1337
+ diag. multipart_suggestion ( "consider introducing a named lifetime parameter" ,
1338
+ vec ! [
1339
+ ( lifetime_ref. span, "&'a " . to_owned( ) ) ,
1340
+ ( generics. span, "<'a>" . to_owned( ) )
1341
+ ] , rustc_errors:: Applicability :: MaybeIncorrect ) ;
1342
+ diag. emit ( ) ;
1343
+
1344
+ return ;
1338
1345
}
1339
1346
}
1340
1347
} ,
0 commit comments