@@ -147,9 +147,7 @@ pub(crate) enum RegionErrorKind<'tcx> {
147
147
pub ( crate ) struct ErrorConstraintInfo < ' tcx > {
148
148
// fr: outlived_fr
149
149
pub ( super ) fr : RegionVid ,
150
- pub ( super ) fr_is_local : bool ,
151
150
pub ( super ) outlived_fr : RegionVid ,
152
- pub ( super ) outlived_fr_is_local : bool ,
153
151
154
152
// Category and span for best blame constraint
155
153
pub ( super ) category : ConstraintCategory < ' tcx > ,
@@ -471,14 +469,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
471
469
fr_is_local, outlived_fr_is_local, category
472
470
) ;
473
471
474
- let errci = ErrorConstraintInfo {
475
- fr,
476
- outlived_fr,
477
- fr_is_local,
478
- outlived_fr_is_local,
479
- category,
480
- span : cause. span ,
481
- } ;
472
+ let errci = ErrorConstraintInfo { fr, outlived_fr, category, span : cause. span } ;
482
473
483
474
let mut diag = match ( category, fr_is_local, outlived_fr_is_local) {
484
475
( ConstraintCategory :: Return ( kind) , true , false ) if self . is_closure_fn_mut ( fr) => {
@@ -680,11 +671,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
680
671
&& self . regioncx . universal_regions ( ) . defining_ty . is_fn_def ( ) )
681
672
|| self . regioncx . universal_regions ( ) . defining_ty . is_const ( )
682
673
{
683
- return self . report_general_error ( & ErrorConstraintInfo {
684
- fr_is_local : true ,
685
- outlived_fr_is_local : false ,
686
- ..* errci
687
- } ) ;
674
+ return self . report_general_error ( errci) ;
688
675
}
689
676
690
677
let mut diag =
@@ -762,15 +749,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
762
749
/// ```
763
750
#[ allow( rustc:: diagnostic_outside_of_impl) ] // FIXME
764
751
fn report_general_error ( & self , errci : & ErrorConstraintInfo < ' tcx > ) -> Diag < ' infcx > {
765
- let ErrorConstraintInfo {
766
- fr,
767
- fr_is_local,
768
- outlived_fr,
769
- outlived_fr_is_local,
770
- span,
771
- category,
772
- ..
773
- } = errci;
752
+ let ErrorConstraintInfo { fr, outlived_fr, span, category, .. } = errci;
774
753
775
754
let mir_def_name = self . infcx . tcx . def_descr ( self . mir_def_id ( ) . to_def_id ( ) ) ;
776
755
@@ -789,19 +768,22 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
789
768
let outlived_fr_name = self . give_region_a_name ( * outlived_fr) . unwrap ( ) ;
790
769
outlived_fr_name. highlight_region_name ( & mut diag) ;
791
770
792
- let err_category = match ( category, outlived_fr_is_local, fr_is_local) {
793
- ( ConstraintCategory :: Return ( _) , true , _) => LifetimeReturnCategoryErr :: WrongReturn {
771
+ let err_category = if matches ! ( category, ConstraintCategory :: Return ( _) )
772
+ && self . regioncx . universal_regions ( ) . is_local_free_region ( * outlived_fr)
773
+ {
774
+ LifetimeReturnCategoryErr :: WrongReturn {
794
775
span : * span,
795
776
mir_def_name,
796
777
outlived_fr_name,
797
778
fr_name : & fr_name,
798
- } ,
799
- _ => LifetimeReturnCategoryErr :: ShortReturn {
779
+ }
780
+ } else {
781
+ LifetimeReturnCategoryErr :: ShortReturn {
800
782
span : * span,
801
783
category_desc : category. description ( ) ,
802
784
free_region_name : & fr_name,
803
785
outlived_fr_name,
804
- } ,
786
+ }
805
787
} ;
806
788
807
789
diag. subdiagnostic ( err_category) ;
0 commit comments