@@ -29,7 +29,6 @@ use tracing::{debug, instrument, trace};
2929
3030use super :: { LIMITATION_NOTE , OutlivesSuggestionBuilder , RegionName , RegionNameSource } ;
3131use crate :: nll:: ConstraintDescription ;
32- use crate :: region_infer:: values:: RegionElement ;
3332use crate :: region_infer:: { BlameConstraint , TypeTest } ;
3433use crate :: session_diagnostics:: {
3534 FnMutError , FnMutReturnTypeErr , GenericDoesNotLiveLongEnough , LifetimeOutliveErr ,
@@ -104,15 +103,9 @@ pub(crate) enum RegionErrorKind<'tcx> {
104103 /// A generic bound failure for a type test (`T: 'a`).
105104 TypeTestError { type_test : TypeTest < ' tcx > } ,
106105
107- /// Higher-ranked subtyping error.
108- BoundUniversalRegionError {
109- /// The placeholder free region.
110- longer_fr : RegionVid ,
111- /// The region element that erroneously must be outlived by `longer_fr`.
112- error_element : RegionElement < ' tcx > ,
113- /// The placeholder region.
114- placeholder : ty:: PlaceholderRegion < ' tcx > ,
115- } ,
106+ /// 'p outlives 'r, which does not hold. 'p is always a placeholder
107+ /// and 'r is some other region.
108+ PlaceholderOutlivesIllegalRegion { longer_fr : RegionVid , illegally_outlived_r : RegionVid } ,
116109
117110 /// Any other lifetime error.
118111 RegionError {
@@ -360,28 +353,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
360353 }
361354 }
362355
363- RegionErrorKind :: BoundUniversalRegionError {
356+ RegionErrorKind :: PlaceholderOutlivesIllegalRegion {
364357 longer_fr,
365- placeholder,
366- error_element,
358+ illegally_outlived_r,
367359 } => {
368- let error_vid = self . regioncx . region_from_element ( longer_fr, & error_element) ;
369-
370- // Find the code to blame for the fact that `longer_fr` outlives `error_fr`.
371- let cause = self
372- . regioncx
373- . best_blame_constraint (
374- longer_fr,
375- NllRegionVariableOrigin :: Placeholder ( placeholder) ,
376- error_vid,
377- )
378- . 0
379- . cause ;
380-
381- let universe = placeholder. universe ;
382- let universe_info = self . regioncx . universe_info ( universe) ;
383-
384- universe_info. report_erroneous_element ( self , placeholder, error_element, cause) ;
360+ self . report_erroneous_rvid_reaches_placeholder ( longer_fr, illegally_outlived_r)
385361 }
386362
387363 RegionErrorKind :: RegionError { fr_origin, longer_fr, shorter_fr, is_reported } => {
@@ -412,6 +388,43 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
412388 outlives_suggestion. add_suggestion ( self ) ;
413389 }
414390
391+ /// Report that `longer_fr: error_vid`, which doesn't hold,
392+ /// where `longer_fr` is a placeholder.
393+ fn report_erroneous_rvid_reaches_placeholder (
394+ & mut self ,
395+ longer_fr : RegionVid ,
396+ error_vid : RegionVid ,
397+ ) {
398+ use NllRegionVariableOrigin :: * ;
399+
400+ let origin_longer = self . regioncx . definitions [ longer_fr] . origin ;
401+
402+ let Placeholder ( placeholder) = origin_longer else {
403+ bug ! ( "Expected {longer_fr:?} to come from placeholder!" ) ;
404+ } ;
405+
406+ // FIXME: Is throwing away the existential region really the best here?
407+ let error_region = match self . regioncx . definitions [ error_vid] . origin {
408+ FreeRegion | Existential { .. } => None ,
409+ Placeholder ( other_placeholder) => Some ( other_placeholder) ,
410+ } ;
411+
412+ // Find the code to blame for the fact that `longer_fr` outlives `error_fr`.
413+ let cause =
414+ self . regioncx . best_blame_constraint ( longer_fr, origin_longer, error_vid) . 0 . cause ;
415+
416+ // FIXME these methods should have better names, and also probably not be this generic.
417+ // FIXME note that we *throw away* the error element here! We probably want to
418+ // thread it through the computation further down and use it, but there currently isn't
419+ // anything there to receive it.
420+ self . regioncx . universe_info ( placeholder. universe ) . report_erroneous_element (
421+ self ,
422+ placeholder,
423+ error_region,
424+ cause,
425+ ) ;
426+ }
427+
415428 /// Report an error because the universal region `fr` was required to outlive
416429 /// `outlived_fr` but it is not known to do so. For example:
417430 ///
@@ -872,6 +885,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
872885 for alias_ty in alias_tys {
873886 if alias_ty. span . desugaring_kind ( ) . is_some ( ) {
874887 // Skip `async` desugaring `impl Future`.
888+ continue ;
875889 }
876890 if let TyKind :: TraitObject ( _, lt) = alias_ty. kind {
877891 if lt. kind == hir:: LifetimeKind :: ImplicitObjectLifetimeDefault {
0 commit comments