1
1
//! Error Reporting for Anonymous Region Lifetime Errors
2
2
//! where one region is named and the other is anonymous.
3
3
use crate :: infer:: error_reporting:: nice_region_error:: NiceRegionError ;
4
+ use crate :: hir:: { FunctionRetTy , TyKind } ;
4
5
use crate :: ty;
5
6
use errors:: { Applicability , DiagnosticBuilder } ;
6
7
@@ -11,9 +12,10 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
11
12
let ( span, sub, sup) = self . get_regions ( ) ;
12
13
13
14
debug ! (
14
- "try_report_named_anon_conflict(sub={:?}, sup={:?})" ,
15
+ "try_report_named_anon_conflict(sub={:?}, sup={:?}, error={:?} )" ,
15
16
sub,
16
- sup
17
+ sup,
18
+ self . error,
17
19
) ;
18
20
19
21
// Determine whether the sub and sup consist of one named region ('a)
@@ -84,6 +86,13 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
84
86
{
85
87
return None ;
86
88
}
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
+ }
87
96
}
88
97
89
98
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> {
103
112
error_var
104
113
) ;
105
114
115
+ diag. span_label ( span, format ! ( "lifetime `{}` required" , named) ) ;
106
116
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
+ ) ;
113
122
114
123
Some ( diag)
115
124
}
0 commit comments