@@ -147,9 +147,7 @@ pub(crate) enum RegionErrorKind<'tcx> {
147147pub ( crate ) struct ErrorConstraintInfo < ' tcx > {
148148 // fr: outlived_fr
149149 pub ( super ) fr : RegionVid ,
150- pub ( super ) fr_is_local : bool ,
151150 pub ( super ) outlived_fr : RegionVid ,
152- pub ( super ) outlived_fr_is_local : bool ,
153151
154152 // Category and span for best blame constraint
155153 pub ( super ) category : ConstraintCategory < ' tcx > ,
@@ -316,13 +314,16 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
316314 let type_test_span = type_test. span ;
317315
318316 if let Some ( lower_bound_region) = lower_bound_region {
319- let generic_ty = type_test. generic_kind . to_ty ( self . infcx . tcx ) ;
317+ let generic_ty = self . regioncx . name_regions (
318+ self . infcx . tcx ,
319+ type_test. generic_kind . to_ty ( self . infcx . tcx ) ,
320+ ) ;
320321 let origin = RelateParamBound ( type_test_span, generic_ty, None ) ;
321322 self . buffer_error ( self . infcx . err_ctxt ( ) . construct_generic_bound_failure (
322323 self . body . source . def_id ( ) . expect_local ( ) ,
323324 type_test_span,
324325 Some ( origin) ,
325- type_test. generic_kind ,
326+ self . regioncx . name_regions ( self . infcx . tcx , type_test. generic_kind ) ,
326327 lower_bound_region,
327328 ) ) ;
328329 } else {
@@ -468,14 +469,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
468469 fr_is_local, outlived_fr_is_local, category
469470 ) ;
470471
471- let errci = ErrorConstraintInfo {
472- fr,
473- outlived_fr,
474- fr_is_local,
475- outlived_fr_is_local,
476- category,
477- span : cause. span ,
478- } ;
472+ let errci = ErrorConstraintInfo { fr, outlived_fr, category, span : cause. span } ;
479473
480474 let mut diag = match ( category, fr_is_local, outlived_fr_is_local) {
481475 ( ConstraintCategory :: Return ( kind) , true , false ) if self . is_closure_fn_mut ( fr) => {
@@ -677,11 +671,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
677671 && self . regioncx . universal_regions ( ) . defining_ty . is_fn_def ( ) )
678672 || self . regioncx . universal_regions ( ) . defining_ty . is_const ( )
679673 {
680- return self . report_general_error ( & ErrorConstraintInfo {
681- fr_is_local : true ,
682- outlived_fr_is_local : false ,
683- ..* errci
684- } ) ;
674+ return self . report_general_error ( errci) ;
685675 }
686676
687677 let mut diag =
@@ -759,15 +749,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
759749 /// ```
760750 #[ allow( rustc:: diagnostic_outside_of_impl) ] // FIXME
761751 fn report_general_error ( & self , errci : & ErrorConstraintInfo < ' tcx > ) -> Diag < ' infcx > {
762- let ErrorConstraintInfo {
763- fr,
764- fr_is_local,
765- outlived_fr,
766- outlived_fr_is_local,
767- span,
768- category,
769- ..
770- } = errci;
752+ let ErrorConstraintInfo { fr, outlived_fr, span, category, .. } = errci;
771753
772754 let mir_def_name = self . infcx . tcx . def_descr ( self . mir_def_id ( ) . to_def_id ( ) ) ;
773755
@@ -786,19 +768,22 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
786768 let outlived_fr_name = self . give_region_a_name ( * outlived_fr) . unwrap ( ) ;
787769 outlived_fr_name. highlight_region_name ( & mut diag) ;
788770
789- let err_category = match ( category, outlived_fr_is_local, fr_is_local) {
790- ( 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 {
791775 span : * span,
792776 mir_def_name,
793777 outlived_fr_name,
794778 fr_name : & fr_name,
795- } ,
796- _ => LifetimeReturnCategoryErr :: ShortReturn {
779+ }
780+ } else {
781+ LifetimeReturnCategoryErr :: ShortReturn {
797782 span : * span,
798783 category_desc : category. description ( ) ,
799784 free_region_name : & fr_name,
800785 outlived_fr_name,
801- } ,
786+ }
802787 } ;
803788
804789 diag. subdiagnostic ( err_category) ;
0 commit comments