@@ -245,6 +245,11 @@ enum Trace<'tcx> {
245245 NotVisited ,
246246}
247247
248+ #[ derive( Clone , PartialEq , Eq , Debug ) ]
249+ pub enum ExtraConstraintInfo {
250+ PlaceholderFromPredicate ( Span ) ,
251+ }
252+
248253impl < ' tcx > RegionInferenceContext < ' tcx > {
249254 /// Creates a new region inference context with a total of
250255 /// `num_region_variables` valid inference variables; the first N
@@ -1818,10 +1823,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
18181823 fr1_origin : NllRegionVariableOrigin ,
18191824 fr2 : RegionVid ,
18201825 ) -> ( ConstraintCategory < ' tcx > , ObligationCause < ' tcx > ) {
1821- let BlameConstraint { category, cause, .. } =
1822- self . best_blame_constraint ( fr1, fr1_origin, |r| {
1823- self . provides_universal_region ( r, fr1, fr2)
1824- } ) ;
1826+ let BlameConstraint { category, cause, .. } = self
1827+ . best_blame_constraint ( fr1, fr1_origin, |r| self . provides_universal_region ( r, fr1, fr2) )
1828+ . 0 ;
18251829 ( category, cause)
18261830 }
18271831
@@ -2010,7 +2014,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20102014 from_region : RegionVid ,
20112015 from_region_origin : NllRegionVariableOrigin ,
20122016 target_test : impl Fn ( RegionVid ) -> bool ,
2013- ) -> BlameConstraint < ' tcx > {
2017+ ) -> ( BlameConstraint < ' tcx > , Vec < ExtraConstraintInfo > ) {
20142018 // Find all paths
20152019 let ( path, target_region) =
20162020 self . find_constraint_paths_between_regions ( from_region, target_test) . unwrap ( ) ;
@@ -2026,6 +2030,18 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20262030 . collect:: <Vec <_>>( )
20272031 ) ;
20282032
2033+ let mut extra_info = vec ! [ ] ;
2034+ for constraint in path. iter ( ) {
2035+ let outlived = constraint. sub ;
2036+ let Some ( origin) = self . var_infos . get ( outlived) else { continue ; } ;
2037+ let RegionVariableOrigin :: Nll ( NllRegionVariableOrigin :: Placeholder ( p) ) = origin. origin else { continue ; } ;
2038+ debug ! ( ?constraint, ?p) ;
2039+ let ConstraintCategory :: Predicate ( span) = constraint. category else { continue ; } ;
2040+ extra_info. push ( ExtraConstraintInfo :: PlaceholderFromPredicate ( span) ) ;
2041+ // We only want to point to one
2042+ break ;
2043+ }
2044+
20292045 // We try to avoid reporting a `ConstraintCategory::Predicate` as our best constraint.
20302046 // Instead, we use it to produce an improved `ObligationCauseCode`.
20312047 // FIXME - determine what we should do if we encounter multiple `ConstraintCategory::Predicate`
@@ -2073,6 +2089,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20732089 from_closure,
20742090 cause : ObligationCause :: new ( span, CRATE_HIR_ID , cause_code) ,
20752091 variance_info : constraint. variance_info ,
2092+ outlives_constraint : * constraint,
20762093 }
20772094 } )
20782095 . collect ( ) ;
@@ -2174,7 +2191,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
21742191 let best_choice =
21752192 if blame_source { range. rev ( ) . find ( find_region) } else { range. find ( find_region) } ;
21762193
2177- debug ! ( ?best_choice, ?blame_source) ;
2194+ debug ! ( ?best_choice, ?blame_source, ?extra_info ) ;
21782195
21792196 if let Some ( i) = best_choice {
21802197 if let Some ( next) = categorized_path. get ( i + 1 ) {
@@ -2183,7 +2200,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
21832200 {
21842201 // The return expression is being influenced by the return type being
21852202 // impl Trait, point at the return type and not the return expr.
2186- return next. clone ( ) ;
2203+ return ( next. clone ( ) , extra_info ) ;
21872204 }
21882205 }
21892206
@@ -2203,7 +2220,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22032220 }
22042221 }
22052222
2206- return categorized_path[ i] . clone ( ) ;
2223+ return ( categorized_path[ i] . clone ( ) , extra_info ) ;
22072224 }
22082225
22092226 // If that search fails, that is.. unusual. Maybe everything
@@ -2213,7 +2230,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22132230 categorized_path. sort_by ( |p0, p1| p0. category . cmp ( & p1. category ) ) ;
22142231 debug ! ( "sorted_path={:#?}" , categorized_path) ;
22152232
2216- categorized_path. remove ( 0 )
2233+ ( categorized_path. remove ( 0 ) , extra_info )
22172234 }
22182235
22192236 pub ( crate ) fn universe_info ( & self , universe : ty:: UniverseIndex ) -> UniverseInfo < ' tcx > {
@@ -2295,7 +2312,13 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
22952312 outlives_requirement={:?}",
22962313 region, outlived_region, outlives_requirement,
22972314 ) ;
2298- ty:: Binder :: dummy ( ty:: OutlivesPredicate ( region. into ( ) , outlived_region) )
2315+ (
2316+ ty:: Binder :: dummy ( ty:: OutlivesPredicate (
2317+ region. into ( ) ,
2318+ outlived_region,
2319+ ) ) ,
2320+ ConstraintCategory :: BoringNoLocation ,
2321+ )
22992322 }
23002323
23012324 ClosureOutlivesSubject :: Ty ( ty) => {
@@ -2305,7 +2328,10 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
23052328 outlives_requirement={:?}",
23062329 ty, outlived_region, outlives_requirement,
23072330 ) ;
2308- ty:: Binder :: dummy ( ty:: OutlivesPredicate ( ty. into ( ) , outlived_region) )
2331+ (
2332+ ty:: Binder :: dummy ( ty:: OutlivesPredicate ( ty. into ( ) , outlived_region) ) ,
2333+ ConstraintCategory :: BoringNoLocation ,
2334+ )
23092335 }
23102336 }
23112337 } )
@@ -2319,4 +2345,5 @@ pub struct BlameConstraint<'tcx> {
23192345 pub from_closure : bool ,
23202346 pub cause : ObligationCause < ' tcx > ,
23212347 pub variance_info : ty:: VarianceDiagInfo < ' tcx > ,
2348+ pub outlives_constraint : OutlivesConstraint < ' tcx > ,
23222349}
0 commit comments