11//! Error Reporting for Anonymous Region Lifetime Errors
22//! where one region is named and the other is anonymous.
33use crate :: infer:: error_reporting:: nice_region_error:: NiceRegionError ;
4+ use crate :: hir:: { FunctionRetTy , TyKind } ;
45use crate :: ty;
56use errors:: { Applicability , DiagnosticBuilder } ;
67
@@ -11,9 +12,10 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
1112 let ( span, sub, sup) = self . get_regions ( ) ;
1213
1314 debug ! (
14- "try_report_named_anon_conflict(sub={:?}, sup={:?})" ,
15+ "try_report_named_anon_conflict(sub={:?}, sup={:?}, error={:?} )" ,
1516 sub,
16- sup
17+ sup,
18+ self . error,
1719 ) ;
1820
1921 // Determine whether the sub and sup consist of one named region ('a)
@@ -84,6 +86,13 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
8486 {
8587 return None ;
8688 }
89+ if let FunctionRetTy :: Return ( ty) = & fndecl. output {
90+ if let ( TyKind :: Def ( _, _) , ty:: ReStatic ) = ( & ty. node , sub) {
91+ // This is an impl Trait return that evaluates de need of 'static.
92+ // We handle this case better in `static_impl_trait`.
93+ return None ;
94+ }
95+ }
8796 }
8897
8998 let ( error_var, span_label_var) = if let Some ( simple_ident) = arg. pat . simple_ident ( ) {
@@ -103,13 +112,13 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
103112 error_var
104113 ) ;
105114
115+ diag. span_label ( span, format ! ( "lifetime `{}` required" , named) ) ;
106116 diag. span_suggestion (
107- new_ty_span,
108- & format ! ( "add explicit lifetime `{}` to {}" , named, span_label_var) ,
109- new_ty. to_string ( ) ,
110- Applicability :: Unspecified ,
111- )
112- . span_label ( span, format ! ( "lifetime `{}` required" , named) ) ;
117+ new_ty_span,
118+ & format ! ( "add explicit lifetime `{}` to {}" , named, span_label_var) ,
119+ new_ty. to_string ( ) ,
120+ Applicability :: Unspecified ,
121+ ) ;
113122
114123 Some ( diag)
115124 }
0 commit comments