88
99use rustc_ast:: walk_list;
1010use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap , FxIndexSet } ;
11- use rustc_errors:: struct_span_err;
11+ use rustc_errors:: { struct_span_err} ;
1212use rustc_hir as hir;
1313use rustc_hir:: def:: { DefKind , Res } ;
1414use rustc_hir:: def_id:: LocalDefId ;
@@ -24,6 +24,7 @@ use rustc_span::symbol::{sym, Ident};
2424use rustc_span:: Span ;
2525use std:: fmt;
2626
27+
2728trait RegionExt {
2829 fn early ( hir_map : Map < ' _ > , param : & GenericParam < ' _ > ) -> ( LocalDefId , Region ) ;
2930
@@ -1318,13 +1319,36 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
13181319 && let hir:: IsAsync :: NotAsync = self . tcx . asyncness ( lifetime_ref. hir_id . owner . def_id )
13191320 && !self . tcx . features ( ) . anonymous_lifetime_in_impl_trait
13201321 {
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+
13281352 }
13291353 scope = s;
13301354 }
0 commit comments