Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ed94397

Browse files
committedSep 17, 2018
Auto merge of #54260 - maxdeviant:public-scope-fields, r=petrochenkov
Make rustc::middle::region::Scope's fields public This PR makes the following changes to `rustc::middle::region::Scope`: - [x] Makes `region::Scope`'s fields public - [x] Removes the `impl Scope` block with constructors (as per [this comment](#54032 (comment))) - [x] Updates call sites throughout the compiler Closes #54122.
2 parents 0b0d2ed + 2d7176f commit ed94397

File tree

17 files changed

+157
-101
lines changed

17 files changed

+157
-101
lines changed
 

‎src/librustc/cfg/construct.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,10 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
556556
target_scope: region::Scope,
557557
to_index: CFGIndex) {
558558
let mut data = CFGEdgeData { exiting_scopes: vec![] };
559-
let mut scope = region::Scope::Node(from_expr.hir_id.local_id);
559+
let mut scope = region::Scope {
560+
id: from_expr.hir_id.local_id,
561+
data: region::ScopeData::Node
562+
};
560563
let region_scope_tree = self.tcx.region_scope_tree(self.owner_def_id);
561564
while scope != target_scope {
562565
data.exiting_scopes.push(scope.item_local_id());
@@ -586,17 +589,23 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
586589
Ok(loop_id) => {
587590
for b in &self.breakable_block_scopes {
588591
if b.block_expr_id == self.tcx.hir.node_to_hir_id(loop_id).local_id {
589-
let scope_id = self.tcx.hir.node_to_hir_id(loop_id).local_id;
590-
return (region::Scope::Node(scope_id), match scope_cf_kind {
592+
let scope = region::Scope {
593+
id: self.tcx.hir.node_to_hir_id(loop_id).local_id,
594+
data: region::ScopeData::Node
595+
};
596+
return (scope, match scope_cf_kind {
591597
ScopeCfKind::Break => b.break_index,
592598
ScopeCfKind::Continue => bug!("can't continue to block"),
593599
});
594600
}
595601
}
596602
for l in &self.loop_scopes {
597603
if l.loop_id == self.tcx.hir.node_to_hir_id(loop_id).local_id {
598-
let scope_id = self.tcx.hir.node_to_hir_id(loop_id).local_id;
599-
return (region::Scope::Node(scope_id), match scope_cf_kind {
604+
let scope = region::Scope {
605+
id: self.tcx.hir.node_to_hir_id(loop_id).local_id,
606+
data: region::ScopeData::Node
607+
};
608+
return (scope, match scope_cf_kind {
600609
ScopeCfKind::Break => l.break_index,
601610
ScopeCfKind::Continue => l.continue_index,
602611
});

‎src/librustc/infer/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
118118
return;
119119
}
120120
};
121-
let scope_decorated_tag = match scope.data() {
121+
let scope_decorated_tag = match scope.data {
122122
region::ScopeData::Node => tag,
123123
region::ScopeData::CallSite => "scope of call-site for function",
124124
region::ScopeData::Arguments => "scope of function body",

‎src/librustc/middle/expr_use_visitor.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,11 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
317317
debug!("consume_body: arg_ty = {:?}", arg_ty);
318318

319319
let fn_body_scope_r =
320-
self.tcx().mk_region(ty::ReScope(region::Scope::Node(body.value.hir_id.local_id)));
320+
self.tcx().mk_region(ty::ReScope(
321+
region::Scope {
322+
id: body.value.hir_id.local_id,
323+
data: region::ScopeData::Node
324+
}));
321325
let arg_cmt = Rc::new(self.mc.cat_rvalue(
322326
arg.hir_id,
323327
arg.pat.span,
@@ -558,7 +562,10 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
558562
_ => {
559563
if let Some(def) = self.mc.tables.type_dependent_defs().get(call.hir_id) {
560564
let def_id = def.def_id();
561-
let call_scope = region::Scope::Node(call.hir_id.local_id);
565+
let call_scope = region::Scope {
566+
id: call.hir_id.local_id,
567+
data: region::ScopeData::Node
568+
};
562569
match OverloadedCallType::from_method_id(self.tcx(), def_id) {
563570
FnMutOverloadedCall => {
564571
let call_scope_r = self.tcx().mk_region(ty::ReScope(call_scope));
@@ -766,7 +773,10 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
766773
// treated as borrowing it for the enclosing temporary
767774
// scope.
768775
let r = self.tcx().mk_region(ty::ReScope(
769-
region::Scope::Node(expr.hir_id.local_id)));
776+
region::Scope {
777+
id: expr.hir_id.local_id,
778+
data: region::ScopeData::Node
779+
}));
770780

771781
self.delegate.borrow(expr.id,
772782
expr.span,

‎src/librustc/middle/region.rs

Lines changed: 20 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
102102
/// generated via deriving here.
103103
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Copy, RustcEncodable, RustcDecodable)]
104104
pub struct Scope {
105-
pub(crate) id: hir::ItemLocalId,
106-
pub(crate) data: ScopeData,
105+
pub id: hir::ItemLocalId,
106+
pub data: ScopeData,
107107
}
108108

109109
impl fmt::Debug for Scope {
@@ -172,48 +172,6 @@ impl_stable_hash_for!(struct ::middle::region::FirstStatementIndex { private });
172172
#[cfg(not(stage0))]
173173
static ASSERT: () = [()][!(mem::size_of::<ScopeData>() == 4) as usize];
174174

175-
#[allow(non_snake_case)]
176-
impl Scope {
177-
#[inline]
178-
pub fn data(self) -> ScopeData {
179-
self.data
180-
}
181-
182-
#[inline]
183-
pub fn new(id: hir::ItemLocalId, data: ScopeData) -> Self {
184-
Scope { id, data }
185-
}
186-
187-
#[inline]
188-
pub fn Node(id: hir::ItemLocalId) -> Self {
189-
Self::new(id, ScopeData::Node)
190-
}
191-
192-
#[inline]
193-
pub fn CallSite(id: hir::ItemLocalId) -> Self {
194-
Self::new(id, ScopeData::CallSite)
195-
}
196-
197-
#[inline]
198-
pub fn Arguments(id: hir::ItemLocalId) -> Self {
199-
Self::new(id, ScopeData::Arguments)
200-
}
201-
202-
#[inline]
203-
pub fn Destruction(id: hir::ItemLocalId) -> Self {
204-
Self::new(id, ScopeData::Destruction)
205-
}
206-
207-
#[inline]
208-
pub fn Remainder(
209-
id: hir::ItemLocalId,
210-
first: FirstStatementIndex,
211-
) -> Self {
212-
Self::new(id, ScopeData::Remainder(first))
213-
}
214-
}
215-
216-
217175
impl Scope {
218176
/// Returns a item-local id associated with this scope.
219177
///
@@ -244,7 +202,7 @@ impl Scope {
244202
return DUMMY_SP;
245203
}
246204
let span = tcx.hir.span(node_id);
247-
if let ScopeData::Remainder(first_statement_index) = self.data() {
205+
if let ScopeData::Remainder(first_statement_index) = self.data {
248206
if let Node::Block(ref blk) = tcx.hir.get(node_id) {
249207
// Want span for scope starting after the
250208
// indexed statement and ending at end of
@@ -498,7 +456,7 @@ impl<'tcx> ScopeTree {
498456
}
499457

500458
// record the destruction scopes for later so we can query them
501-
if let ScopeData::Destruction = child.data() {
459+
if let ScopeData::Destruction = child.data {
502460
self.destruction_scopes.insert(child.item_local_id(), child);
503461
}
504462
}
@@ -578,10 +536,10 @@ impl<'tcx> ScopeTree {
578536
// if there's one. Static items, for instance, won't
579537
// have an enclosing scope, hence no scope will be
580538
// returned.
581-
let mut id = Scope::Node(expr_id);
539+
let mut id = Scope { id: expr_id, data: ScopeData::Node };
582540

583541
while let Some(&(p, _)) = self.parent_map.get(&id) {
584-
match p.data() {
542+
match p.data {
585543
ScopeData::Destruction => {
586544
debug!("temporary_scope({:?}) = {:?} [enclosing]",
587545
expr_id, id);
@@ -637,7 +595,7 @@ impl<'tcx> ScopeTree {
637595
/// Returns the id of the innermost containing body
638596
pub fn containing_body(&self, mut scope: Scope)-> Option<hir::ItemLocalId> {
639597
loop {
640-
if let ScopeData::CallSite = scope.data() {
598+
if let ScopeData::CallSite = scope.data {
641599
return Some(scope.item_local_id());
642600
}
643601

@@ -730,7 +688,7 @@ impl<'tcx> ScopeTree {
730688
self.root_body.unwrap().local_id
731689
});
732690

733-
Scope::CallSite(scope)
691+
Scope { id: scope, data: ScopeData::CallSite }
734692
}
735693

736694
/// Assuming that the provided region was defined within this `ScopeTree`,
@@ -750,7 +708,7 @@ impl<'tcx> ScopeTree {
750708

751709
let param_owner_id = tcx.hir.as_local_node_id(param_owner).unwrap();
752710
let body_id = tcx.hir.body_owned_by(param_owner_id);
753-
Scope::CallSite(tcx.hir.body(body_id).value.hir_id.local_id)
711+
Scope { id: tcx.hir.body(body_id).value.hir_id.local_id, data: ScopeData::CallSite }
754712
}
755713

756714
/// Checks whether the given scope contains a `yield`. If so,
@@ -854,7 +812,10 @@ fn resolve_block<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, blk:
854812
// except for the first such subscope, which has the
855813
// block itself as a parent.
856814
visitor.enter_scope(
857-
Scope::Remainder(blk.hir_id.local_id, FirstStatementIndex::new(i))
815+
Scope {
816+
id: blk.hir_id.local_id,
817+
data: ScopeData::Remainder(FirstStatementIndex::new(i))
818+
}
858819
);
859820
visitor.cx.var_parent = visitor.cx.parent;
860821
}
@@ -879,7 +840,7 @@ fn resolve_arm<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, arm: &
879840
}
880841

881842
fn resolve_pat<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, pat: &'tcx hir::Pat) {
882-
visitor.record_child_scope(Scope::Node(pat.hir_id.local_id));
843+
visitor.record_child_scope(Scope { id: pat.hir_id.local_id, data: ScopeData::Node });
883844

884845
// If this is a binding then record the lifetime of that binding.
885846
if let PatKind::Binding(..) = pat.node {
@@ -1008,15 +969,15 @@ fn resolve_expr<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, expr:
1008969

1009970
if let hir::ExprKind::Yield(..) = expr.node {
1010971
// Mark this expr's scope and all parent scopes as containing `yield`.
1011-
let mut scope = Scope::Node(expr.hir_id.local_id);
972+
let mut scope = Scope { id: expr.hir_id.local_id, data: ScopeData::Node };
1012973
loop {
1013974
visitor.scope_tree.yield_in_scope.insert(scope,
1014975
(expr.span, visitor.expr_and_pat_count));
1015976

1016977
// Keep traversing up while we can.
1017978
match visitor.scope_tree.parent_map.get(&scope) {
1018979
// Don't cross from closure bodies to their parent.
1019-
Some(&(superscope, _)) => match superscope.data() {
980+
Some(&(superscope, _)) => match superscope.data {
1020981
ScopeData::CallSite => break,
1021982
_ => scope = superscope
1022983
},
@@ -1280,9 +1241,9 @@ impl<'a, 'tcx> RegionResolutionVisitor<'a, 'tcx> {
12801241
// account for the destruction scope representing the scope of
12811242
// the destructors that run immediately after it completes.
12821243
if self.terminating_scopes.contains(&id) {
1283-
self.enter_scope(Scope::Destruction(id));
1244+
self.enter_scope(Scope { id, data: ScopeData::Destruction });
12841245
}
1285-
self.enter_scope(Scope::Node(id));
1246+
self.enter_scope(Scope { id, data: ScopeData::Node });
12861247
}
12871248
}
12881249

@@ -1315,8 +1276,8 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionResolutionVisitor<'a, 'tcx> {
13151276
}
13161277
self.cx.root_id = Some(body.value.hir_id.local_id);
13171278

1318-
self.enter_scope(Scope::CallSite(body.value.hir_id.local_id));
1319-
self.enter_scope(Scope::Arguments(body.value.hir_id.local_id));
1279+
self.enter_scope(Scope { id: body.value.hir_id.local_id, data: ScopeData::CallSite });
1280+
self.enter_scope(Scope { id: body.value.hir_id.local_id, data: ScopeData::Arguments });
13201281

13211282
// The arguments and `self` are parented to the fn.
13221283
self.cx.var_parent = self.cx.parent.take();

‎src/librustc/util/ppaux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ define_print! {
769769
write!(f, "{}", br)
770770
}
771771
ty::ReScope(scope) if cx.identify_regions => {
772-
match scope.data() {
772+
match scope.data {
773773
region::ScopeData::Node =>
774774
write!(f, "'{}s", scope.item_local_id().as_usize()),
775775
region::ScopeData::CallSite =>

‎src/librustc_borrowck/borrowck/check_loans.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,12 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
767767

768768
let mut ret = UseOk;
769769

770+
let scope = region::Scope {
771+
id: expr_id,
772+
data: region::ScopeData::Node
773+
};
770774
self.each_in_scope_loan_affecting_path(
771-
region::Scope::Node(expr_id), use_path, |loan| {
775+
scope, use_path, |loan| {
772776
if !compatible_borrow_kinds(loan.kind, borrow_kind) {
773777
ret = UseWhileBorrowed(loan.loan_path.clone(), loan.span);
774778
false
@@ -886,7 +890,10 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
886890

887891
// Check that we don't invalidate any outstanding loans
888892
if let Some(loan_path) = opt_loan_path(assignee_cmt) {
889-
let scope = region::Scope::Node(assignment_id);
893+
let scope = region::Scope {
894+
id: assignment_id,
895+
data: region::ScopeData::Node
896+
};
890897
self.each_in_scope_loan_affecting_path(scope, &loan_path, |loan| {
891898
self.report_illegal_mutation(assignment_span, &loan_path, loan);
892899
false

‎src/librustc_borrowck/borrowck/gather_loans/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ pub fn gather_loans_in_fn<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
4343
let mut glcx = GatherLoanCtxt {
4444
bccx,
4545
all_loans: Vec::new(),
46-
item_ub: region::Scope::Node(bccx.tcx.hir.body(body).value.hir_id.local_id),
46+
item_ub: region::Scope {
47+
id: bccx.tcx.hir.body(body).value.hir_id.local_id,
48+
data: region::ScopeData::Node
49+
},
4750
move_data: MoveData::default(),
4851
move_error_collector: move_error::MoveErrorCollector::new(),
4952
};
@@ -375,7 +378,10 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
375378
};
376379
debug!("loan_scope = {:?}", loan_scope);
377380

378-
let borrow_scope = region::Scope::Node(borrow_id);
381+
let borrow_scope = region::Scope {
382+
id: borrow_id,
383+
data: region::ScopeData::Node
384+
};
379385
let gen_scope = self.compute_gen_scope(borrow_scope, loan_scope);
380386
debug!("gen_scope = {:?}", gen_scope);
381387

‎src/librustc_borrowck/borrowck/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ impl<'a, 'tcx> LoanPath<'tcx> {
441441
LpUpvar(upvar_id) => {
442442
let block_id = closure_to_block(upvar_id.closure_expr_id, bccx.tcx);
443443
let hir_id = bccx.tcx.hir.node_to_hir_id(block_id);
444-
region::Scope::Node(hir_id.local_id)
444+
region::Scope { id: hir_id.local_id, data: region::ScopeData::Node }
445445
}
446446
LpDowncast(ref base, _) |
447447
LpExtend(ref base, ..) => base.kill_scope(bccx),

‎src/librustc_driver/test.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
198198

199199
pub fn create_region_hierarchy(&mut self, rh: &RH,
200200
parent: (region::Scope, region::ScopeDepth)) {
201-
let me = region::Scope::Node(rh.id);
201+
let me = region::Scope { id: rh.id, data: region::ScopeData::Node };
202202
self.region_scope_tree.record_scope_parent(me, Some(parent));
203203
for child_rh in rh.sub {
204204
self.create_region_hierarchy(child_rh, (me, parent.1 + 1));
@@ -209,7 +209,10 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
209209
// creates a region hierarchy where 1 is root, 10 and 11 are
210210
// children of 1, etc
211211

212-
let dscope = region::Scope::Destruction(hir::ItemLocalId(1));
212+
let dscope = region::Scope {
213+
id: hir::ItemLocalId(1),
214+
data: region::ScopeData::Destruction
215+
};
213216
self.region_scope_tree.record_scope_parent(dscope, None);
214217
self.create_region_hierarchy(&RH {
215218
id: hir::ItemLocalId(1),
@@ -355,7 +358,10 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
355358
}
356359

357360
pub fn t_rptr_scope(&self, id: u32) -> Ty<'tcx> {
358-
let r = ty::ReScope(region::Scope::Node(hir::ItemLocalId(id)));
361+
let r = ty::ReScope(region::Scope {
362+
id: hir::ItemLocalId(id),
363+
data: region::ScopeData::Node
364+
});
359365
self.infcx.tcx.mk_imm_ref(self.infcx.tcx.mk_region(r), self.tcx().types.isize)
360366
}
361367

‎src/librustc_mir/build/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'tcx> CFG<'tcx> {
5151
source_info: SourceInfo,
5252
region_scope: region::Scope) {
5353
if tcx.emit_end_regions() {
54-
if let region::ScopeData::CallSite = region_scope.data() {
54+
if let region::ScopeData::CallSite = region_scope.data {
5555
// The CallSite scope (aka the root scope) is sort of weird, in that it is
5656
// supposed to "separate" the "interior" and "exterior" of a closure. Being
5757
// that, it is not really a part of the region hierarchy, but for some

‎src/librustc_mir/build/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,14 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
550550
upvar_decls);
551551

552552
let fn_def_id = tcx.hir.local_def_id(fn_id);
553-
let call_site_scope = region::Scope::CallSite(body.value.hir_id.local_id);
554-
let arg_scope = region::Scope::Arguments(body.value.hir_id.local_id);
553+
let call_site_scope = region::Scope {
554+
id: body.value.hir_id.local_id,
555+
data: region::ScopeData::CallSite
556+
};
557+
let arg_scope = region::Scope {
558+
id: body.value.hir_id.local_id,
559+
data: region::ScopeData::Arguments
560+
};
555561
let mut block = START_BLOCK;
556562
let source_info = builder.source_info(span);
557563
let call_site_s = (call_site_scope, source_info);

‎src/librustc_mir/build/scope.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
565565
// The outermost scope (`scopes[0]`) will be the `CallSiteScope`.
566566
// We want `scopes[1]`, which is the `ParameterScope`.
567567
assert!(self.scopes.len() >= 2);
568-
assert!(match self.scopes[1].region_scope.data() {
568+
assert!(match self.scopes[1].region_scope.data {
569569
region::ScopeData::Arguments => true,
570570
_ => false,
571571
});

‎src/librustc_mir/dataflow/impls/borrows.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
157157
) -> Self {
158158
let scope_tree = tcx.region_scope_tree(def_id);
159159
let root_scope = body_id.map(|body_id| {
160-
region::Scope::CallSite(tcx.hir.body(body_id).value.hir_id.local_id)
160+
region::Scope {
161+
id: tcx.hir.body(body_id).value.hir_id.local_id,
162+
data: region::ScopeData::CallSite
163+
}
161164
});
162165

163166
let mut borrows_out_of_scope_at_location = FxHashMap();

‎src/librustc_mir/hair/cx/block.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Block {
2727
cx.region_scope_tree.opt_destruction_scope(self.hir_id.local_id);
2828
Block {
2929
targeted_by_break: self.targeted_by_break,
30-
region_scope: region::Scope::Node(self.hir_id.local_id),
30+
region_scope: region::Scope {
31+
id: self.hir_id.local_id,
32+
data: region::ScopeData::Node
33+
},
3134
opt_destruction_scope,
3235
span: self.span,
3336
stmts,
@@ -59,7 +62,10 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
5962
hir::StmtKind::Semi(ref expr, _) => {
6063
result.push(StmtRef::Mirror(Box::new(Stmt {
6164
kind: StmtKind::Expr {
62-
scope: region::Scope::Node(hir_id.local_id),
65+
scope: region::Scope {
66+
id: hir_id.local_id,
67+
data: region::ScopeData::Node
68+
},
6369
expr: expr.to_ref(),
6470
},
6571
opt_destruction_scope: opt_dxn_ext,
@@ -71,10 +77,11 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
7177
// ignore for purposes of the MIR
7278
}
7379
hir::DeclKind::Local(ref local) => {
74-
let remainder_scope = region::Scope::Remainder(
75-
block_id,
76-
region::FirstStatementIndex::new(index),
77-
);
80+
let remainder_scope = region::Scope {
81+
id: block_id,
82+
data: region::ScopeData::Remainder(
83+
region::FirstStatementIndex::new(index)),
84+
};
7885

7986
let mut pattern = cx.pattern_from_hir(&local.pat);
8087

@@ -94,7 +101,10 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
94101
result.push(StmtRef::Mirror(Box::new(Stmt {
95102
kind: StmtKind::Let {
96103
remainder_scope: remainder_scope,
97-
init_scope: region::Scope::Node(hir_id.local_id),
104+
init_scope: region::Scope {
105+
id: hir_id.local_id,
106+
data: region::ScopeData::Node
107+
},
98108
pattern,
99109
initializer: local.init.to_ref(),
100110
lint_level: cx.lint_level_of(local.id),

‎src/librustc_mir/hair/cx/expr.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
2727

2828
fn make_mirror<'a, 'gcx>(self, cx: &mut Cx<'a, 'gcx, 'tcx>) -> Expr<'tcx> {
2929
let temp_lifetime = cx.region_scope_tree.temporary_scope(self.hir_id.local_id);
30-
let expr_scope = region::Scope::Node(self.hir_id.local_id);
30+
let expr_scope = region::Scope {
31+
id: self.hir_id.local_id,
32+
data: region::ScopeData::Node
33+
};
3134

3235
debug!("Expr::make_mirror(): id={}, span={:?}", self.id, self.span);
3336

@@ -148,7 +151,10 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
148151
// Convert this to a suitable `&foo` and
149152
// then an unsafe coercion. Limit the region to be just this
150153
// expression.
151-
let region = ty::ReScope(region::Scope::Node(hir_expr.hir_id.local_id));
154+
let region = ty::ReScope(region::Scope {
155+
id: hir_expr.hir_id.local_id,
156+
data: region::ScopeData::Node
157+
});
152158
let region = cx.tcx.mk_region(region);
153159
expr = Expr {
154160
temp_lifetime,
@@ -581,7 +587,10 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
581587
hir::ExprKind::Break(dest, ref value) => {
582588
match dest.target_id {
583589
Ok(target_id) => ExprKind::Break {
584-
label: region::Scope::Node(cx.tcx.hir.node_to_hir_id(target_id).local_id),
590+
label: region::Scope {
591+
id: cx.tcx.hir.node_to_hir_id(target_id).local_id,
592+
data: region::ScopeData::Node
593+
},
585594
value: value.to_ref(),
586595
},
587596
Err(err) => bug!("invalid loop id for break: {}", err)
@@ -590,7 +599,10 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
590599
hir::ExprKind::Continue(dest) => {
591600
match dest.target_id {
592601
Ok(loop_id) => ExprKind::Continue {
593-
label: region::Scope::Node(cx.tcx.hir.node_to_hir_id(loop_id).local_id),
602+
label: region::Scope {
603+
id: cx.tcx.hir.node_to_hir_id(loop_id).local_id,
604+
data: region::ScopeData::Node
605+
},
594606
},
595607
Err(err) => bug!("invalid loop id for continue: {}", err)
596608
}

‎src/librustc_typeck/check/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,10 @@ impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> {
622622
let body_id = item_id.and_then(|id| tcx.hir.maybe_body_owned_by(id));
623623
let implicit_region_bound = body_id.map(|body_id| {
624624
let body = tcx.hir.body(body_id);
625-
tcx.mk_region(ty::ReScope(region::Scope::CallSite(body.value.hir_id.local_id)))
625+
tcx.mk_region(ty::ReScope(region::Scope {
626+
id: body.value.hir_id.local_id,
627+
data: region::ScopeData::CallSite
628+
}))
626629
});
627630

628631
Inherited {

‎src/librustc_typeck/check/regionck.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,10 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
307307
let body_id = body.id();
308308
self.body_id = body_id.node_id;
309309

310-
let call_site = region::Scope::CallSite(body.value.hir_id.local_id);
310+
let call_site = region::Scope {
311+
id: body.value.hir_id.local_id,
312+
data: region::ScopeData::CallSite
313+
};
311314
self.call_site_scope = Some(call_site);
312315

313316
let fn_sig = {
@@ -333,7 +336,12 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
333336
&fn_sig_tys[..],
334337
body_id.node_id,
335338
span);
336-
self.link_fn_args(region::Scope::Node(body.value.hir_id.local_id), &body.arguments);
339+
self.link_fn_args(
340+
region::Scope {
341+
id: body.value.hir_id.local_id,
342+
data: region::ScopeData::Node
343+
},
344+
&body.arguments);
337345
self.visit_body(body);
338346
self.visit_region_obligations(body_id.node_id);
339347

@@ -483,7 +491,10 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> {
483491
let expr_ty = self.resolve_node_type(expr.hir_id);
484492
// the region corresponding to this expression
485493
let expr_region = self.tcx.mk_region(ty::ReScope(
486-
region::Scope::Node(expr.hir_id.local_id)));
494+
region::Scope {
495+
id: expr.hir_id.local_id,
496+
data: region::ScopeData::Node
497+
}));
487498
self.type_must_outlive(infer::ExprTypeIsNotInScope(expr_ty, expr.span),
488499
expr_ty, expr_region);
489500

@@ -766,7 +777,10 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
766777
// call occurs.
767778
//
768779
// FIXME(#6268) to support nested method calls, should be callee_id
769-
let callee_scope = region::Scope::Node(call_expr.hir_id.local_id);
780+
let callee_scope = region::Scope {
781+
id: call_expr.hir_id.local_id,
782+
data: region::ScopeData::Node
783+
};
770784
let callee_region = self.tcx.mk_region(ty::ReScope(callee_scope));
771785

772786
debug!("callee_region={:?}", callee_region);
@@ -819,7 +833,10 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
819833
self.check_safety_of_rvalue_destructor_if_necessary(&cmt, expr.span);
820834

821835
let expr_region = self.tcx.mk_region(ty::ReScope(
822-
region::Scope::Node(expr.hir_id.local_id)));
836+
region::Scope {
837+
id: expr.hir_id.local_id,
838+
data: region::ScopeData::Node
839+
}));
823840
for adjustment in adjustments {
824841
debug!("constrain_adjustments: adjustment={:?}, cmt={:?}",
825842
adjustment, cmt);
@@ -913,7 +930,10 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
913930
debug!("constrain_index(index_expr=?, indexed_ty={}",
914931
self.ty_to_string(indexed_ty));
915932

916-
let r_index_expr = ty::ReScope(region::Scope::Node(index_expr.hir_id.local_id));
933+
let r_index_expr = ty::ReScope(region::Scope {
934+
id: index_expr.hir_id.local_id,
935+
data: region::ScopeData::Node
936+
});
917937
if let ty::Ref(r_ptr, r_ty, _) = indexed_ty.sty {
918938
match r_ty.sty {
919939
ty::Slice(_) | ty::Str => {
@@ -1072,7 +1092,10 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
10721092
}
10731093

10741094
adjustment::AutoBorrow::RawPtr(m) => {
1075-
let r = self.tcx.mk_region(ty::ReScope(region::Scope::Node(expr.hir_id.local_id)));
1095+
let r = self.tcx.mk_region(ty::ReScope(region::Scope {
1096+
id: expr.hir_id.local_id,
1097+
data: region::ScopeData::Node
1098+
}));
10761099
self.link_region(expr.span, r, ty::BorrowKind::from_mutbl(m), expr_cmt);
10771100
}
10781101
}

0 commit comments

Comments
 (0)
Please sign in to comment.