Skip to content

Commit db169e5

Browse files
committed
move annotate onto a method of UniversalRegions
This allows it to print out the "late-bound regions" from the closure context more easily. Besides, all the state that is being printed it is private to the `UniversalRegions`.
1 parent b7f8713 commit db169e5

13 files changed

+89
-61
lines changed

src/librustc_mir/borrow_check/nll/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ fn dump_annotation<'a, 'gcx, 'tcx>(
276276
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
277277
mir: &Mir<'tcx>,
278278
mir_def_id: DefId,
279-
regioncx: &RegionInferenceContext,
279+
regioncx: &RegionInferenceContext<'tcx>,
280280
closure_region_requirements: &Option<ClosureRegionRequirements>,
281281
errors_buffer: &mut Vec<Diagnostic>,
282282
) {
@@ -299,7 +299,7 @@ fn dump_annotation<'a, 'gcx, 'tcx>(
299299
.diagnostic()
300300
.span_note_diag(mir.span, "External requirements");
301301

302-
regioncx.annotate(&mut err);
302+
regioncx.annotate(tcx, &mut err);
303303

304304
err.note(&format!(
305305
"number of external vids: {}",
@@ -319,7 +319,7 @@ fn dump_annotation<'a, 'gcx, 'tcx>(
319319
.sess
320320
.diagnostic()
321321
.span_note_diag(mir.span, "No external requirements");
322-
regioncx.annotate(&mut err);
322+
regioncx.annotate(tcx, &mut err);
323323

324324
err.buffer(errors_buffer);
325325
}

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

Lines changed: 0 additions & 56 deletions
This file was deleted.

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ use rustc::util::common;
2929
use rustc_data_structures::graph::scc::Sccs;
3030
use rustc_data_structures::indexed_set::IdxSet;
3131
use rustc_data_structures::indexed_vec::IndexVec;
32-
use rustc_errors::Diagnostic;
32+
use rustc_errors::{DiagnosticBuilder, Diagnostic};
3333

3434
use std::rc::Rc;
3535

36-
mod annotation;
3736
mod dump_mir;
3837
mod error_reporting;
3938
mod graphviz;
@@ -359,6 +358,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
359358
self.universal_regions.to_region_vid(r)
360359
}
361360

361+
/// Add annotations for `#[rustc_regions]`; see `UniversalRegions::annotate`.
362+
crate fn annotate(&self, tcx: TyCtxt<'_, '_, 'tcx>, err: &mut DiagnosticBuilder<'_>) {
363+
self.universal_regions.annotate(tcx, err)
364+
}
365+
362366
/// Returns true if the region `r` contains the point `p`.
363367
///
364368
/// Panics if called before `solve()` executes,

src/librustc_mir/borrow_check/nll/universal_regions.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use rustc::ty::subst::Substs;
3131
use rustc::ty::{self, ClosureSubsts, GeneratorSubsts, RegionVid, Ty, TyCtxt};
3232
use rustc::util::nodemap::FxHashMap;
3333
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
34+
use rustc_errors::DiagnosticBuilder;
3435
use std::iter;
3536
use syntax::ast;
3637

@@ -310,6 +311,63 @@ impl<'tcx> UniversalRegions<'tcx> {
310311
pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
311312
self.indices.to_region_vid(r)
312313
}
314+
315+
/// As part of the NLL unit tests, you can annotate a function with
316+
/// `#[rustc_regions]`, and we will emit information about the region
317+
/// inference context and -- in particular -- the external constraints
318+
/// that this region imposes on others. The methods in this file
319+
/// handle the part about dumping the inference context internal
320+
/// state.
321+
crate fn annotate(&self, tcx: TyCtxt<'_, '_, 'tcx>, err: &mut DiagnosticBuilder<'_>) {
322+
match self.defining_ty {
323+
DefiningTy::Closure(def_id, substs) => {
324+
err.note(&format!(
325+
"defining type: {:?} with closure substs {:#?}",
326+
def_id,
327+
&substs.substs[..]
328+
));
329+
330+
let closure_base_def_id = tcx.closure_base_def_id(def_id);
331+
for_each_late_bound_region_defined_on(tcx, closure_base_def_id, |r| {
332+
err.note(&format!(
333+
"late-bound region {:?} is {:?}",
334+
r,
335+
self.to_region_vid(r),
336+
));
337+
});
338+
}
339+
DefiningTy::Generator(def_id, substs, _) => {
340+
err.note(&format!(
341+
"defining type: {:?} with generator substs {:#?}",
342+
def_id,
343+
&substs.substs[..]
344+
));
345+
346+
let closure_base_def_id = tcx.closure_base_def_id(def_id);
347+
for_each_late_bound_region_defined_on(tcx, closure_base_def_id, |r| {
348+
err.note(&format!(
349+
"late-bound region {:?} is {:?}",
350+
r,
351+
self.to_region_vid(r),
352+
));
353+
});
354+
}
355+
DefiningTy::FnDef(def_id, substs) => {
356+
err.note(&format!(
357+
"defining type: {:?} with substs {:#?}",
358+
def_id,
359+
&substs[..]
360+
));
361+
}
362+
DefiningTy::Const(def_id, substs) => {
363+
err.note(&format!(
364+
"defining constant type: {:?} with substs {:#?}",
365+
def_id,
366+
&substs[..]
367+
));
368+
}
369+
}
370+
}
313371
}
314372

