Skip to content

Commit f1767db

Browse files
committed
Add ExtraConstraintInfo
1 parent 9929c0a commit f1767db

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::ty::{self, RegionVid, TyCtxt};
1515
use rustc_span::symbol::{kw, Symbol};
1616
use rustc_span::{sym, DesugaringKind, Span};
1717

18-
use crate::region_infer::BlameConstraint;
18+
use crate::region_infer::{BlameConstraint, ExtraConstraintInfo};
1919
use crate::{
2020
borrow_set::BorrowData, nll::ConstraintDescription, region_infer::Cause, MirBorrowckCtxt,
2121
WriteKind,
@@ -38,6 +38,7 @@ pub(crate) enum BorrowExplanation<'tcx> {
3838
span: Span,
3939
region_name: RegionName,
4040
opt_place_desc: Option<String>,
41+
extra_info: Vec<ExtraConstraintInfo>,
4142
},
4243
Unexplained,
4344
}
@@ -243,6 +244,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
243244
ref region_name,
244245
ref opt_place_desc,
245246
from_closure: _,
247+
ref extra_info,
246248
} => {
247249
region_name.highlight_region_name(err);
248250

@@ -268,6 +270,11 @@ impl<'tcx> BorrowExplanation<'tcx> {
268270
);
269271
};
270272

273+
for extra in extra_info {
274+
match extra {
275+
_ => {}
276+
}
277+
}
271278
self.add_lifetime_bound_suggestion_to_diagnostic(err, &category, span, region_name);
272279
}
273280
_ => {}
@@ -309,8 +316,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
309316
&self,
310317
borrow_region: RegionVid,
311318
outlived_region: RegionVid,
312-
) -> (ConstraintCategory<'tcx>, bool, Span, Option<RegionName>) {
313-
let blame_constraint = self.regioncx.best_blame_constraint(
319+
) -> (ConstraintCategory<'tcx>, bool, Span, Option<RegionName>, Vec<ExtraConstraintInfo>) {
320+
let (blame_constraint, extra_info) = self.regioncx.best_blame_constraint(
314321
borrow_region,
315322
NllRegionVariableOrigin::FreeRegion,
316323
|r| self.regioncx.provides_universal_region(r, borrow_region, outlived_region),
@@ -319,7 +326,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
319326

320327
let outlived_fr_name = self.give_region_a_name(outlived_region);
321328

322-
(category, from_closure, cause.span, outlived_fr_name)
329+
(category, from_closure, cause.span, outlived_fr_name, extra_info)
323330
}
324331

325332
/// Returns structured explanation for *why* the borrow contains the
@@ -391,7 +398,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
391398

392399
None => {
393400
if let Some(region) = self.to_error_region_vid(borrow_region_vid) {
394-
let (category, from_closure, span, region_name) =
401+
let (category, from_closure, span, region_name, extra_info) =
395402
self.free_region_constraint_info(borrow_region_vid, region);
396403
if let Some(region_name) = region_name {
397404
let opt_place_desc = self.describe_place(borrow.borrowed_place.as_ref());
@@ -401,6 +408,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
401408
span,
402409
region_name,
403410
opt_place_desc,
411+
extra_info,
404412
}
405413
} else {
406414
debug!("Could not generate a region name");

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
354354
) {
355355
debug!("report_region_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr);
356356

357-
let BlameConstraint { category, cause, variance_info, .. } =
358-
self.regioncx.best_blame_constraint(fr, fr_origin, |r| {
357+
let BlameConstraint { category, cause, variance_info, .. } = self
358+
.regioncx
359+
.best_blame_constraint(fr, fr_origin, |r| {
359360
self.regioncx.provides_universal_region(r, fr, outlived_fr)
360-
});
361+
})
362+
.0;
361363

362364
debug!("report_region_error: category={:?} {:?} {:?}", category, cause, variance_info);
363365

compiler/rustc_borrowck/src/region_infer/mod.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ enum Trace<'tcx> {
245245
NotVisited,
246246
}
247247

248+
#[derive(Clone, PartialEq, Eq, Debug)]
249+
pub enum ExtraConstraintInfo {}
250+
248251
impl<'tcx> RegionInferenceContext<'tcx> {
249252
/// Creates a new region inference context with a total of
250253
/// `num_region_variables` valid inference variables; the first N
@@ -1818,10 +1821,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
18181821
fr1_origin: NllRegionVariableOrigin,
18191822
fr2: RegionVid,
18201823
) -> (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-
});
1824+
let BlameConstraint { category, cause, .. } = self
1825+
.best_blame_constraint(fr1, fr1_origin, |r| self.provides_universal_region(r, fr1, fr2))
1826+
.0;
18251827
(category, cause)
18261828
}
18271829

@@ -2010,7 +2012,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20102012
from_region: RegionVid,
20112013
from_region_origin: NllRegionVariableOrigin,
20122014
target_test: impl Fn(RegionVid) -> bool,
2013-
) -> BlameConstraint<'tcx> {
2015+
) -> (BlameConstraint<'tcx>, Vec<ExtraConstraintInfo>) {
20142016
// Find all paths
20152017
let (path, target_region) =
20162018
self.find_constraint_paths_between_regions(from_region, target_test).unwrap();
@@ -2026,6 +2028,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20262028
.collect::<Vec<_>>()
20272029
);
20282030

2031+
let extra_info = vec![];
2032+
20292033
// We try to avoid reporting a `ConstraintCategory::Predicate` as our best constraint.
20302034
// Instead, we use it to produce an improved `ObligationCauseCode`.
20312035
// FIXME - determine what we should do if we encounter multiple `ConstraintCategory::Predicate`
@@ -2175,7 +2179,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
21752179
let best_choice =
21762180
if blame_source { range.rev().find(find_region) } else { range.find(find_region) };
21772181

2178-
debug!(?best_choice, ?blame_source);
2182+
debug!(?best_choice, ?blame_source, ?extra_info);
21792183

21802184
if let Some(i) = best_choice {
21812185
if let Some(next) = categorized_path.get(i + 1) {
@@ -2184,7 +2188,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
21842188
{
21852189
// The return expression is being influenced by the return type being
21862190
// impl Trait, point at the return type and not the return expr.
2187-
return next.clone();
2191+
return (next.clone(), extra_info);
21882192
}
21892193
}
21902194

@@ -2204,7 +2208,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22042208
}
22052209
}
22062210

2207-
return categorized_path[i].clone();
2211+
return (categorized_path[i].clone(), extra_info);
22082212
}
22092213

22102214
// If that search fails, that is.. unusual. Maybe everything
@@ -2214,7 +2218,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22142218
categorized_path.sort_by(|p0, p1| p0.category.cmp(&p1.category));
22152219
debug!("sorted_path={:#?}", categorized_path);
22162220

2217-
categorized_path.remove(0)
2221+
(categorized_path.remove(0), extra_info)
22182222
}
22192223

22202224
pub(crate) fn universe_info(&self, universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {

0 commit comments

Comments
 (0)