@@ -245,6 +245,11 @@ enum Trace<'tcx> {
245
245
NotVisited ,
246
246
}
247
247
248
+ #[ derive( Clone , PartialEq , Eq , Debug ) ]
249
+ pub enum ExtraConstraintInfo {
250
+ PlaceholderFromPredicate ( Span ) ,
251
+ }
252
+
248
253
impl < ' tcx > RegionInferenceContext < ' tcx > {
249
254
/// Creates a new region inference context with a total of
250
255
/// `num_region_variables` valid inference variables; the first N
@@ -1818,10 +1823,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1818
1823
fr1_origin : NllRegionVariableOrigin ,
1819
1824
fr2 : RegionVid ,
1820
1825
) -> ( 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 ;
1825
1829
( category, cause)
1826
1830
}
1827
1831
@@ -2010,7 +2014,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
2010
2014
from_region : RegionVid ,
2011
2015
from_region_origin : NllRegionVariableOrigin ,
2012
2016
target_test : impl Fn ( RegionVid ) -> bool ,
2013
- ) -> BlameConstraint < ' tcx > {
2017
+ ) -> ( BlameConstraint < ' tcx > , Vec < ExtraConstraintInfo > ) {
2014
2018
// Find all paths
2015
2019
let ( path, target_region) =
2016
2020
self . find_constraint_paths_between_regions ( from_region, target_test) . unwrap ( ) ;
@@ -2026,6 +2030,18 @@ impl<'tcx> RegionInferenceContext<'tcx> {
2026
2030
. collect:: <Vec <_>>( )
2027
2031
) ;
2028
2032
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
+
2029
2045
// We try to avoid reporting a `ConstraintCategory::Predicate` as our best constraint.
2030
2046
// Instead, we use it to produce an improved `ObligationCauseCode`.
2031
2047
// FIXME - determine what we should do if we encounter multiple `ConstraintCategory::Predicate`
@@ -2073,6 +2089,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
2073
2089
from_closure,
2074
2090
cause : ObligationCause :: new ( span, CRATE_HIR_ID , cause_code) ,
2075
2091
variance_info : constraint. variance_info ,
2092
+ outlives_constraint : * constraint,
2076
2093
}
2077
2094
} )
2078
2095
. collect ( ) ;
@@ -2174,7 +2191,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
2174
2191
let best_choice =
2175
2192
if blame_source { range. rev ( ) . find ( find_region) } else { range. find ( find_region) } ;
2176
2193
2177
- debug ! ( ?best_choice, ?blame_source) ;
2194
+ debug ! ( ?best_choice, ?blame_source, ?extra_info ) ;
2178
2195
2179
2196
if let Some ( i) = best_choice {
2180
2197
if let Some ( next) = categorized_path. get ( i + 1 ) {
@@ -2183,7 +2200,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
2183
2200
{
2184
2201
// The return expression is being influenced by the return type being
2185
2202
// impl Trait, point at the return type and not the return expr.
2186
- return next. clone ( ) ;
2203
+ return ( next. clone ( ) , extra_info ) ;
2187
2204
}
2188
2205
}
2189
2206
@@ -2203,7 +2220,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
2203
2220
}
2204
2221
}
2205
2222
2206
- return categorized_path[ i] . clone ( ) ;
2223
+ return ( categorized_path[ i] . clone ( ) , extra_info ) ;
2207
2224
}
2208
2225
2209
2226
// If that search fails, that is.. unusual. Maybe everything
@@ -2213,7 +2230,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
2213
2230
categorized_path. sort_by ( |p0, p1| p0. category . cmp ( & p1. category ) ) ;
2214
2231
debug ! ( "sorted_path={:#?}" , categorized_path) ;
2215
2232
2216
- categorized_path. remove ( 0 )
2233
+ ( categorized_path. remove ( 0 ) , extra_info )
2217
2234
}
2218
2235
2219
2236
pub ( crate ) fn universe_info ( & self , universe : ty:: UniverseIndex ) -> UniverseInfo < ' tcx > {
@@ -2295,7 +2312,13 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
2295
2312
outlives_requirement={:?}",
2296
2313
region, outlived_region, outlives_requirement,
2297
2314
) ;
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
+ )
2299
2322
}
2300
2323
2301
2324
ClosureOutlivesSubject :: Ty ( ty) => {
@@ -2305,7 +2328,10 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
2305
2328
outlives_requirement={:?}",
2306
2329
ty, outlived_region, outlives_requirement,
2307
2330
) ;
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
+ )
2309
2335
}
2310
2336
}
2311
2337
} )
@@ -2319,4 +2345,5 @@ pub struct BlameConstraint<'tcx> {
2319
2345
pub from_closure : bool ,
2320
2346
pub cause : ObligationCause < ' tcx > ,
2321
2347
pub variance_info : ty:: VarianceDiagInfo < ' tcx > ,
2348
+ pub outlives_constraint : OutlivesConstraint < ' tcx > ,
2322
2349
}
0 commit comments