@@ -16,7 +16,7 @@ use rustc_lint;
16
16
use rustc_resolve:: MakeGlobMap ;
17
17
use rustc:: middle:: lang_items;
18
18
use rustc:: middle:: free_region:: FreeRegionMap ;
19
- use rustc:: middle:: region:: { self , CodeExtent } ;
19
+ use rustc:: middle:: region:: { CodeExtent , RegionMaps } ;
20
20
use rustc:: middle:: region:: CodeExtentData ;
21
21
use rustc:: middle:: resolve_lifetime;
22
22
use rustc:: middle:: stability;
@@ -44,6 +44,7 @@ use rustc::hir;
44
44
45
45
struct Env < ' a , ' gcx : ' a + ' tcx , ' tcx : ' a > {
46
46
infcx : & ' a infer:: InferCtxt < ' a , ' gcx , ' tcx > ,
47
+ region_maps : & ' a mut RegionMaps < ' tcx > ,
47
48
}
48
49
49
50
struct RH < ' a > {
@@ -136,7 +137,6 @@ fn test_env<F>(source_string: &str,
136
137
// run just enough stuff to build a tcx:
137
138
let lang_items = lang_items:: collect_language_items ( & sess, & hir_map) ;
138
139
let named_region_map = resolve_lifetime:: krate ( & sess, & hir_map) ;
139
- let region_map = region:: resolve_crate ( & sess, & hir_map) ;
140
140
let index = stability:: Index :: new ( & hir_map) ;
141
141
TyCtxt :: create_and_enter ( & sess,
142
142
ty:: maps:: Providers :: default ( ) ,
@@ -146,17 +146,16 @@ fn test_env<F>(source_string: &str,
146
146
resolutions,
147
147
named_region_map. unwrap ( ) ,
148
148
hir_map,
149
- region_map,
150
149
lang_items,
151
150
index,
152
151
"test_crate" ,
153
152
|tcx| {
154
153
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 } ) ;
157
156
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) ;
160
159
assert_eq ! ( tcx. sess. err_count( ) , expected_err_count) ;
161
160
} ) ;
162
161
} ) ;
@@ -167,23 +166,21 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
167
166
self . infcx . tcx
168
167
}
169
168
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) ) ;
172
172
for child_rh in rh. sub {
173
173
self . create_region_hierarchy ( child_rh, me) ;
174
174
}
175
175
}
176
176
177
- pub fn create_simple_region_hierarchy ( & self ) {
177
+ pub fn create_simple_region_hierarchy ( & mut self ) {
178
178
// creates a region hierarchy where 1 is root, 10 and 11 are
179
179
// children of 1, etc
180
180
181
181
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 ) ;
187
184
self . create_region_hierarchy ( & RH {
188
185
id : node ( 1 ) ,
189
186
sub : & [ RH {
@@ -327,13 +324,13 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
327
324
}
328
325
329
326
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) ) ) ;
331
328
self . infcx . tcx . mk_imm_ref ( self . infcx . tcx . mk_region ( r) , self . tcx ( ) . types . isize )
332
329
}
333
330
334
331
pub fn re_free ( & self , nid : ast:: NodeId , id : u32 ) -> ty:: Region < ' tcx > {
335
332
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) ) ,
337
334
bound_region : ty:: BrAnon ( id) ,
338
335
} ) )
339
336
}
@@ -431,7 +428,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
431
428
432
429
#[ test]
433
430
fn contravariant_region_ptr_ok ( ) {
434
- test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |env| {
431
+ test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |mut env| {
435
432
env. create_simple_region_hierarchy ( ) ;
436
433
let t_rptr1 = env. t_rptr_scope ( 1 ) ;
437
434
let t_rptr10 = env. t_rptr_scope ( 10 ) ;
@@ -443,7 +440,7 @@ fn contravariant_region_ptr_ok() {
443
440
444
441
#[ test]
445
442
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| {
447
444
env. create_simple_region_hierarchy ( ) ;
448
445
let t_rptr1 = env. t_rptr_scope ( 1 ) ;
449
446
let t_rptr10 = env. t_rptr_scope ( 10 ) ;
@@ -463,7 +460,7 @@ fn sub_free_bound_false() {
463
460
//!
464
461
//! does NOT hold.
465
462
466
- test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |env| {
463
+ test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |mut env| {
467
464
env. create_simple_region_hierarchy ( ) ;
468
465
let t_rptr_free1 = env. t_rptr_free ( 1 , 1 ) ;
469
466
let t_rptr_bound1 = env. t_rptr_late_bound ( 1 ) ;
@@ -480,7 +477,7 @@ fn sub_bound_free_true() {
480
477
//!
481
478
//! DOES hold.
482
479
483
- test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |env| {
480
+ test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |mut env| {
484
481
env. create_simple_region_hierarchy ( ) ;
485
482
let t_rptr_bound1 = env. t_rptr_late_bound ( 1 ) ;
486
483
let t_rptr_free1 = env. t_rptr_free ( 1 , 1 ) ;
@@ -515,7 +512,7 @@ fn lub_free_bound_infer() {
515
512
//! that it yields `fn(&'x isize)` for some free `'x`,
516
513
//! anyhow.
517
514
518
- test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |env| {
515
+ test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |mut env| {
519
516
env. create_simple_region_hierarchy ( ) ;
520
517
let t_infer1 = env. infcx . next_ty_var ( TypeVariableOrigin :: MiscVariable ( DUMMY_SP ) ) ;
521
518
let t_rptr_bound1 = env. t_rptr_late_bound ( 1 ) ;
@@ -539,7 +536,7 @@ fn lub_bound_bound() {
539
536
540
537
#[ test]
541
538
fn lub_bound_free ( ) {
542
- test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |env| {
539
+ test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |mut env| {
543
540
env. create_simple_region_hierarchy ( ) ;
544
541
let t_rptr_bound1 = env. t_rptr_late_bound ( 1 ) ;
545
542
let t_rptr_free1 = env. t_rptr_free ( 1 , 1 ) ;
@@ -573,7 +570,7 @@ fn lub_bound_bound_inverse_order() {
573
570
574
571
#[ test]
575
572
fn lub_free_free ( ) {
576
- test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |env| {
573
+ test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |mut env| {
577
574
env. create_simple_region_hierarchy ( ) ;
578
575
let t_rptr_free1 = env. t_rptr_free ( 1 , 1 ) ;
579
576
let t_rptr_free2 = env. t_rptr_free ( 1 , 2 ) ;
@@ -586,7 +583,7 @@ fn lub_free_free() {
586
583
587
584
#[ test]
588
585
fn lub_returning_scope ( ) {
589
- test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |env| {
586
+ test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |mut env| {
590
587
env. create_simple_region_hierarchy ( ) ;
591
588
let t_rptr_scope10 = env. t_rptr_scope ( 10 ) ;
592
589
let t_rptr_scope11 = env. t_rptr_scope ( 11 ) ;
@@ -599,7 +596,7 @@ fn lub_returning_scope() {
599
596
600
597
#[ test]
601
598
fn glb_free_free_with_common_scope ( ) {
602
- test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |env| {
599
+ test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |mut env| {
603
600
env. create_simple_region_hierarchy ( ) ;
604
601
let t_rptr_free1 = env. t_rptr_free ( 1 , 1 ) ;
605
602
let t_rptr_free2 = env. t_rptr_free ( 1 , 2 ) ;
@@ -623,7 +620,7 @@ fn glb_bound_bound() {
623
620
624
621
#[ test]
625
622
fn glb_bound_free ( ) {
626
- test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |env| {
623
+ test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |mut env| {
627
624
env. create_simple_region_hierarchy ( ) ;
628
625
let t_rptr_bound1 = env. t_rptr_late_bound ( 1 ) ;
629
626
let t_rptr_free1 = env. t_rptr_free ( 1 , 1 ) ;
@@ -745,7 +742,7 @@ fn subst_ty_renumber_some_bounds() {
745
742
#[ test]
746
743
fn escaping ( ) {
747
744
748
- test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |env| {
745
+ test_env ( EMPTY_SOURCE_STR , errors ( & [ ] ) , |mut env| {
749
746
// Situation:
750
747
// Theta = [A -> &'a foo]
751
748
env. create_simple_region_hierarchy ( ) ;
0 commit comments