@@ -106,91 +106,47 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
106
106
None => String :: new ( ) ,
107
107
} ;
108
108
109
- let ( span_1, span_2, main_label, span_label, future_return_type) =
110
- match ( sup_is_ret_type, sub_is_ret_type) {
111
- ( None , None ) => {
112
- let ( main_label_1, span_label_1) = if ty_sup. hir_id == ty_sub. hir_id {
113
- (
114
- "this type is declared with multiple lifetimes..." . to_owned ( ) ,
115
- "...but data with one lifetime flows into the other here" . to_owned ( ) ,
116
- )
117
- } else {
118
- (
119
- "these two types are declared with different lifetimes..." . to_owned ( ) ,
120
- format ! ( "...but data{} flows{} here" , span_label_var1, span_label_var2) ,
121
- )
122
- } ;
123
- ( ty_sup. span , ty_sub. span , main_label_1, span_label_1, None )
124
- }
109
+ debug ! (
110
+ "try_report_anon_anon_conflict: sub_is_ret_type={:?} sup_is_ret_type={:?}" ,
111
+ sub_is_ret_type, sup_is_ret_type
112
+ ) ;
125
113
126
- ( Some ( ret_span) , _) => {
127
- let sup_future = self . future_return_type ( scope_def_id_sup) ;
128
- let ( return_type, action) = if sup_future. is_some ( ) {
129
- ( "returned future" , "held across an await point" )
130
- } else {
131
- ( "return type" , "returned" )
132
- } ;
114
+ let mut err = struct_span_err ! ( self . tcx( ) . sess, span, E0623 , "lifetime mismatch" ) ;
133
115
134
- (
135
- ty_sub. span ,
136
- ret_span,
137
- format ! (
138
- "this parameter and the {} are declared with different lifetimes..." ,
139
- return_type
140
- ) ,
141
- format ! ( "...but data{} is {} here" , span_label_var1, action) ,
142
- sup_future,
143
- )
144
- }
145
- ( _, Some ( ret_span) ) => {
146
- let sub_future = self . future_return_type ( scope_def_id_sub) ;
147
- let ( return_type, action) = if sub_future. is_some ( ) {
148
- ( "returned future" , "held across an await point" )
149
- } else {
150
- ( "return type" , "returned" )
151
- } ;
116
+ match ( sup_is_ret_type, sub_is_ret_type) {
117
+ ( ret_capture @ Some ( ret_span) , _) | ( _, ret_capture @ Some ( ret_span) ) => {
118
+ let param_span =
119
+ if sup_is_ret_type == ret_capture { ty_sub. span } else { ty_sup. span } ;
120
+
121
+ err. span_label (
122
+ param_span,
123
+ "this parameter and the return type are declared with different lifetimes..." ,
124
+ ) ;
125
+ err. span_label ( ret_span, "" ) ;
126
+ err. span_label ( span, format ! ( "...but data{} is returned here" , span_label_var1) ) ;
127
+ }
152
128
153
- (
129
+ ( None , None ) => {
130
+ if ty_sup. hir_id == ty_sub. hir_id {
131
+ err. span_label ( ty_sup. span , "this type is declared with multiple lifetimes..." ) ;
132
+ err. span_label ( ty_sub. span , "" ) ;
133
+ err. span_label ( span, "...but data with one lifetime flows into the other here" ) ;
134
+ } else {
135
+ err. span_label (
154
136
ty_sup. span ,
155
- ret_span,
156
- format ! (
157
- "this parameter and the {} are declared with different lifetimes..." ,
158
- return_type
159
- ) ,
160
- format ! ( "...but data{} is {} here" , span_label_var1, action) ,
161
- sub_future,
162
- )
137
+ "these two types are declared with different lifetimes..." ,
138
+ ) ;
139
+ err. span_label ( ty_sub. span , "" ) ;
140
+ err. span_label (
141
+ span,
142
+ format ! ( "...but data{} flows{} here" , span_label_var1, span_label_var2) ,
143
+ ) ;
163
144
}
164
- } ;
165
-
166
- let mut err = struct_span_err ! ( self . tcx( ) . sess, span, E0623 , "lifetime mismatch" ) ;
167
-
168
- err. span_label ( span_1, main_label) ;
169
- err. span_label ( span_2, String :: new ( ) ) ;
170
- err. span_label ( span, span_label) ;
145
+ }
146
+ }
171
147
172
148
self . suggest_adding_lifetime_params ( sub, ty_sup, ty_sub, & mut err) ;
173
149
174
- // TODO: This is only helpful if the lifetime more visible in the impl Future type than in the signature.
175
- if let Some ( t) = future_return_type {
176
- let snip = self
177
- . tcx ( )
178
- . sess
179
- . source_map ( )
180
- . span_to_snippet ( t. span )
181
- . ok ( )
182
- . and_then ( |s| match ( & t. kind , s. as_str ( ) ) {
183
- ( rustc_hir:: TyKind :: Tup ( & [ ] ) , "" ) => Some ( "()" . to_string ( ) ) ,
184
- ( _, "" ) => None ,
185
- _ => Some ( s) ,
186
- } )
187
- . unwrap_or_else ( || "{unnamed_type}" . to_string ( ) ) ;
188
-
189
- err. span_label (
190
- t. span ,
191
- & format ! ( "this `async fn` implicitly returns an `impl Future<Output = {}>`" , snip) ,
192
- ) ;
193
- }
194
150
err. emit ( ) ;
195
151
Some ( ErrorReported )
196
152
}
0 commit comments