@@ -14,7 +14,10 @@ use rustc_infer::infer::{NllRegionVariableOrigin, RelateParamBound};
1414use rustc_middle:: bug;
1515use rustc_middle:: hir:: place:: PlaceBase ;
1616use rustc_middle:: mir:: { AnnotationSource , ConstraintCategory , ReturnConstraint } ;
17- use rustc_middle:: ty:: { self , GenericArgs , Region , RegionVid , Ty , TyCtxt , TypeVisitor } ;
17+ use rustc_middle:: ty:: fold:: fold_regions;
18+ use rustc_middle:: ty:: {
19+ self , GenericArgs , Region , RegionVid , Ty , TyCtxt , TypeFoldable , TypeVisitor ,
20+ } ;
1821use rustc_span:: { Ident , Span , kw} ;
1922use rustc_trait_selection:: error_reporting:: InferCtxtErrorExt ;
2023use rustc_trait_selection:: error_reporting:: infer:: nice_region_error:: {
@@ -183,6 +186,17 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
183186 }
184187 }
185188
189+ /// Map the regions in the type to named regions, where possible.
190+ fn name_regions < T > ( & self , tcx : TyCtxt < ' tcx > , ty : T ) -> T
191+ where
192+ T : TypeFoldable < TyCtxt < ' tcx > > ,
193+ {
194+ fold_regions ( tcx, ty, |region, _| match * region {
195+ ty:: ReVar ( vid) => self . to_error_region ( vid) . unwrap_or ( region) ,
196+ _ => region,
197+ } )
198+ }
199+
186200 /// Returns `true` if a closure is inferred to be an `FnMut` closure.
187201 fn is_closure_fn_mut ( & self , fr : RegionVid ) -> bool {
188202 if let Some ( ty:: ReLateParam ( late_param) ) = self . to_error_region ( fr) . as_deref ( )
@@ -314,7 +328,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
314328 let type_test_span = type_test. span ;
315329
316330 if let Some ( lower_bound_region) = lower_bound_region {
317- let generic_ty = self . regioncx . name_regions (
331+ let generic_ty = self . name_regions (
318332 self . infcx . tcx ,
319333 type_test. generic_kind . to_ty ( self . infcx . tcx ) ,
320334 ) ;
@@ -323,7 +337,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
323337 self . body . source . def_id ( ) . expect_local ( ) ,
324338 type_test_span,
325339 Some ( origin) ,
326- self . regioncx . name_regions ( self . infcx . tcx , type_test. generic_kind ) ,
340+ self . name_regions ( self . infcx . tcx , type_test. generic_kind ) ,
327341 lower_bound_region,
328342 ) ) ;
329343 } else {
@@ -354,9 +368,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
354368 }
355369
356370 RegionErrorKind :: UnexpectedHiddenRegion { span, hidden_ty, key, member_region } => {
357- let named_ty = self . regioncx . name_regions ( self . infcx . tcx , hidden_ty) ;
358- let named_key = self . regioncx . name_regions ( self . infcx . tcx , key) ;
359- let named_region = self . regioncx . name_regions ( self . infcx . tcx , member_region) ;
371+ let named_ty =
372+ self . regioncx . name_regions_for_member_constraint ( self . infcx . tcx , hidden_ty) ;
373+ let named_key =
374+ self . regioncx . name_regions_for_member_constraint ( self . infcx . tcx , key) ;
375+ let named_region = self
376+ . regioncx
377+ . name_regions_for_member_constraint ( self . infcx . tcx , member_region) ;
360378 let diag = unexpected_hidden_region_diagnostic (
361379 self . infcx ,
362380 self . mir_def_id ( ) ,
0 commit comments