315373
struct UniversalRegionsBuilder<'cx, 'gcx: 'tcx, 'tcx: 'cx> {

src/test/ui/nll/closure-requirements/propagate-approximated-fail-no-postdom.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ LL | | },
1212
i16,
1313
for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>, std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) &'_#3r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>))
1414
]
15+
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_approximated_fail_no_postdom[317d]::supply[0]), BrNamed(crate0:DefIndex(1:17), 'a)) is '_#4r
16+
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_approximated_fail_no_postdom[317d]::supply[0]), BrNamed(crate0:DefIndex(1:19), 'c)) is '_#5r
17+
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_approximated_fail_no_postdom[317d]::supply[0]), BrNamed(crate0:DefIndex(1:18), 'b)) is '_#6r
1518

1619
error: unsatisfied lifetime constraints
1720
--> $DIR/propagate-approximated-fail-no-postdom.rs:56:13

src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ LL | | });
1414
i16,
1515
for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't1)) &'_#2r u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't1)) u32>))
1616
]
17+
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_approximated_ref[317d]::supply[0]), BrNamed(crate0:DefIndex(1:17), 'b)) is '_#3r
18+
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_approximated_ref[317d]::supply[0]), BrNamed(crate0:DefIndex(1:16), 'a)) is '_#4r
1719
= note: number of external vids: 5
1820
= note: where '_#1r: '_#2r
1921

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ LL | | });
1515
i16,
1616
for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't1)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't2)) u32>))
1717
]
18+
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]), BrNamed(crate0:DefIndex(1:16), 'a)) is '_#2r
19+
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]), BrNamed(crate0:DefIndex(1:17), 'b)) is '_#3r
1820
= note: number of external vids: 4
1921
= note: where '_#1r: '_#0r
2022

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ LL | | });
1414
i16,
1515
for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't0)) std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't1)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't1)) u32>))
1616
]
17+
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]), BrNamed(crate0:DefIndex(1:17), 'b)) is '_#3r
18+
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]), BrNamed(crate0:DefIndex(1:16), 'a)) is '_#4r
1719
= note: number of external vids: 5
1820
= note: where '_#1r: '_#0r
1921

src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ LL | | });
1414
i16,
1515
for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) &'_#2r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>))
1616
]
17+
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_approximated_val[317d]::test[0]), BrNamed(crate0:DefIndex(1:17), 'b)) is '_#3r
18+
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_approximated_val[317d]::test[0]), BrNamed(crate0:DefIndex(1:16), 'a)) is '_#4r
1719
= note: number of external vids: 5
1820
= note: where '_#1r: '_#2r
1921

src/test/ui/nll/closure-requirements/propagate-despite-same-free-region.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ LL | | },
1212
i16,
1313
for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) &'_#2r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>))
1414
]
15+
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_despite_same_free_region[317d]::supply[0]), BrNamed(crate0:DefIndex(1:15), 'a)) is '_#3r
1516
= note: number of external vids: 4
1617
= note: where '_#1r: '_#2r
1718

src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ LL | | });
1313
i16,
1414
for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) &'_#1r u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't1)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>))
1515
]
16+
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_fail_to_approximate_longer_no_bounds[317d]::supply[0]), BrNamed(crate0:DefIndex(1:16), 'a)) is '_#2r
17+
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_fail_to_approximate_longer_no_bounds[317d]::supply[0]), BrNamed(crate0:DefIndex(1:17), 'b)) is '_#3r
1618

1719
error: unsatisfied lifetime constraints
1820
--> $DIR/propagate-fail-to-approximate-longer-no-bounds.rs:47:9

src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-wrong-bounds.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ LL | | });
1313
i16,
1414
for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) &'_#1r u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't1)) &'_#2r u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't3)) std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 't1)) u32>))
1515
]
16+
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_fail_to_approximate_longer_wrong_bounds[317d]::supply[0]), BrNamed(crate0:DefIndex(1:17), 'b)) is '_#3r
17+
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_fail_to_approximate_longer_wrong_bounds[317d]::supply[0]), BrNamed(crate0:DefIndex(1:16), 'a)) is '_#4r
1618

1719
error: unsatisfied lifetime constraints
1820
--> $DIR/propagate-fail-to-approximate-longer-wrong-bounds.rs:51:9

src/test/ui/nll/ty-outlives/projection-one-region-trait-bound-static-closure.stderr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
1010
i32,
1111
extern "rust-call" fn((std::cell::Cell<&'_#2r ()>, T))
1212
]
13+
= note: late-bound region ReFree(DefId(0/0:8 ~ projection_one_region_trait_bound_static_closure[317d]::no_relationships_late[0]), BrNamed(crate0:DefIndex(1:16), 'a)) is '_#3r
14+
= note: late-bound region ReFree(DefId(0/0:8 ~ projection_one_region_trait_bound_static_closure[317d]::no_relationships_late[0]), BrNamed(crate0:DefIndex(1:18), T)) is '_#4r
1315

1416
note: No external requirements
1517
--> $DIR/projection-one-region-trait-bound-static-closure.rs:42:1
@@ -40,6 +42,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
4042
i32,
4143
extern "rust-call" fn((std::cell::Cell<&'_#3r ()>, T))
4244
]
45+
= note: late-bound region ReFree(DefId(0/0:9 ~ projection_one_region_trait_bound_static_closure[317d]::no_relationships_early[0]), BrNamed(crate0:DefIndex(1:22), T)) is '_#4r
4346

4447
note: No external requirements
4548
--> $DIR/projection-one-region-trait-bound-static-closure.rs:50:1
@@ -72,6 +75,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
7275
i32,
7376
extern "rust-call" fn((std::cell::Cell<&'_#3r ()>, T))
7477
]
78+
= note: late-bound region ReFree(DefId(0/0:10 ~ projection_one_region_trait_bound_static_closure[317d]::projection_outlives[0]), BrNamed(crate0:DefIndex(1:26), T)) is '_#4r
7579

7680
note: No external requirements
7781
--> $DIR/projection-one-region-trait-bound-static-closure.rs:59:1
@@ -104,6 +108,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
104108
i32,
105109
extern "rust-call" fn((std::cell::Cell<&'_#3r ()>, T))
106110
]
111+
= note: late-bound region ReFree(DefId(0/0:11 ~ projection_one_region_trait_bound_static_closure[317d]::elements_outlive[0]), BrNamed(crate0:DefIndex(1:30), T)) is '_#4r
107112

108113
note: No external requirements
109114
--> $DIR/projection-one-region-trait-bound-static-closure.rs:78:1
@@ -135,6 +140,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
135140
i32,
136141
extern "rust-call" fn((std::cell::Cell<&'_#2r ()>, T))
137142
]
143+
= note: late-bound region ReFree(DefId(0/0:12 ~ projection_one_region_trait_bound_static_closure[317d]::one_region[0]), BrNamed(crate0:DefIndex(1:33), T)) is '_#3r
138144

139145
note: No external requirements
140146
--> $DIR/projection-one-region-trait-bound-static-closure.rs:87:1

0 commit comments

Comments
 (0)