@@ -28,6 +28,7 @@ use rustc_trait_selection::traits::{Obligation, ObligationCtxt};
2828use tracing:: { debug, instrument, trace} ;
2929
3030use super :: { LIMITATION_NOTE , OutlivesSuggestionBuilder , RegionName , RegionNameSource } ;
31+ use crate :: consumers:: RegionInferenceContext ;
3132use crate :: nll:: ConstraintDescription ;
3233use crate :: region_infer:: { BlameConstraint , TypeTest } ;
3334use crate :: session_diagnostics:: {
@@ -134,28 +135,28 @@ pub(crate) struct ErrorConstraintInfo<'tcx> {
134135 pub ( super ) span : Span ,
135136}
136137
137- impl < ' infcx , ' tcx > MirBorrowckCtxt < ' _ , ' infcx , ' tcx > {
138+ impl < ' tcx > RegionInferenceContext < ' tcx > {
138139 /// Converts a region inference variable into a `ty::Region` that
139140 /// we can use for error reporting. If `r` is universally bound,
140141 /// then we use the name that we have on record for it. If `r` is
141142 /// existentially bound, then we check its inferred value and try
142143 /// to find a good name from that. Returns `None` if we can't find
143144 /// one (e.g., this is just some random part of the CFG).
144145 pub ( super ) fn to_error_region ( & self , r : RegionVid ) -> Option < ty:: Region < ' tcx > > {
145- self . to_error_region_vid ( r) . and_then ( |r| self . regioncx . region_definition ( r) . external_name )
146+ self . to_error_region_vid ( r) . and_then ( |r| self . region_definition ( r) . external_name )
146147 }
147148
148149 /// Returns the `RegionVid` corresponding to the region returned by
149150 /// `to_error_region`.
150151 pub ( super ) fn to_error_region_vid ( & self , r : RegionVid ) -> Option < RegionVid > {
151- if self . regioncx . universal_regions ( ) . is_universal_region ( r) {
152+ if self . universal_regions ( ) . is_universal_region ( r) {
152153 Some ( r)
153154 } else {
154155 // We just want something nameable, even if it's not
155156 // actually an upper bound.
156- let upper_bound = self . regioncx . approx_universal_upper_bound ( r) ;
157+ let upper_bound = self . approx_universal_upper_bound ( r) ;
157158
158- if self . regioncx . upper_bound_in_region_scc ( r, upper_bound) {
159+ if self . upper_bound_in_region_scc ( r, upper_bound) {
159160 self . to_error_region_vid ( upper_bound)
160161 } else {
161162 None
@@ -179,14 +180,16 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
179180 if let Some ( r) = self . to_error_region ( fr)
180181 && let ty:: ReLateParam ( late_param) = r. kind ( )
181182 && let ty:: LateParamRegionKind :: ClosureEnv = late_param. kind
182- && let DefiningTy :: Closure ( _, args) = self . regioncx . universal_regions ( ) . defining_ty
183+ && let DefiningTy :: Closure ( _, args) = self . universal_regions ( ) . defining_ty
183184 {
184185 return args. as_closure ( ) . kind ( ) == ty:: ClosureKind :: FnMut ;
185186 }
186187
187188 false
188189 }
190+ }
189191
192+ impl < ' infcx , ' tcx > MirBorrowckCtxt < ' _ , ' infcx , ' tcx > {
190193 // For generic associated types (GATs) which implied 'static requirement
191194 // from higher-ranked trait bounds (HRTB). Try to locate span of the trait
192195 // and the span which bounded to the trait for adding 'static lifetime suggestion
@@ -309,12 +312,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
309312 RegionErrorKind :: TypeTestError { type_test } => {
310313 // Try to convert the lower-bound region into something named we can print for
311314 // the user.
312- let lower_bound_region = self . to_error_region ( type_test. lower_bound ) ;
315+ let lower_bound_region = self . regioncx . to_error_region ( type_test. lower_bound ) ;
313316
314317 let type_test_span = type_test. span ;
315318
316319 if let Some ( lower_bound_region) = lower_bound_region {
317- let generic_ty = self . name_regions (
320+ let generic_ty = self . regioncx . name_regions (
318321 self . infcx . tcx ,
319322 type_test. generic_kind . to_ty ( self . infcx . tcx ) ,
320323 ) ;
@@ -324,7 +327,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
324327 self . body . source . def_id ( ) . expect_local ( ) ,
325328 type_test_span,
326329 Some ( origin) ,
327- self . name_regions ( self . infcx . tcx , type_test. generic_kind ) ,
330+ self . regioncx . name_regions ( self . infcx . tcx , type_test. generic_kind ) ,
328331 lower_bound_region,
329332 ) ) ;
330333 } else {
@@ -450,7 +453,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
450453 debug ! ( "report_region_error: category={:?} {:?} {:?}" , category, cause, variance_info) ;
451454
452455 // Check if we can use one of the "nice region errors".
453- if let ( Some ( f) , Some ( o) ) = ( self . to_error_region ( fr) , self . to_error_region ( outlived_fr) ) {
456+ if let ( Some ( f) , Some ( o) ) =
457+ ( self . regioncx . to_error_region ( fr) , self . regioncx . to_error_region ( outlived_fr) )
458+ {
454459 let infer_err = self . infcx . err_ctxt ( ) ;
455460 let nice =
456461 NiceRegionError :: new_from_span ( & infer_err, self . mir_def_id ( ) , cause. span , o, f) ;
@@ -481,7 +486,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
481486 d. note ( "meoow :c" ) ;
482487 d
483488 }
484- ( ConstraintCategory :: Return ( kind) , true , false ) if self . is_closure_fn_mut ( fr) => {
489+ ( ConstraintCategory :: Return ( kind) , true , false )
490+ if self . regioncx . is_closure_fn_mut ( fr) =>
491+ {
485492 self . report_fnmut_error ( & errci, kind)
486493 }
487494 ( ConstraintCategory :: Assignment , true , false )
@@ -736,7 +743,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
736743 // Only show an extra note if we can find an 'error region' for both of the region
737744 // variables. This avoids showing a noisy note that just mentions 'synthetic' regions
738745 // that don't help the user understand the error.
739- match ( self . to_error_region ( errci. fr ) , self . to_error_region ( errci. outlived_fr ) ) {
746+ match (
747+ self . regioncx . to_error_region ( errci. fr ) ,
748+ self . regioncx . to_error_region ( errci. outlived_fr ) ,
749+ ) {
740750 ( Some ( f) , Some ( o) ) => {
741751 self . maybe_suggest_constrain_dyn_trait_impl ( & mut diag, f, o, category) ;
742752
@@ -842,7 +852,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
842852 outlived_fr : RegionVid ,
843853 ) {
844854 if let ( Some ( f) , Some ( outlived_f) ) =
845- ( self . to_error_region ( fr) , self . to_error_region ( outlived_fr) )
855+ ( self . regioncx . to_error_region ( fr) , self . regioncx . to_error_region ( outlived_fr) )
846856 {
847857 if outlived_f. kind ( ) != ty:: ReStatic {
848858 return ;
@@ -1013,7 +1023,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
10131023 }
10141024
10151025 fn suggest_adding_lifetime_params ( & self , diag : & mut Diag < ' _ > , sub : RegionVid , sup : RegionVid ) {
1016- let ( Some ( sub) , Some ( sup) ) = ( self . to_error_region ( sub) , self . to_error_region ( sup) ) else {
1026+ let ( Some ( sub) , Some ( sup) ) =
1027+ ( self . regioncx . to_error_region ( sub) , self . regioncx . to_error_region ( sup) )
1028+ else {
10171029 return ;
10181030 } ;
10191031
0 commit comments