Skip to content

Commit 0b62018

Browse files
nikomatsakisdavidtwco
authored andcommitted
propagate boring vs interesting causal info for constraints/tests
1 parent 609bb27 commit 0b62018

File tree

7 files changed

+70
-72
lines changed

7 files changed

+70
-72
lines changed

src/librustc_mir/borrow_check/nll/constraint_generation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010

1111
use borrow_check::borrow_set::BorrowSet;
1212
use borrow_check::location::LocationTable;
13+
use borrow_check::nll::ToRegionVid;
1314
use borrow_check::nll::facts::AllFacts;
1415
use borrow_check::nll::region_infer::{Cause, RegionInferenceContext};
15-
use borrow_check::nll::ToRegionVid;
16+
use borrow_check::nll::type_check::AtLocation;
1617
use rustc::hir;
1718
use rustc::infer::InferCtxt;
1819
use rustc::mir::visit::TyContext;
@@ -310,9 +311,8 @@ impl<'cx, 'cg, 'gcx, 'tcx> ConstraintGeneration<'cx, 'cg, 'gcx, 'tcx> {
310311
debug!("add_reborrow_constraint - base_ty = {:?}", base_ty);
311312
match base_ty.sty {
312313
ty::TyRef(ref_region, _, mutbl) => {
313-
let span = self.mir.source_info(location).span;
314314
self.regioncx.add_outlives(
315-
span,
315+
location.boring(),
316316
ref_region.to_region_vid(),
317317
borrow_region.to_region_vid(),
318318
);

src/librustc_mir/borrow_check/nll/constraint_set.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
use rustc::ty::RegionVid;
1212
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
13+
use borrow_check::nll::type_check::Locations;
1314

1415
use std::fmt;
15-
use syntax_pos::Span;
1616
use std::ops::Deref;
1717

1818
#[derive(Clone, Default)]
@@ -23,8 +23,8 @@ crate struct ConstraintSet {
2323
impl ConstraintSet {
2424
pub fn push(&mut self, constraint: OutlivesConstraint) {
2525
debug!(
26-
"add_outlives({:?}: {:?})",
27-
constraint.sup, constraint.sub
26+
"add_outlives({:?}: {:?} @ {:?})",
27+
constraint.sup, constraint.sub, constraint.locations
2828
);
2929
if constraint.sup == constraint.sub {
3030
// 'a: 'a is pretty uninteresting
@@ -96,15 +96,15 @@ pub struct OutlivesConstraint {
9696
pub next: Option<ConstraintIndex>,
9797

9898
/// Where did this constraint arise?
99-
pub span: Span,
99+
pub locations: Locations,
100100
}
101101

102102
impl fmt::Debug for OutlivesConstraint {
103103
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
104104
write!(
105105
formatter,
106106
"({:?}: {:?}) due to {:?}",
107-
self.sup, self.sub, self.span
107+
self.sup, self.sub, self.locations
108108
)
109109
}
110110
}

src/librustc_mir/borrow_check/nll/region_infer/dump_mir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
8282
let OutlivesConstraint {
8383
sup,
8484
sub,
85-
span,
85+
locations,
8686
next: _,
8787
} = constraint;
8888
with_msg(&format!(
8989
"{:?}: {:?} due to {:?}",
9090
sup,
9191
sub,
92-
span
92+
locations,
9393
))?;
9494
}
9595

src/librustc_mir/borrow_check/nll/region_infer/graphviz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl<'this, 'tcx> dot::Labeller<'this> for RegionInferenceContext<'tcx> {
4444
dot::LabelText::LabelStr(format!("{:?}", n).into_cow())
4545
}
4646
fn edge_label(&'this self, e: &OutlivesConstraint) -> dot::LabelText<'this> {
47-
dot::LabelText::LabelStr(format!("{:?}", e.span).into_cow())
47+
dot::LabelText::LabelStr(format!("{:?}", e.locations).into_cow())
4848
}
4949
}
5050

src/librustc_mir/borrow_check/nll/region_infer/mod.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use super::universal_regions::UniversalRegions;
1212
use borrow_check::nll::region_infer::values::ToElementIndex;
1313
use borrow_check::nll::constraint_set::{ConstraintIndex, ConstraintSet, OutlivesConstraint};
14+
use borrow_check::nll::type_check::Locations;
1415
use rustc::hir::def_id::DefId;
1516
use rustc::infer::canonical::QueryRegionConstraint;
1617
use rustc::infer::error_reporting::nice_region_error::NiceRegionError;
@@ -154,11 +155,8 @@ pub struct TypeTest<'tcx> {
154155
/// The region `'x` that the type must outlive.
155156
pub lower_bound: RegionVid,
156157

157-
/// The point where the outlives relation must hold.
158-
pub point: Location,
159-
160-
/// Where did this constraint arise?
161-
pub span: Span,
158+
/// Where did this constraint arise and why?
159+
pub locations: Locations,
162160

163161
/// A test which, if met by the region `'x`, proves that this type
164162
/// constraint is satisfied.
@@ -356,13 +354,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
356354
/// Indicates that the region variable `sup` must outlive `sub` is live at the point `point`.
357355
pub(super) fn add_outlives(
358356
&mut self,
359-
span: Span,
357+
locations: Locations,
360358
sup: RegionVid,
361359
sub: RegionVid,
362360
) {
363361
assert!(self.inferred_values.is_none(), "values already inferred");
364362
self.constraints.push(OutlivesConstraint {
365-
span,
363+
locations,
366364
sup,
367365
sub,
368366
next: None,
@@ -408,7 +406,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
408406

409407
self.check_type_tests(infcx, mir, mir_def_id, outlives_requirements.as_mut());
410408

411-
self.check_universal_regions(infcx, mir_def_id, outlives_requirements.as_mut());
409+
self.check_universal_regions(infcx, mir, mir_def_id, outlives_requirements.as_mut());
412410

413411
let outlives_requirements = outlives_requirements.unwrap_or(vec![]);
414412

@@ -506,7 +504,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
506504
}
507505

508506
if let Some(propagated_outlives_requirements) = &mut propagated_outlives_requirements {
509-
if self.try_promote_type_test(infcx, type_test, propagated_outlives_requirements) {
507+
if self.try_promote_type_test(infcx, mir, type_test, propagated_outlives_requirements) {
510508
continue;
511509
}
512510
}
@@ -515,9 +513,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
515513
let lower_bound_region = self.to_error_region(type_test.lower_bound);
516514
if let Some(lower_bound_region) = lower_bound_region {
517515
let region_scope_tree = &tcx.region_scope_tree(mir_def_id);
516+
let type_test_span = type_test.locations.span(mir);
518517
infcx.report_generic_bound_failure(
519518
region_scope_tree,
520-
type_test.span,
519+
type_test_span,
521520
None,
522521
type_test.generic_kind,
523522
lower_bound_region,
@@ -532,8 +531,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
532531
// to report it; we could probably handle it by
533532
// iterating over the universal regions and reporting
534533
// an error that multiple bounds are required.
534+
let type_test_span = type_test.locations.span(mir);
535535
tcx.sess.span_err(
536-
type_test.span,
536+
type_test_span,
537537
&format!("`{}` does not live long enough", type_test.generic_kind,),
538538
);
539539
}
@@ -566,6 +566,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
566566
fn try_promote_type_test<'gcx>(
567567
&self,
568568
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
569+
mir: &Mir<'tcx>,
569570
type_test: &TypeTest<'tcx>,
570571
propagated_outlives_requirements: &mut Vec<ClosureOutlivesRequirement<'gcx>>,
571572
) -> bool {
@@ -574,8 +575,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
574575
let TypeTest {
575576
generic_kind,
576577
lower_bound,
577-
point: _,
578-
span,
578+
locations,
579579
test: _,
580580
} = type_test;
581581

@@ -599,7 +599,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
599599
propagated_outlives_requirements.push(ClosureOutlivesRequirement {
600600
subject,
601601
outlived_free_region: lower_bound_plus,
602-
blame_span: *span,
602+
blame_span: locations.span(mir),
603603
});
604604
true
605605
}
@@ -865,6 +865,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
865865
fn check_universal_regions<'gcx>(
866866
&self,
867867
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
868+
mir: &Mir<'tcx>,
868869
mir_def_id: DefId,
869870
mut propagated_outlives_requirements: Option<&mut Vec<ClosureOutlivesRequirement<'gcx>>>,
870871
) {
@@ -881,6 +882,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
881882
for (fr, _) in universal_definitions {
882883
self.check_universal_region(
883884
infcx,
885+
mir,
884886
mir_def_id,
885887
fr,
886888
&mut propagated_outlives_requirements,
@@ -899,6 +901,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
899901
fn check_universal_region<'gcx>(
900902
&self,
901903
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
904+
mir: &Mir<'tcx>,
902905
mir_def_id: DefId,
903906
longer_fr: RegionVid,
904907
propagated_outlives_requirements: &mut Option<&mut Vec<ClosureOutlivesRequirement<'gcx>>>,
@@ -921,7 +924,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
921924
);
922925

923926
let blame_index = self.blame_constraint(longer_fr, shorter_fr);
924-
let blame_span = self.constraints[blame_index].span;
927+
let blame_span = self.constraints[blame_index].locations.span(mir);
925928

926929
if let Some(propagated_outlives_requirements) = propagated_outlives_requirements {
927930
// Shrink `fr` until we find a non-local region (if we do).

src/librustc_mir/borrow_check/nll/type_check/constraint_conversion.rs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ use rustc::infer::canonical::QueryRegionConstraint;
1919
use rustc::infer::outlives::obligations::{TypeOutlives, TypeOutlivesDelegate};
2020
use rustc::infer::region_constraints::{GenericKind, VerifyBound};
2121
use rustc::infer::{self, SubregionOrigin};
22-
use rustc::mir::{Location, Mir};
2322
use rustc::ty::subst::UnpackedKind;
2423
use rustc::ty::{self, TyCtxt};
25-
use syntax::codemap::Span;
24+
use syntax_pos::DUMMY_SP;
2625

2726
crate struct ConstraintConversion<'a, 'gcx: 'tcx, 'tcx: 'a> {
2827
tcx: TyCtxt<'a, 'gcx, 'tcx>,
29-
mir: &'a Mir<'tcx>,
3028
universal_regions: &'a UniversalRegions<'tcx>,
3129
location_table: &'a LocationTable,
3230
region_bound_pairs: &'a [(ty::Region<'tcx>, GenericKind<'tcx>)],
@@ -41,7 +39,6 @@ crate struct ConstraintConversion<'a, 'gcx: 'tcx, 'tcx: 'a> {
4139
impl<'a, 'gcx, 'tcx> ConstraintConversion<'a, 'gcx, 'tcx> {
4240
crate fn new(
4341
tcx: TyCtxt<'a, 'gcx, 'tcx>,
44-
mir: &'a Mir<'tcx>,
4542
universal_regions: &'a UniversalRegions<'tcx>,
4643
location_table: &'a LocationTable,
4744
region_bound_pairs: &'a [(ty::Region<'tcx>, GenericKind<'tcx>)],
@@ -54,7 +51,6 @@ impl<'a, 'gcx, 'tcx> ConstraintConversion<'a, 'gcx, 'tcx> {
5451
) -> Self {
5552
Self {
5653
tcx,
57-
mir,
5854
universal_regions,
5955
location_table,
6056
region_bound_pairs,
@@ -91,8 +87,7 @@ impl<'a, 'gcx, 'tcx> ConstraintConversion<'a, 'gcx, 'tcx> {
9187
// will start to fail.
9288
let ty::OutlivesPredicate(k1, r2) =
9389
query_constraint.no_late_bound_regions().unwrap_or_else(|| {
94-
span_bug!(
95-
self.span(),
90+
bug!(
9691
"query_constraint {:?} contained bound regions",
9792
query_constraint,
9893
);
@@ -125,7 +120,7 @@ impl<'a, 'gcx, 'tcx> ConstraintConversion<'a, 'gcx, 'tcx> {
125120
UnpackedKind::Type(t1) => {
126121
// we don't actually use this for anything, but
127122
// the `TypeOutlives` code needs an origin.
128-
let origin = infer::RelateParamBound(self.span(), t1);
123+
let origin = infer::RelateParamBound(DUMMY_SP, t1);
129124

130125
TypeOutlives::new(
131126
&mut *self,
@@ -146,15 +141,12 @@ impl<'a, 'gcx, 'tcx> ConstraintConversion<'a, 'gcx, 'tcx> {
146141
) -> TypeTest<'tcx> {
147142
let lower_bound = self.to_region_vid(region);
148143

149-
let point = self.locations.from_location().unwrap_or(Location::START);
150-
151144
let test = self.verify_bound_to_region_test(&bound);
152145

153146
TypeTest {
154147
generic_kind,
155148
lower_bound,
156-
point,
157-
span: self.span(),
149+
locations: self.locations,
158150
test,
159151
}
160152
}
@@ -189,17 +181,9 @@ impl<'a, 'gcx, 'tcx> ConstraintConversion<'a, 'gcx, 'tcx> {
189181
self.universal_regions.to_region_vid(r)
190182
}
191183

192-
fn span(&self) -> Span {
193-
self.mir
194-
.source_info(self.locations.from_location().unwrap_or(Location::START))
195-
.span
196-
}
197-
198184
fn add_outlives(&mut self, sup: ty::RegionVid, sub: ty::RegionVid) {
199-
let span = self.span();
200-
201185
self.outlives_constraints.push(OutlivesConstraint {
202-
span,
186+
locations: self.locations,
203187
sub,
204188
sup,
205189
next: None,

0 commit comments

Comments
 (0)