@@ -14,7 +14,10 @@ use rustc_infer::infer::{NllRegionVariableOrigin, RelateParamBound};
14
14
use rustc_middle:: bug;
15
15
use rustc_middle:: hir:: place:: PlaceBase ;
16
16
use 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
+ } ;
18
21
use rustc_span:: { Ident , Span , kw} ;
19
22
use rustc_trait_selection:: error_reporting:: InferCtxtErrorExt ;
20
23
use rustc_trait_selection:: error_reporting:: infer:: nice_region_error:: {
@@ -183,6 +186,17 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
183
186
}
184
187
}
185
188
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
+
186
200
/// Returns `true` if a closure is inferred to be an `FnMut` closure.
187
201
fn is_closure_fn_mut ( & self , fr : RegionVid ) -> bool {
188
202
if let Some ( ty:: ReLateParam ( late_param) ) = self . to_error_region ( fr) . as_deref ( )
@@ -314,7 +328,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
314
328
let type_test_span = type_test. span ;
315
329
316
330
if let Some ( lower_bound_region) = lower_bound_region {
317
- let generic_ty = self . regioncx . name_regions (
331
+ let generic_ty = self . name_regions (
318
332
self . infcx . tcx ,
319
333
type_test. generic_kind . to_ty ( self . infcx . tcx ) ,
320
334
) ;
@@ -323,7 +337,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
323
337
self . body . source . def_id ( ) . expect_local ( ) ,
324
338
type_test_span,
325
339
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 ) ,
327
341
lower_bound_region,
328
342
) ) ;
329
343
} else {
@@ -354,9 +368,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
354
368
}
355
369
356
370
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) ;
360
378
let diag = unexpected_hidden_region_diagnostic (
361
379
self . infcx ,
362
380
self . mir_def_id ( ) ,
0 commit comments