@@ -31,9 +31,7 @@ mod var_name;
31
31
enum ConstraintCategory {
32
32
Cast ,
33
33
Assignment ,
34
- AssignmentToUpvar ,
35
34
Return ,
36
- CallArgumentToUpvar ,
37
35
CallArgument ,
38
36
Other ,
39
37
Boring ,
@@ -42,14 +40,10 @@ enum ConstraintCategory {
42
40
impl fmt:: Display for ConstraintCategory {
43
41
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
44
42
match self {
45
- ConstraintCategory :: Assignment | ConstraintCategory :: AssignmentToUpvar => {
46
- write ! ( f, "assignment" )
47
- }
43
+ ConstraintCategory :: Assignment => write ! ( f, "assignment" ) ,
48
44
ConstraintCategory :: Return => write ! ( f, "return" ) ,
49
45
ConstraintCategory :: Cast => write ! ( f, "cast" ) ,
50
- ConstraintCategory :: CallArgument | ConstraintCategory :: CallArgumentToUpvar => {
51
- write ! ( f, "argument" )
52
- }
46
+ ConstraintCategory :: CallArgument => write ! ( f, "argument" ) ,
53
47
_ => write ! ( f, "free region" ) ,
54
48
}
55
49
}
@@ -224,10 +218,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
224
218
"constraint_is_interesting: locations={:?} constraint={:?}" ,
225
219
constraint. locations, constraint
226
220
) ;
227
- if let Locations :: Interesting ( _ ) = constraint . locations {
228
- true
229
- } else {
230
- false
221
+
222
+ match constraint . locations {
223
+ Locations :: Interesting ( _ ) | Locations :: All => true ,
224
+ _ => false ,
231
225
}
232
226
}
233
227
@@ -320,45 +314,25 @@ impl<'tcx> RegionInferenceContext<'tcx> {
320
314
}
321
315
}
322
316
323
- let category = match (
324
- category,
317
+ let ( fr_is_local, outlived_fr_is_local) : ( bool , bool ) = (
325
318
self . universal_regions . is_local_free_region ( fr) ,
326
319
self . universal_regions . is_local_free_region ( outlived_fr) ,
327
- ) {
328
- ( ConstraintCategory :: Assignment , true , false ) => ConstraintCategory :: AssignmentToUpvar ,
329
- ( ConstraintCategory :: CallArgument , true , false ) => {
330
- ConstraintCategory :: CallArgumentToUpvar
331
- }
332
- ( category, _, _) => category,
320
+ ) ;
321
+ debug ! ( "report_error: fr_is_local={:?} outlived_fr_is_local={:?} category={:?}" ,
322
+ fr_is_local, outlived_fr_is_local, category) ;
323
+
324
+ match ( fr_is_local, outlived_fr_is_local) {
325
+ ( true , false ) =>
326
+ self . report_escapes_closure_error ( mir, infcx, mir_def_id, fr, outlived_fr,
327
+ category, span, errors_buffer) ,
328
+ _ =>
329
+ self . report_general_error ( mir, infcx, mir_def_id, fr, fr_is_local,
330
+ outlived_fr, outlived_fr_is_local,
331
+ category, span, errors_buffer) ,
333
332
} ;
334
-
335
- debug ! ( "report_error: category={:?}" , category) ;
336
- match category {
337
- ConstraintCategory :: AssignmentToUpvar | ConstraintCategory :: CallArgumentToUpvar => self
338
- . report_closure_error (
339
- mir,
340
- infcx,
341
- mir_def_id,
342
- fr,
343
- outlived_fr,
344
- category,
345
- span,
346
- errors_buffer,
347
- ) ,
348
- _ => self . report_general_error (
349
- mir,
350
- infcx,
351
- mir_def_id,
352
- fr,
353
- outlived_fr,
354
- category,
355
- span,
356
- errors_buffer,
357
- ) ,
358
- }
359
333
}
360
334
361
- fn report_closure_error (
335
+ fn report_escapes_closure_error (
362
336
& self ,
363
337
mir : & Mir < ' tcx > ,
364
338
infcx : & InferCtxt < ' _ , ' _ , ' tcx > ,
@@ -374,16 +348,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
374
348
self . get_var_name_and_span_for_region ( infcx. tcx , mir, outlived_fr) ;
375
349
376
350
if fr_name_and_span. is_none ( ) && outlived_fr_name_and_span. is_none ( ) {
377
- return self . report_general_error (
378
- mir,
379
- infcx,
380
- mir_def_id,
381
- fr,
382
- outlived_fr,
383
- category,
384
- span,
385
- errors_buffer,
386
- ) ;
351
+ return self . report_general_error ( mir, infcx, mir_def_id,
352
+ fr, true , outlived_fr, false ,
353
+ category, span, errors_buffer) ;
387
354
}
388
355
389
356
let mut diag = infcx
@@ -423,7 +390,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
423
390
infcx : & InferCtxt < ' _ , ' _ , ' tcx > ,
424
391
mir_def_id : DefId ,
425
392
fr : RegionVid ,
393
+ fr_is_local : bool ,
426
394
outlived_fr : RegionVid ,
395
+ outlived_fr_is_local : bool ,
427
396
category : ConstraintCategory ,
428
397
span : Span ,
429
398
errors_buffer : & mut Vec < Diagnostic > ,
@@ -434,17 +403,26 @@ impl<'tcx> RegionInferenceContext<'tcx> {
434
403
) ;
435
404
436
405
let counter = & mut 1 ;
437
- let fr_name = self . give_region_a_name ( infcx. tcx , mir, mir_def_id, fr, counter, & mut diag) ;
438
- let outlived_fr_name =
439
- self . give_region_a_name ( infcx. tcx , mir, mir_def_id, outlived_fr, counter, & mut diag) ;
440
-
441
- diag. span_label (
442
- span,
443
- format ! (
444
- "{} requires that `{}` must outlive `{}`" ,
445
- category, fr_name, outlived_fr_name,
446
- ) ,
447
- ) ;
406
+ let fr_name = self . give_region_a_name (
407
+ infcx. tcx , mir, mir_def_id, fr, counter, & mut diag) ;
408
+ let outlived_fr_name = self . give_region_a_name (
409
+ infcx. tcx , mir, mir_def_id, outlived_fr, counter, & mut diag) ;
410
+
411
+ match ( category, outlived_fr_is_local, fr_is_local) {
412
+ ( ConstraintCategory :: Return , true , _) => {
413
+ diag. span_label ( span, format ! (
414
+ "closure was supposed to return data with lifetime `{}` but it is returning \
415
+ data with lifetime `{}`",
416
+ fr_name, outlived_fr_name,
417
+ ) ) ;
418
+ } ,
419
+ _ => {
420
+ diag. span_label ( span, format ! (
421
+ "{} requires that `{}` must outlive `{}`" ,
422
+ category, fr_name, outlived_fr_name,
423
+ ) ) ;
424
+ } ,
425
+ }
448
426
449
427
diag. buffer ( errors_buffer) ;
450
428
}
0 commit comments