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());
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"),
});
}
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,
});
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",
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,
_ => {
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));
// 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,
/// 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 {
#[cfg(not(stage0))]
static ASSERT: () = [()][!(mem::size_of::<ScopeData>() == 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.
///
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
}
// 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);
}
}
// 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);
/// Returns the id of the innermost containing body
pub fn containing_body(&self, mut scope: Scope)-> Option<hir::ItemLocalId> {
loop {
- if let ScopeData::CallSite = scope.data() {
+ if let ScopeData::CallSite = scope.data {
return Some(scope.item_local_id());
}
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`,
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,
// 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;
}
}
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 {
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));
// 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
},
// 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 });
}
}
}
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();
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 =>
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
// 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
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(),
};
};
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);
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),
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));
// 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),
}
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)
}
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
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);
// 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,
});
) -> 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();
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,
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,
// 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);
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),
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);
// 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,
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)
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)
}
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 {
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 = {
&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);
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);
// 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);
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);
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 => {
}
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);
}
}