diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index 1b97480920321..6b9c0aac52e79 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -556,7 +556,10 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { target_scope: region::Scope, to_index: CFGIndex) { let mut data = CFGEdgeData { exiting_scopes: vec![] }; - let mut scope = region::Scope::Node(from_expr.hir_id.local_id); + let mut scope = region::Scope { + id: from_expr.hir_id.local_id, + data: region::ScopeData::Node + }; let region_scope_tree = self.tcx.region_scope_tree(self.owner_def_id); while scope != target_scope { data.exiting_scopes.push(scope.item_local_id()); @@ -586,8 +589,11 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { Ok(loop_id) => { for b in &self.breakable_block_scopes { if b.block_expr_id == self.tcx.hir.node_to_hir_id(loop_id).local_id { - let scope_id = self.tcx.hir.node_to_hir_id(loop_id).local_id; - return (region::Scope::Node(scope_id), match scope_cf_kind { + let scope = region::Scope { + id: self.tcx.hir.node_to_hir_id(loop_id).local_id, + data: region::ScopeData::Node + }; + return (scope, match scope_cf_kind { ScopeCfKind::Break => b.break_index, ScopeCfKind::Continue => bug!("can't continue to block"), }); @@ -595,8 +601,11 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } for l in &self.loop_scopes { if l.loop_id == self.tcx.hir.node_to_hir_id(loop_id).local_id { - let scope_id = self.tcx.hir.node_to_hir_id(loop_id).local_id; - return (region::Scope::Node(scope_id), match scope_cf_kind { + let scope = region::Scope { + id: self.tcx.hir.node_to_hir_id(loop_id).local_id, + data: region::ScopeData::Node + }; + return (scope, match scope_cf_kind { ScopeCfKind::Break => l.break_index, ScopeCfKind::Continue => l.continue_index, }); diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index a0c96554c91f1..cf76c3b7e02df 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -118,7 +118,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { return; } }; - let scope_decorated_tag = match scope.data() { + let scope_decorated_tag = match scope.data { region::ScopeData::Node => tag, region::ScopeData::CallSite => "scope of call-site for function", region::ScopeData::Arguments => "scope of function body", diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 356992b22146d..469ae04c0fdc1 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -317,7 +317,11 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { debug!("consume_body: arg_ty = {:?}", arg_ty); let fn_body_scope_r = - self.tcx().mk_region(ty::ReScope(region::Scope::Node(body.value.hir_id.local_id))); + self.tcx().mk_region(ty::ReScope( + region::Scope { + id: body.value.hir_id.local_id, + data: region::ScopeData::Node + })); let arg_cmt = Rc::new(self.mc.cat_rvalue( arg.hir_id, arg.pat.span, @@ -558,7 +562,10 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { _ => { if let Some(def) = self.mc.tables.type_dependent_defs().get(call.hir_id) { let def_id = def.def_id(); - let call_scope = region::Scope::Node(call.hir_id.local_id); + let call_scope = region::Scope { + id: call.hir_id.local_id, + data: region::ScopeData::Node + }; match OverloadedCallType::from_method_id(self.tcx(), def_id) { FnMutOverloadedCall => { let call_scope_r = self.tcx().mk_region(ty::ReScope(call_scope)); @@ -766,7 +773,10 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { // treated as borrowing it for the enclosing temporary // scope. let r = self.tcx().mk_region(ty::ReScope( - region::Scope::Node(expr.hir_id.local_id))); + region::Scope { + id: expr.hir_id.local_id, + data: region::ScopeData::Node + })); self.delegate.borrow(expr.id, expr.span, diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 2f99743cfbdca..788fbcef17163 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -102,8 +102,8 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher, /// generated via deriving here. #[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Copy, RustcEncodable, RustcDecodable)] pub struct Scope { - pub(crate) id: hir::ItemLocalId, - pub(crate) data: ScopeData, + pub id: hir::ItemLocalId, + pub data: ScopeData, } impl fmt::Debug for Scope { @@ -172,48 +172,6 @@ impl_stable_hash_for!(struct ::middle::region::FirstStatementIndex { private }); #[cfg(not(stage0))] static ASSERT: () = [()][!(mem::size_of::() == 4) as usize]; -#[allow(non_snake_case)] -impl Scope { - #[inline] - pub fn data(self) -> ScopeData { - self.data - } - - #[inline] - pub fn new(id: hir::ItemLocalId, data: ScopeData) -> Self { - Scope { id, data } - } - - #[inline] - pub fn Node(id: hir::ItemLocalId) -> Self { - Self::new(id, ScopeData::Node) - } - - #[inline] - pub fn CallSite(id: hir::ItemLocalId) -> Self { - Self::new(id, ScopeData::CallSite) - } - - #[inline] - pub fn Arguments(id: hir::ItemLocalId) -> Self { - Self::new(id, ScopeData::Arguments) - } - - #[inline] - pub fn Destruction(id: hir::ItemLocalId) -> Self { - Self::new(id, ScopeData::Destruction) - } - - #[inline] - pub fn Remainder( - id: hir::ItemLocalId, - first: FirstStatementIndex, - ) -> Self { - Self::new(id, ScopeData::Remainder(first)) - } -} - - impl Scope { /// Returns a item-local id associated with this scope. /// @@ -244,7 +202,7 @@ impl Scope { return DUMMY_SP; } let span = tcx.hir.span(node_id); - if let ScopeData::Remainder(first_statement_index) = self.data() { + if let ScopeData::Remainder(first_statement_index) = self.data { if let Node::Block(ref blk) = tcx.hir.get(node_id) { // Want span for scope starting after the // indexed statement and ending at end of @@ -498,7 +456,7 @@ impl<'tcx> ScopeTree { } // record the destruction scopes for later so we can query them - if let ScopeData::Destruction = child.data() { + if let ScopeData::Destruction = child.data { self.destruction_scopes.insert(child.item_local_id(), child); } } @@ -578,10 +536,10 @@ impl<'tcx> ScopeTree { // if there's one. Static items, for instance, won't // have an enclosing scope, hence no scope will be // returned. - let mut id = Scope::Node(expr_id); + let mut id = Scope { id: expr_id, data: ScopeData::Node }; while let Some(&(p, _)) = self.parent_map.get(&id) { - match p.data() { + match p.data { ScopeData::Destruction => { debug!("temporary_scope({:?}) = {:?} [enclosing]", expr_id, id); @@ -637,7 +595,7 @@ impl<'tcx> ScopeTree { /// Returns the id of the innermost containing body pub fn containing_body(&self, mut scope: Scope)-> Option { loop { - if let ScopeData::CallSite = scope.data() { + if let ScopeData::CallSite = scope.data { return Some(scope.item_local_id()); } @@ -730,7 +688,7 @@ impl<'tcx> ScopeTree { self.root_body.unwrap().local_id }); - Scope::CallSite(scope) + Scope { id: scope, data: ScopeData::CallSite } } /// Assuming that the provided region was defined within this `ScopeTree`, @@ -750,7 +708,7 @@ impl<'tcx> ScopeTree { let param_owner_id = tcx.hir.as_local_node_id(param_owner).unwrap(); let body_id = tcx.hir.body_owned_by(param_owner_id); - Scope::CallSite(tcx.hir.body(body_id).value.hir_id.local_id) + Scope { id: tcx.hir.body(body_id).value.hir_id.local_id, data: ScopeData::CallSite } } /// 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: // except for the first such subscope, which has the // block itself as a parent. visitor.enter_scope( - Scope::Remainder(blk.hir_id.local_id, FirstStatementIndex::new(i)) + Scope { + id: blk.hir_id.local_id, + data: ScopeData::Remainder(FirstStatementIndex::new(i)) + } ); visitor.cx.var_parent = visitor.cx.parent; } @@ -879,7 +840,7 @@ fn resolve_arm<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, arm: & } fn resolve_pat<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, pat: &'tcx hir::Pat) { - visitor.record_child_scope(Scope::Node(pat.hir_id.local_id)); + visitor.record_child_scope(Scope { id: pat.hir_id.local_id, data: ScopeData::Node }); // If this is a binding then record the lifetime of that binding. if let PatKind::Binding(..) = pat.node { @@ -1008,7 +969,7 @@ fn resolve_expr<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, expr: if let hir::ExprKind::Yield(..) = expr.node { // Mark this expr's scope and all parent scopes as containing `yield`. - let mut scope = Scope::Node(expr.hir_id.local_id); + let mut scope = Scope { id: expr.hir_id.local_id, data: ScopeData::Node }; loop { visitor.scope_tree.yield_in_scope.insert(scope, (expr.span, visitor.expr_and_pat_count)); @@ -1016,7 +977,7 @@ fn resolve_expr<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, expr: // Keep traversing up while we can. match visitor.scope_tree.parent_map.get(&scope) { // Don't cross from closure bodies to their parent. - Some(&(superscope, _)) => match superscope.data() { + Some(&(superscope, _)) => match superscope.data { ScopeData::CallSite => break, _ => scope = superscope }, @@ -1280,9 +1241,9 @@ impl<'a, 'tcx> RegionResolutionVisitor<'a, 'tcx> { // account for the destruction scope representing the scope of // the destructors that run immediately after it completes. if self.terminating_scopes.contains(&id) { - self.enter_scope(Scope::Destruction(id)); + self.enter_scope(Scope { id, data: ScopeData::Destruction }); } - self.enter_scope(Scope::Node(id)); + self.enter_scope(Scope { id, data: ScopeData::Node }); } } @@ -1315,8 +1276,8 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionResolutionVisitor<'a, 'tcx> { } self.cx.root_id = Some(body.value.hir_id.local_id); - self.enter_scope(Scope::CallSite(body.value.hir_id.local_id)); - self.enter_scope(Scope::Arguments(body.value.hir_id.local_id)); + self.enter_scope(Scope { id: body.value.hir_id.local_id, data: ScopeData::CallSite }); + self.enter_scope(Scope { id: body.value.hir_id.local_id, data: ScopeData::Arguments }); // The arguments and `self` are parented to the fn. self.cx.var_parent = self.cx.parent.take(); diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 5ffb77dda688a..9a1add26bb0b4 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -769,7 +769,7 @@ define_print! { write!(f, "{}", br) } ty::ReScope(scope) if cx.identify_regions => { - match scope.data() { + match scope.data { region::ScopeData::Node => write!(f, "'{}s", scope.item_local_id().as_usize()), region::ScopeData::CallSite => diff --git a/src/librustc_borrowck/borrowck/check_loans.rs b/src/librustc_borrowck/borrowck/check_loans.rs index 1af117c97f569..40bfbf1596a47 100644 --- a/src/librustc_borrowck/borrowck/check_loans.rs +++ b/src/librustc_borrowck/borrowck/check_loans.rs @@ -767,8 +767,12 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { let mut ret = UseOk; + let scope = region::Scope { + id: expr_id, + data: region::ScopeData::Node + }; self.each_in_scope_loan_affecting_path( - region::Scope::Node(expr_id), use_path, |loan| { + scope, use_path, |loan| { if !compatible_borrow_kinds(loan.kind, borrow_kind) { ret = UseWhileBorrowed(loan.loan_path.clone(), loan.span); false @@ -886,7 +890,10 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { // Check that we don't invalidate any outstanding loans if let Some(loan_path) = opt_loan_path(assignee_cmt) { - let scope = region::Scope::Node(assignment_id); + let scope = region::Scope { + id: assignment_id, + data: region::ScopeData::Node + }; self.each_in_scope_loan_affecting_path(scope, &loan_path, |loan| { self.report_illegal_mutation(assignment_span, &loan_path, loan); false diff --git a/src/librustc_borrowck/borrowck/gather_loans/mod.rs b/src/librustc_borrowck/borrowck/gather_loans/mod.rs index 6c83e2dd1c206..dc400c6ef3ead 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/mod.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/mod.rs @@ -43,7 +43,10 @@ pub fn gather_loans_in_fn<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, let mut glcx = GatherLoanCtxt { bccx, all_loans: Vec::new(), - item_ub: region::Scope::Node(bccx.tcx.hir.body(body).value.hir_id.local_id), + item_ub: region::Scope { + id: bccx.tcx.hir.body(body).value.hir_id.local_id, + data: region::ScopeData::Node + }, move_data: MoveData::default(), move_error_collector: move_error::MoveErrorCollector::new(), }; @@ -375,7 +378,10 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> { }; debug!("loan_scope = {:?}", loan_scope); - let borrow_scope = region::Scope::Node(borrow_id); + let borrow_scope = region::Scope { + id: borrow_id, + data: region::ScopeData::Node + }; let gen_scope = self.compute_gen_scope(borrow_scope, loan_scope); debug!("gen_scope = {:?}", gen_scope); diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index ad45c5429a512..6c0a8c23de93e 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -441,7 +441,7 @@ impl<'a, 'tcx> LoanPath<'tcx> { LpUpvar(upvar_id) => { let block_id = closure_to_block(upvar_id.closure_expr_id, bccx.tcx); let hir_id = bccx.tcx.hir.node_to_hir_id(block_id); - region::Scope::Node(hir_id.local_id) + region::Scope { id: hir_id.local_id, data: region::ScopeData::Node } } LpDowncast(ref base, _) | LpExtend(ref base, ..) => base.kill_scope(bccx), diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index ff35371976aa4..0a7bd3d97022d 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -198,7 +198,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> { pub fn create_region_hierarchy(&mut self, rh: &RH, parent: (region::Scope, region::ScopeDepth)) { - let me = region::Scope::Node(rh.id); + let me = region::Scope { id: rh.id, data: region::ScopeData::Node }; self.region_scope_tree.record_scope_parent(me, Some(parent)); for child_rh in rh.sub { self.create_region_hierarchy(child_rh, (me, parent.1 + 1)); @@ -209,7 +209,10 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> { // creates a region hierarchy where 1 is root, 10 and 11 are // children of 1, etc - let dscope = region::Scope::Destruction(hir::ItemLocalId(1)); + let dscope = region::Scope { + id: hir::ItemLocalId(1), + data: region::ScopeData::Destruction + }; self.region_scope_tree.record_scope_parent(dscope, None); self.create_region_hierarchy(&RH { id: hir::ItemLocalId(1), @@ -355,7 +358,10 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> { } pub fn t_rptr_scope(&self, id: u32) -> Ty<'tcx> { - let r = ty::ReScope(region::Scope::Node(hir::ItemLocalId(id))); + let r = ty::ReScope(region::Scope { + id: hir::ItemLocalId(id), + data: region::ScopeData::Node + }); self.infcx.tcx.mk_imm_ref(self.infcx.tcx.mk_region(r), self.tcx().types.isize) } diff --git a/src/librustc_mir/build/cfg.rs b/src/librustc_mir/build/cfg.rs index d46b0813ca703..8e40fd19941b3 100644 --- a/src/librustc_mir/build/cfg.rs +++ b/src/librustc_mir/build/cfg.rs @@ -51,7 +51,7 @@ impl<'tcx> CFG<'tcx> { source_info: SourceInfo, region_scope: region::Scope) { if tcx.emit_end_regions() { - if let region::ScopeData::CallSite = region_scope.data() { + if let region::ScopeData::CallSite = region_scope.data { // The CallSite scope (aka the root scope) is sort of weird, in that it is // supposed to "separate" the "interior" and "exterior" of a closure. Being // that, it is not really a part of the region hierarchy, but for some diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 576c91a02b08d..d2061d8eecf5f 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -550,8 +550,14 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>, upvar_decls); let fn_def_id = tcx.hir.local_def_id(fn_id); - let call_site_scope = region::Scope::CallSite(body.value.hir_id.local_id); - let arg_scope = region::Scope::Arguments(body.value.hir_id.local_id); + let call_site_scope = region::Scope { + id: body.value.hir_id.local_id, + data: region::ScopeData::CallSite + }; + let arg_scope = region::Scope { + id: body.value.hir_id.local_id, + data: region::ScopeData::Arguments + }; let mut block = START_BLOCK; let source_info = builder.source_info(span); let call_site_s = (call_site_scope, source_info); diff --git a/src/librustc_mir/build/scope.rs b/src/librustc_mir/build/scope.rs index 1406183955bd4..cc5b08f2a9047 100644 --- a/src/librustc_mir/build/scope.rs +++ b/src/librustc_mir/build/scope.rs @@ -565,7 +565,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { // The outermost scope (`scopes[0]`) will be the `CallSiteScope`. // We want `scopes[1]`, which is the `ParameterScope`. assert!(self.scopes.len() >= 2); - assert!(match self.scopes[1].region_scope.data() { + assert!(match self.scopes[1].region_scope.data { region::ScopeData::Arguments => true, _ => false, }); diff --git a/src/librustc_mir/dataflow/impls/borrows.rs b/src/librustc_mir/dataflow/impls/borrows.rs index 66f020faa87df..93136a0fb83e3 100644 --- a/src/librustc_mir/dataflow/impls/borrows.rs +++ b/src/librustc_mir/dataflow/impls/borrows.rs @@ -157,7 +157,10 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> { ) -> Self { let scope_tree = tcx.region_scope_tree(def_id); let root_scope = body_id.map(|body_id| { - region::Scope::CallSite(tcx.hir.body(body_id).value.hir_id.local_id) + region::Scope { + id: tcx.hir.body(body_id).value.hir_id.local_id, + data: region::ScopeData::CallSite + } }); let mut borrows_out_of_scope_at_location = FxHashMap(); diff --git a/src/librustc_mir/hair/cx/block.rs b/src/librustc_mir/hair/cx/block.rs index b0a60fedfbbc2..2ab0a57a85541 100644 --- a/src/librustc_mir/hair/cx/block.rs +++ b/src/librustc_mir/hair/cx/block.rs @@ -27,7 +27,10 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Block { cx.region_scope_tree.opt_destruction_scope(self.hir_id.local_id); Block { targeted_by_break: self.targeted_by_break, - region_scope: region::Scope::Node(self.hir_id.local_id), + region_scope: region::Scope { + id: self.hir_id.local_id, + data: region::ScopeData::Node + }, opt_destruction_scope, span: self.span, stmts, @@ -59,7 +62,10 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, hir::StmtKind::Semi(ref expr, _) => { result.push(StmtRef::Mirror(Box::new(Stmt { kind: StmtKind::Expr { - scope: region::Scope::Node(hir_id.local_id), + scope: region::Scope { + id: hir_id.local_id, + data: region::ScopeData::Node + }, expr: expr.to_ref(), }, opt_destruction_scope: opt_dxn_ext, @@ -71,10 +77,11 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, // ignore for purposes of the MIR } hir::DeclKind::Local(ref local) => { - let remainder_scope = region::Scope::Remainder( - block_id, - region::FirstStatementIndex::new(index), - ); + let remainder_scope = region::Scope { + id: block_id, + data: region::ScopeData::Remainder( + region::FirstStatementIndex::new(index)), + }; let mut pattern = cx.pattern_from_hir(&local.pat); @@ -94,7 +101,10 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, result.push(StmtRef::Mirror(Box::new(Stmt { kind: StmtKind::Let { remainder_scope: remainder_scope, - init_scope: region::Scope::Node(hir_id.local_id), + init_scope: region::Scope { + id: hir_id.local_id, + data: region::ScopeData::Node + }, pattern, initializer: local.init.to_ref(), lint_level: cx.lint_level_of(local.id), diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 510e7eb9c63f7..3183f0f47eace 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -27,7 +27,10 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr { fn make_mirror<'a, 'gcx>(self, cx: &mut Cx<'a, 'gcx, 'tcx>) -> Expr<'tcx> { let temp_lifetime = cx.region_scope_tree.temporary_scope(self.hir_id.local_id); - let expr_scope = region::Scope::Node(self.hir_id.local_id); + let expr_scope = region::Scope { + id: self.hir_id.local_id, + data: region::ScopeData::Node + }; debug!("Expr::make_mirror(): id={}, span={:?}", self.id, self.span); @@ -148,7 +151,10 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, // Convert this to a suitable `&foo` and // then an unsafe coercion. Limit the region to be just this // expression. - let region = ty::ReScope(region::Scope::Node(hir_expr.hir_id.local_id)); + let region = ty::ReScope(region::Scope { + id: hir_expr.hir_id.local_id, + data: region::ScopeData::Node + }); let region = cx.tcx.mk_region(region); expr = Expr { temp_lifetime, @@ -581,7 +587,10 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, hir::ExprKind::Break(dest, ref value) => { match dest.target_id { Ok(target_id) => ExprKind::Break { - label: region::Scope::Node(cx.tcx.hir.node_to_hir_id(target_id).local_id), + label: region::Scope { + id: cx.tcx.hir.node_to_hir_id(target_id).local_id, + data: region::ScopeData::Node + }, value: value.to_ref(), }, 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>, hir::ExprKind::Continue(dest) => { match dest.target_id { Ok(loop_id) => ExprKind::Continue { - label: region::Scope::Node(cx.tcx.hir.node_to_hir_id(loop_id).local_id), + label: region::Scope { + id: cx.tcx.hir.node_to_hir_id(loop_id).local_id, + data: region::ScopeData::Node + }, }, Err(err) => bug!("invalid loop id for continue: {}", err) } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index aa27fe528e1fd..db0c4fdb03ae6 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -622,7 +622,10 @@ impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> { let body_id = item_id.and_then(|id| tcx.hir.maybe_body_owned_by(id)); let implicit_region_bound = body_id.map(|body_id| { let body = tcx.hir.body(body_id); - tcx.mk_region(ty::ReScope(region::Scope::CallSite(body.value.hir_id.local_id))) + tcx.mk_region(ty::ReScope(region::Scope { + id: body.value.hir_id.local_id, + data: region::ScopeData::CallSite + })) }); Inherited { diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 05fe0cb9262cc..fbf8afc3be234 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -307,7 +307,10 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { let body_id = body.id(); self.body_id = body_id.node_id; - let call_site = region::Scope::CallSite(body.value.hir_id.local_id); + let call_site = region::Scope { + id: body.value.hir_id.local_id, + data: region::ScopeData::CallSite + }; self.call_site_scope = Some(call_site); let fn_sig = { @@ -333,7 +336,12 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { &fn_sig_tys[..], body_id.node_id, span); - self.link_fn_args(region::Scope::Node(body.value.hir_id.local_id), &body.arguments); + self.link_fn_args( + region::Scope { + id: body.value.hir_id.local_id, + data: region::ScopeData::Node + }, + &body.arguments); self.visit_body(body); self.visit_region_obligations(body_id.node_id); @@ -483,7 +491,10 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> { let expr_ty = self.resolve_node_type(expr.hir_id); // the region corresponding to this expression let expr_region = self.tcx.mk_region(ty::ReScope( - region::Scope::Node(expr.hir_id.local_id))); + region::Scope { + id: expr.hir_id.local_id, + data: region::ScopeData::Node + })); self.type_must_outlive(infer::ExprTypeIsNotInScope(expr_ty, expr.span), expr_ty, expr_region); @@ -766,7 +777,10 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { // call occurs. // // FIXME(#6268) to support nested method calls, should be callee_id - let callee_scope = region::Scope::Node(call_expr.hir_id.local_id); + let callee_scope = region::Scope { + id: call_expr.hir_id.local_id, + data: region::ScopeData::Node + }; let callee_region = self.tcx.mk_region(ty::ReScope(callee_scope)); debug!("callee_region={:?}", callee_region); @@ -819,7 +833,10 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { self.check_safety_of_rvalue_destructor_if_necessary(&cmt, expr.span); let expr_region = self.tcx.mk_region(ty::ReScope( - region::Scope::Node(expr.hir_id.local_id))); + region::Scope { + id: expr.hir_id.local_id, + data: region::ScopeData::Node + })); for adjustment in adjustments { debug!("constrain_adjustments: adjustment={:?}, cmt={:?}", adjustment, cmt); @@ -913,7 +930,10 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { debug!("constrain_index(index_expr=?, indexed_ty={}", self.ty_to_string(indexed_ty)); - let r_index_expr = ty::ReScope(region::Scope::Node(index_expr.hir_id.local_id)); + let r_index_expr = ty::ReScope(region::Scope { + id: index_expr.hir_id.local_id, + data: region::ScopeData::Node + }); if let ty::Ref(r_ptr, r_ty, _) = indexed_ty.sty { match r_ty.sty { ty::Slice(_) | ty::Str => { @@ -1072,7 +1092,10 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { } adjustment::AutoBorrow::RawPtr(m) => { - let r = self.tcx.mk_region(ty::ReScope(region::Scope::Node(expr.hir_id.local_id))); + let r = self.tcx.mk_region(ty::ReScope(region::Scope { + id: expr.hir_id.local_id, + data: region::ScopeData::Node + })); self.link_region(expr.span, r, ty::BorrowKind::from_mutbl(m), expr_cmt); } }