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`.
This commit is contained in:
parent
b7f871363b
commit
db169e53e5
@ -276,7 +276,7 @@ fn dump_annotation<'a, 'gcx, 'tcx>(
|
||||
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
mir: &Mir<'tcx>,
|
||||
mir_def_id: DefId,
|
||||
regioncx: &RegionInferenceContext,
|
||||
regioncx: &RegionInferenceContext<'tcx>,
|
||||
closure_region_requirements: &Option<ClosureRegionRequirements>,
|
||||
errors_buffer: &mut Vec<Diagnostic>,
|
||||
) {
|
||||
@ -299,7 +299,7 @@ fn dump_annotation<'a, 'gcx, 'tcx>(
|
||||
.diagnostic()
|
||||
.span_note_diag(mir.span, "External requirements");
|
||||
|
||||
regioncx.annotate(&mut err);
|
||||
regioncx.annotate(tcx, &mut err);
|
||||
|
||||
err.note(&format!(
|
||||
"number of external vids: {}",
|
||||
@ -319,7 +319,7 @@ fn dump_annotation<'a, 'gcx, 'tcx>(
|
||||
.sess
|
||||
.diagnostic()
|
||||
.span_note_diag(mir.span, "No external requirements");
|
||||
regioncx.annotate(&mut err);
|
||||
regioncx.annotate(tcx, &mut err);
|
||||
|
||||
err.buffer(errors_buffer);
|
||||
}
|
||||
|
@ -1,56 +0,0 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//! As part of the NLL unit tests, you can annotate a function with
|
||||
//! `#[rustc_regions]`, and we will emit information about the region
|
||||
//! inference context and -- in particular -- the external constraints
|
||||
//! that this region imposes on others. The methods in this file
|
||||
//! handle the part about dumping the inference context internal
|
||||
//! state.
|
||||
|
||||
use borrow_check::nll::region_infer::RegionInferenceContext;
|
||||
use borrow_check::nll::universal_regions::DefiningTy;
|
||||
use rustc_errors::DiagnosticBuilder;
|
||||
|
||||
impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
/// Write out our state into the `.mir` files.
|
||||
pub(crate) fn annotate(&self, err: &mut DiagnosticBuilder<'_>) {
|
||||
match self.universal_regions.defining_ty {
|
||||
DefiningTy::Closure(def_id, substs) => {
|
||||
err.note(&format!(
|
||||
"defining type: {:?} with closure substs {:#?}",
|
||||
def_id,
|
||||
&substs.substs[..]
|
||||
));
|
||||
}
|
||||
DefiningTy::Generator(def_id, substs, _) => {
|
||||
err.note(&format!(
|
||||
"defining type: {:?} with generator substs {:#?}",
|
||||
def_id,
|
||||
&substs.substs[..]
|
||||
));
|
||||
}
|
||||
DefiningTy::FnDef(def_id, substs) => {
|
||||
err.note(&format!(
|
||||
"defining type: {:?} with substs {:#?}",
|
||||
def_id,
|
||||
&substs[..]
|
||||
));
|
||||
}
|
||||
DefiningTy::Const(def_id, substs) => {
|
||||
err.note(&format!(
|
||||
"defining constant type: {:?} with substs {:#?}",
|
||||
def_id,
|
||||
&substs[..]
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -29,11 +29,10 @@ use rustc::util::common;
|
||||
use rustc_data_structures::graph::scc::Sccs;
|
||||
use rustc_data_structures::indexed_set::IdxSet;
|
||||
use rustc_data_structures::indexed_vec::IndexVec;
|
||||
use rustc_errors::Diagnostic;
|
||||
use rustc_errors::{DiagnosticBuilder, Diagnostic};
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
mod annotation;
|
||||
mod dump_mir;
|
||||
mod error_reporting;
|
||||
mod graphviz;
|
||||
@ -359,6 +358,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
self.universal_regions.to_region_vid(r)
|
||||
}
|
||||
|
||||
/// Add annotations for `#[rustc_regions]`; see `UniversalRegions::annotate`.
|
||||
crate fn annotate(&self, tcx: TyCtxt<'_, '_, 'tcx>, err: &mut DiagnosticBuilder<'_>) {
|
||||
self.universal_regions.annotate(tcx, err)
|
||||
}
|
||||
|
||||
/// Returns true if the region `r` contains the point `p`.
|
||||
///
|
||||
/// Panics if called before `solve()` executes,
|
||||
|
@ -31,6 +31,7 @@ use rustc::ty::subst::Substs;
|
||||
use rustc::ty::{self, ClosureSubsts, GeneratorSubsts, RegionVid, Ty, TyCtxt};
|
||||
use rustc::util::nodemap::FxHashMap;
|
||||
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
|
||||
use rustc_errors::DiagnosticBuilder;
|
||||
use std::iter;
|
||||
use syntax::ast;
|
||||
|
||||
@ -310,6 +311,63 @@ impl<'tcx> UniversalRegions<'tcx> {
|
||||
pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
|
||||
self.indices.to_region_vid(r)
|
||||
}
|
||||
|
||||
/// As part of the NLL unit tests, you can annotate a function with
|
||||
/// `#[rustc_regions]`, and we will emit information about the region
|
||||
/// inference context and -- in particular -- the external constraints
|
||||
/// that this region imposes on others. The methods in this file
|
||||
/// handle the part about dumping the inference context internal
|
||||
/// state.
|
||||
crate fn annotate(&self, tcx: TyCtxt<'_, '_, 'tcx>, err: &mut DiagnosticBuilder<'_>) {
|
||||
match self.defining_ty {
|
||||
DefiningTy::Closure(def_id, substs) => {
|
||||
err.note(&format!(
|
||||
"defining type: {:?} with closure substs {:#?}",
|
||||
def_id,
|
||||
&substs.substs[..]
|
||||
));
|
||||
|
||||
let closure_base_def_id = tcx.closure_base_def_id(def_id);
|
||||
for_each_late_bound_region_defined_on(tcx, closure_base_def_id, |r| {
|
||||
err.note(&format!(
|
||||
"late-bound region {:?} is {:?}",
|
||||
r,
|
||||
self.to_region_vid(r),
|
||||
));
|
||||
});
|
||||
}
|
||||
DefiningTy::Generator(def_id, substs, _) => {
|
||||
err.note(&format!(
|
||||
"defining type: {:?} with generator substs {:#?}",
|
||||
def_id,
|
||||
&substs.substs[..]
|
||||
));
|
||||
|
||||
let closure_base_def_id = tcx.closure_base_def_id(def_id);
|
||||
for_each_late_bound_region_defined_on(tcx, closure_base_def_id, |r| {
|
||||
err.note(&format!(
|
||||
"late-bound region {:?} is {:?}",
|
||||
r,
|
||||
self.to_region_vid(r),
|
||||
));
|
||||
});
|
||||
}
|
||||
DefiningTy::FnDef(def_id, substs) => {
|
||||
err.note(&format!(
|
||||
"defining type: {:?} with substs {:#?}",
|
||||
def_id,
|
||||
&substs[..]
|
||||
));
|
||||
}
|
||||
DefiningTy::Const(def_id, substs) => {
|
||||
err.note(&format!(
|
||||
"defining constant type: {:?} with substs {:#?}",
|
||||
def_id,
|
||||
&substs[..]
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct UniversalRegionsBuilder<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
|
||||
|
@ -12,6 +12,9 @@ LL | | },
|
||||
i16,
|
||||
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>))
|
||||
]
|
||||
= 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
|
||||
= 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
|
||||
= 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
|
||||
|
||||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/propagate-approximated-fail-no-postdom.rs:56:13
|
||||
|
@ -14,6 +14,8 @@ LL | | });
|
||||
i16,
|
||||
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>))
|
||||
]
|
||||
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_approximated_ref[317d]::supply[0]), BrNamed(crate0:DefIndex(1:17), 'b)) is '_#3r
|
||||
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_approximated_ref[317d]::supply[0]), BrNamed(crate0:DefIndex(1:16), 'a)) is '_#4r
|
||||
= note: number of external vids: 5
|
||||
= note: where '_#1r: '_#2r
|
||||
|
||||
|
@ -15,6 +15,8 @@ LL | | });
|
||||
i16,
|
||||
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>))
|
||||
]
|
||||
= 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
|
||||
= 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
|
||||
= note: number of external vids: 4
|
||||
= note: where '_#1r: '_#0r
|
||||
|
||||
|
@ -14,6 +14,8 @@ LL | | });
|
||||
i16,
|
||||
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>))
|
||||
]
|
||||
= 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
|
||||
= 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
|
||||
= note: number of external vids: 5
|
||||
= note: where '_#1r: '_#0r
|
||||
|
||||
|
@ -14,6 +14,8 @@ LL | | });
|
||||
i16,
|
||||
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>))
|
||||
]
|
||||
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_approximated_val[317d]::test[0]), BrNamed(crate0:DefIndex(1:17), 'b)) is '_#3r
|
||||
= note: late-bound region ReFree(DefId(0/0:6 ~ propagate_approximated_val[317d]::test[0]), BrNamed(crate0:DefIndex(1:16), 'a)) is '_#4r
|
||||
= note: number of external vids: 5
|
||||
= note: where '_#1r: '_#2r
|
||||
|
||||
|
@ -12,6 +12,7 @@ LL | | },
|
||||
i16,
|
||||
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>))
|
||||
]
|
||||
= 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
|
||||
= note: number of external vids: 4
|
||||
= note: where '_#1r: '_#2r
|
||||
|
||||
|
@ -13,6 +13,8 @@ LL | | });
|
||||
i16,
|
||||
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>))
|
||||
]
|
||||
= 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
|
||||
= 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
|
||||
|
||||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/propagate-fail-to-approximate-longer-no-bounds.rs:47:9
|
||||
|
@ -13,6 +13,8 @@ LL | | });
|
||||
i16,
|
||||
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>))
|
||||
]
|
||||
= 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
|
||||
= 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
|
||||
|
||||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/propagate-fail-to-approximate-longer-wrong-bounds.rs:51:9
|
||||
|
@ -10,6 +10,8 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
|
||||
i32,
|
||||
extern "rust-call" fn((std::cell::Cell<&'_#2r ()>, T))
|
||||
]
|
||||
= 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
|
||||
= 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
|
||||
|
||||
note: No external requirements
|
||||
--> $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));
|
||||
i32,
|
||||
extern "rust-call" fn((std::cell::Cell<&'_#3r ()>, T))
|
||||
]
|
||||
= 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
|
||||
|
||||
note: No external requirements
|
||||
--> $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));
|
||||
i32,
|
||||
extern "rust-call" fn((std::cell::Cell<&'_#3r ()>, T))
|
||||
]
|
||||
= 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
|
||||
|
||||
note: No external requirements
|
||||
--> $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));
|
||||
i32,
|
||||
extern "rust-call" fn((std::cell::Cell<&'_#3r ()>, T))
|
||||
]
|
||||
= 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
|
||||
|
||||
note: No external requirements
|
||||
--> $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));
|
||||
i32,
|
||||
extern "rust-call" fn((std::cell::Cell<&'_#2r ()>, T))
|
||||
]
|
||||
= 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
|
||||
|
||||
note: No external requirements
|
||||
--> $DIR/projection-one-region-trait-bound-static-closure.rs:87:1
|
||||
|
Loading…
Reference in New Issue
Block a user