@@ -247,7 +247,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
247
247
match category {
248
248
ConstraintCategory :: AssignmentToUpvar |
249
249
ConstraintCategory :: CallArgumentToUpvar =>
250
- self . report_closure_error ( mir, infcx, fr, outlived_fr, span) ,
250
+ self . report_closure_error ( mir, infcx, mir_def_id , fr, outlived_fr, category , span) ,
251
251
_ =>
252
252
self . report_general_error ( mir, infcx, mir_def_id, fr, outlived_fr, category, span) ,
253
253
}
@@ -257,33 +257,44 @@ impl<'tcx> RegionInferenceContext<'tcx> {
257
257
& self ,
258
258
mir : & Mir < ' tcx > ,
259
259
infcx : & InferCtxt < ' _ , ' _ , ' tcx > ,
260
+ mir_def_id : DefId ,
260
261
fr : RegionVid ,
261
262
outlived_fr : RegionVid ,
263
+ category : & ConstraintCategory ,
262
264
span : & Span ,
263
265
) {
266
+ let fr_name_and_span = self . get_var_name_and_span_for_region (
267
+ infcx. tcx , mir, fr) ;
268
+ let outlived_fr_name_and_span = self . get_var_name_and_span_for_region (
269
+ infcx. tcx , mir, outlived_fr) ;
270
+
271
+ if fr_name_and_span. is_none ( ) && outlived_fr_name_and_span. is_none ( ) {
272
+ return self . report_general_error ( mir, infcx, mir_def_id, fr, outlived_fr, category,
273
+ span) ;
274
+ }
275
+
264
276
let diag = & mut infcx. tcx . sess . struct_span_err (
265
277
* span, & format ! ( "borrowed data escapes outside of closure" ) ,
266
278
) ;
267
279
268
- let ( outlived_fr_name, outlived_fr_span) = self . get_var_name_and_span_for_region (
269
- infcx. tcx , mir, outlived_fr) ;
270
-
271
- if let Some ( name) = outlived_fr_name {
272
- diag. span_label (
273
- outlived_fr_span,
274
- format ! ( "`{}` is declared here, outside of the closure body" , name) ,
275
- ) ;
280
+ if let Some ( ( outlived_fr_name, outlived_fr_span) ) = outlived_fr_name_and_span {
281
+ if let Some ( name) = outlived_fr_name {
282
+ diag. span_label (
283
+ outlived_fr_span,
284
+ format ! ( "`{}` is declared here, outside of the closure body" , name) ,
285
+ ) ;
286
+ }
276
287
}
277
288
278
- let ( fr_name, fr_span) = self . get_var_name_and_span_for_region ( infcx. tcx , mir, fr) ;
289
+ if let Some ( ( fr_name, fr_span) ) = fr_name_and_span {
290
+ if let Some ( name) = fr_name {
291
+ diag. span_label (
292
+ fr_span,
293
+ format ! ( "`{}` is a reference that is only valid in the closure body" , name) ,
294
+ ) ;
279
295
280
- if let Some ( name) = fr_name {
281
- diag. span_label (
282
- fr_span,
283
- format ! ( "`{}` is a reference that is only valid in the closure body" , name) ,
284
- ) ;
285
-
286
- diag. span_label ( * span, format ! ( "`{}` escapes the closure body here" , name) ) ;
296
+ diag. span_label ( * span, format ! ( "`{}` escapes the closure body here" , name) ) ;
297
+ }
287
298
}
288
299
289
300
diag. emit ( ) ;
0 commit comments