Skip to content

Commit c008f05

Browse files
committed
patch the librustc_driver unit tests
1 parent b393d64 commit c008f05

File tree

2 files changed

+43
-39
lines changed

2 files changed

+43
-39
lines changed

src/librustc/middle/region.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,28 @@ impl<'tcx> RegionMaps<'tcx> {
319319
}
320320
}
321321

322+
pub fn record_code_extent(&mut self,
323+
child: CodeExtent<'tcx>,
324+
parent: Option<CodeExtent<'tcx>>) {
325+
debug!("{:?}.parent = {:?}", child, parent);
326+
327+
if let Some(p) = parent {
328+
let prev = self.scope_map.insert(child, p);
329+
assert!(prev.is_none());
330+
}
331+
332+
// record the destruction scopes for later so we can query them
333+
if let &CodeExtentData::DestructionScope(n) = child {
334+
self.destruction_scopes.insert(n, child);
335+
}
336+
}
337+
322338
pub fn each_encl_scope<E>(&self, mut e:E) where E: FnMut(CodeExtent<'tcx>, CodeExtent<'tcx>) {
323339
for (&child, &parent) in &self.scope_map {
324340
e(child, parent)
325341
}
326342
}
343+
327344
pub fn each_var_scope<E>(&self, mut e:E) where E: FnMut(&ast::NodeId, CodeExtent<'tcx>) {
328345
for (child, parent) in self.var_map.iter() {
329346
e(child, parent)
@@ -1098,17 +1115,7 @@ impl<'a, 'tcx> RegionResolutionVisitor<'a, 'tcx> {
10981115
parent: Option<CodeExtent<'tcx>>)
10991116
-> CodeExtent<'tcx> {
11001117
let code_extent = self.tcx.intern_code_extent(data);
1101-
debug!("{:?}.parent = {:?}", code_extent, parent);
1102-
if let Some(p) = parent {
1103-
let prev = self.region_maps.scope_map.insert(code_extent, p);
1104-
assert!(prev.is_none());
1105-
}
1106-
1107-
// record the destruction scopes for later so we can query them
1108-
if let &CodeExtentData::DestructionScope(n) = code_extent {
1109-
self.region_maps.destruction_scopes.insert(n, code_extent);
1110-
}
1111-
1118+
self.region_maps.record_code_extent(code_extent, parent);
11121119
code_extent
11131120
}
11141121

src/librustc_driver/test.rs

+25-28
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_lint;
1616
use rustc_resolve::MakeGlobMap;
1717
use rustc::middle::lang_items;
1818
use rustc::middle::free_region::FreeRegionMap;
19-
use rustc::middle::region::{self, CodeExtent};
19+
use rustc::middle::region::{CodeExtent, RegionMaps};
2020
use rustc::middle::region::CodeExtentData;
2121
use rustc::middle::resolve_lifetime;
2222
use rustc::middle::stability;
@@ -44,6 +44,7 @@ use rustc::hir;
4444

4545
struct Env<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
4646
infcx: &'a infer::InferCtxt<'a, 'gcx, 'tcx>,
47+
region_maps: &'a mut RegionMaps<'tcx>,
4748
}
4849

4950
struct RH<'a> {
@@ -136,7 +137,6 @@ fn test_env<F>(source_string: &str,
136137
// run just enough stuff to build a tcx:
137138
let lang_items = lang_items::collect_language_items(&sess, &hir_map);
138139
let named_region_map = resolve_lifetime::krate(&sess, &hir_map);
139-
let region_map = region::resolve_crate(&sess, &hir_map);
140140
let index = stability::Index::new(&hir_map);
141141
TyCtxt::create_and_enter(&sess,
142142
ty::maps::Providers::default(),
@@ -146,17 +146,16 @@ fn test_env<F>(source_string: &str,
146146
resolutions,
147147
named_region_map.unwrap(),
148148
hir_map,
149-
region_map,
150149
lang_items,
151150
index,
152151
"test_crate",
153152
|tcx| {
154153
tcx.infer_ctxt((), Reveal::UserFacing).enter(|infcx| {
155-
156-
body(Env { infcx: &infcx });
154+
let mut region_maps = RegionMaps::new();
155+
body(Env { infcx: &infcx, region_maps: &mut region_maps });
157156
let free_regions = FreeRegionMap::new();
158-
let def_id = tcx.hir.map.local_def_id(ast::CRATE_NODE_ID);
159-
infcx.resolve_regions_and_report_errors(def_id, &region_map, &free_regions);
157+
let def_id = tcx.hir.local_def_id(ast::CRATE_NODE_ID);
158+
infcx.resolve_regions_and_report_errors(def_id, &region_maps, &free_regions);
160159
assert_eq!(tcx.sess.err_count(), expected_err_count);
161160
});
162161
});
@@ -167,23 +166,21 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
167166
self.infcx.tcx
168167
}
169168

170-
pub fn create_region_hierarchy(&self, rh: &RH, parent: CodeExtent) {
171-
let me = self.infcx.tcx.region_maps.intern_node(rh.id, parent);
169+
pub fn create_region_hierarchy(&mut self, rh: &RH, parent: CodeExtent<'tcx>) {
170+
let me = self.tcx().intern_code_extent(CodeExtentData::Misc(rh.id));
171+
self.region_maps.record_code_extent(me, Some(parent));
172172
for child_rh in rh.sub {
173173
self.create_region_hierarchy(child_rh, me);
174174
}
175175
}
176176

177-
pub fn create_simple_region_hierarchy(&self) {
177+
pub fn create_simple_region_hierarchy(&mut self) {
178178
// creates a region hierarchy where 1 is root, 10 and 11 are
179179
// children of 1, etc
180180

181181
let node = ast::NodeId::from_u32;
182-
let dscope = self.infcx
183-
.tcx
184-
.region_maps
185-
.intern_code_extent(CodeExtentData::DestructionScope(node(1)),
186-
region::ROOT_CODE_EXTENT);
182+
let dscope = self.tcx().intern_code_extent(CodeExtentData::DestructionScope(node(1)));
183+
self.region_maps.record_code_extent(dscope, None);
187184
self.create_region_hierarchy(&RH {
188185
id: node(1),
189186
sub: &[RH {
@@ -327,13 +324,13 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
327324
}
328325

329326
pub fn t_rptr_scope(&self, id: u32) -> Ty<'tcx> {
330-
let r = ty::ReScope(self.tcx().region_maps.node_extent(ast::NodeId::from_u32(id)));
327+
let r = ty::ReScope(self.tcx().node_extent(ast::NodeId::from_u32(id)));
331328
self.infcx.tcx.mk_imm_ref(self.infcx.tcx.mk_region(r), self.tcx().types.isize)
332329
}
333330

334331
pub fn re_free(&self, nid: ast::NodeId, id: u32) -> ty::Region<'tcx> {
335332
self.infcx.tcx.mk_region(ty::ReFree(ty::FreeRegion {
336-
scope: self.tcx().region_maps.item_extent(nid),
333+
scope: Some(self.tcx().node_extent(nid)),
337334
bound_region: ty::BrAnon(id),
338335
}))
339336
}
@@ -431,7 +428,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
431428

432429
#[test]
433430
fn contravariant_region_ptr_ok() {
434-
test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
431+
test_env(EMPTY_SOURCE_STR, errors(&[]), |mut env| {
435432
env.create_simple_region_hierarchy();
436433
let t_rptr1 = env.t_rptr_scope(1);
437434
let t_rptr10 = env.t_rptr_scope(10);
@@ -443,7 +440,7 @@ fn contravariant_region_ptr_ok() {
443440

444441
#[test]
445442
fn contravariant_region_ptr_err() {
446-
test_env(EMPTY_SOURCE_STR, errors(&["mismatched types"]), |env| {
443+
test_env(EMPTY_SOURCE_STR, errors(&["mismatched types"]), |mut env| {
447444
env.create_simple_region_hierarchy();
448445
let t_rptr1 = env.t_rptr_scope(1);
449446
let t_rptr10 = env.t_rptr_scope(10);
@@ -463,7 +460,7 @@ fn sub_free_bound_false() {
463460
//!
464461
//! does NOT hold.
465462
466-
test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
463+
test_env(EMPTY_SOURCE_STR, errors(&[]), |mut env| {
467464
env.create_simple_region_hierarchy();
468465
let t_rptr_free1 = env.t_rptr_free(1, 1);
469466
let t_rptr_bound1 = env.t_rptr_late_bound(1);
@@ -480,7 +477,7 @@ fn sub_bound_free_true() {
480477
//!
481478
//! DOES hold.
482479
483-
test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
480+
test_env(EMPTY_SOURCE_STR, errors(&[]), |mut env| {
484481
env.create_simple_region_hierarchy();
485482
let t_rptr_bound1 = env.t_rptr_late_bound(1);
486483
let t_rptr_free1 = env.t_rptr_free(1, 1);
@@ -515,7 +512,7 @@ fn lub_free_bound_infer() {
515512
//! that it yields `fn(&'x isize)` for some free `'x`,
516513
//! anyhow.
517514
518-
test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
515+
test_env(EMPTY_SOURCE_STR, errors(&[]), |mut env| {
519516
env.create_simple_region_hierarchy();
520517
let t_infer1 = env.infcx.next_ty_var(TypeVariableOrigin::MiscVariable(DUMMY_SP));
521518
let t_rptr_bound1 = env.t_rptr_late_bound(1);
@@ -539,7 +536,7 @@ fn lub_bound_bound() {
539536

540537
#[test]
541538
fn lub_bound_free() {
542-
test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
539+
test_env(EMPTY_SOURCE_STR, errors(&[]), |mut env| {
543540
env.create_simple_region_hierarchy();
544541
let t_rptr_bound1 = env.t_rptr_late_bound(1);
545542
let t_rptr_free1 = env.t_rptr_free(1, 1);
@@ -573,7 +570,7 @@ fn lub_bound_bound_inverse_order() {
573570

574571
#[test]
575572
fn lub_free_free() {
576-
test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
573+
test_env(EMPTY_SOURCE_STR, errors(&[]), |mut env| {
577574
env.create_simple_region_hierarchy();
578575
let t_rptr_free1 = env.t_rptr_free(1, 1);
579576
let t_rptr_free2 = env.t_rptr_free(1, 2);
@@ -586,7 +583,7 @@ fn lub_free_free() {
586583

587584
#[test]
588585
fn lub_returning_scope() {
589-
test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
586+
test_env(EMPTY_SOURCE_STR, errors(&[]), |mut env| {
590587
env.create_simple_region_hierarchy();
591588
let t_rptr_scope10 = env.t_rptr_scope(10);
592589
let t_rptr_scope11 = env.t_rptr_scope(11);
@@ -599,7 +596,7 @@ fn lub_returning_scope() {
599596

600597
#[test]
601598
fn glb_free_free_with_common_scope() {
602-
test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
599+
test_env(EMPTY_SOURCE_STR, errors(&[]), |mut env| {
603600
env.create_simple_region_hierarchy();
604601
let t_rptr_free1 = env.t_rptr_free(1, 1);
605602
let t_rptr_free2 = env.t_rptr_free(1, 2);
@@ -623,7 +620,7 @@ fn glb_bound_bound() {
623620

624621
#[test]
625622
fn glb_bound_free() {
626-
test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
623+
test_env(EMPTY_SOURCE_STR, errors(&[]), |mut env| {
627624
env.create_simple_region_hierarchy();
628625
let t_rptr_bound1 = env.t_rptr_late_bound(1);
629626
let t_rptr_free1 = env.t_rptr_free(1, 1);
@@ -745,7 +742,7 @@ fn subst_ty_renumber_some_bounds() {
745742
#[test]
746743
fn escaping() {
747744

748-
test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
745+
test_env(EMPTY_SOURCE_STR, errors(&[]), |mut env| {
749746
// Situation:
750747
// Theta = [A -> &'a foo]
751748
env.create_simple_region_hierarchy();

0 commit comments

Comments
 (0)