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,6 +24,7 @@ use rustc_span::symbol::{sym, Ident};
24
24
use rustc_span:: Span ;
25
25
use std:: fmt;
26
26
27
+
27
28
trait RegionExt {
28
29
fn early ( hir_map : Map < ' _ > , param : & GenericParam < ' _ > ) -> ( LocalDefId , Region ) ;
29
30
@@ -1318,13 +1319,36 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
1318
1319
&& let hir:: IsAsync :: NotAsync = self . tcx . asyncness ( lifetime_ref. hir_id . owner . def_id )
1319
1320
&& !self . tcx . features ( ) . anonymous_lifetime_in_impl_trait
1320
1321
{
1321
- rustc_session:: parse:: feature_err (
1322
- & self . tcx . sess . parse_sess ,
1323
- sym:: anonymous_lifetime_in_impl_trait,
1324
- lifetime_ref. span ,
1325
- "anonymous lifetimes in `impl Trait` are unstable" ,
1326
- ) . emit ( ) ;
1327
- return ;
1322
+
1323
+ match self . tcx . hir ( ) . get_generics ( lifetime_ref. hir_id . owner . to_def_id ( ) . as_local ( ) . unwrap ( ) ) {
1324
+ Some ( generics) => {
1325
+ for i in 0 ..generics. params . len ( ) {
1326
+
1327
+ if !generics. span . contains ( generics. params [ i] . span ) {
1328
+ struct_span_err ! (
1329
+ self . tcx. sess,
1330
+ 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 ;
1338
+ }
1339
+ }
1340
+ } ,
1341
+ None => {
1342
+ rustc_session:: parse:: feature_err (
1343
+ & self . tcx . sess . parse_sess ,
1344
+ sym:: anonymous_lifetime_in_impl_trait,
1345
+ lifetime_ref. span ,
1346
+ "anonymous lifetimes in `impl Trait` are unstable" ,
1347
+ ) . emit ( ) ;
1348
+ return ;
1349
+ }
1350
+ }
1351
+
1328
1352
}
1329
1353
scope = s;
1330
1354
}
0 commit comments