@@ -247,7 +247,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
247247 match category {
248248 ConstraintCategory :: AssignmentToUpvar |
249249 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) ,
251251 _ =>
252252 self . report_general_error ( mir, infcx, mir_def_id, fr, outlived_fr, category, span) ,
253253 }
@@ -257,33 +257,44 @@ impl<'tcx> RegionInferenceContext<'tcx> {
257257 & self ,
258258 mir : & Mir < ' tcx > ,
259259 infcx : & InferCtxt < ' _ , ' _ , ' tcx > ,
260+ mir_def_id : DefId ,
260261 fr : RegionVid ,
261262 outlived_fr : RegionVid ,
263+ category : & ConstraintCategory ,
262264 span : & Span ,
263265 ) {
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+
264276 let diag = & mut infcx. tcx . sess . struct_span_err (
265277 * span, & format ! ( "borrowed data escapes outside of closure" ) ,
266278 ) ;
267279
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+ }
276287 }
277288
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+ ) ;
279295
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+ }
287298 }
288299
289300 diag. emit ( ) ;
0 commit comments