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,7 +24,6 @@ use rustc_span::symbol::{sym, Ident};
2424use rustc_span:: Span ;
2525use std:: fmt;
2626
27-
2827trait RegionExt {
2928 fn early ( hir_map : Map < ' _ > , param : & GenericParam < ' _ > ) -> ( LocalDefId , Region ) ;
3029
@@ -1320,21 +1319,29 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
13201319 && !self . tcx . features ( ) . anonymous_lifetime_in_impl_trait
13211320 {
13221321
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 ) {
13241323 Some ( generics) => {
13251324 for i in 0 ..generics. params . len ( ) {
13261325
13271326 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,
13301331 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 ;
13381345 }
13391346 }
13401347 } ,
0 commit comments