/// (D9.): DestructionScope for temporaries created during M8.
/// (R10.): Remainder scope for block `'b:`, stmt 1 (let y = ...).
/// (D11.): DestructionScope for temporaries and bindings from block `'b:`.
-/// (D12.): DestructionScope for temporaries created during M1 (e.g. f()).
+/// (D12.): DestructionScope for temporaries created during M1 (e.g., f()).
/// ```
///
/// Note that while the above picture shows the destruction scopes
/// everything after that first `let`. (If you want a scope that
/// includes EXPR_1 as well, then do not use `Scope::Remainder`,
/// but instead another `Scope` that encompasses the whole block,
-/// e.g. `Scope::Node`.
+/// e.g., `Scope::Node`.
///
/// * the subscope with `first_statement_index == 1` is scope of `c`,
/// and thus does not include EXPR_2, but covers the `...`.
impl Scope {
/// Returns a item-local id associated with this scope.
///
- /// NB: likely to be replaced as API is refined; e.g. pnkfelix
+ /// N.B., likely to be replaced as API is refined; e.g., pnkfelix
/// anticipates `fn entry_node_id` and `fn each_exit_node_id`.
pub fn item_local_id(&self) -> hir::ItemLocalId {
self.id
pub fn node_id(&self, tcx: TyCtxt<'_, '_, '_>, scope_tree: &ScopeTree) -> ast::NodeId {
match scope_tree.root_body {
Some(hir_id) => {
- tcx.hir.hir_to_node_id(hir::HirId {
+ tcx.hir().hir_to_node_id(hir::HirId {
owner: hir_id.owner,
local_id: self.item_local_id()
})
if node_id == ast::DUMMY_NODE_ID {
return DUMMY_SP;
}
- let span = tcx.hir.span(node_id);
+ let span = tcx.hir().span(node_id);
if let ScopeData::Remainder(first_statement_index) = self.data {
- if let Node::Block(ref blk) = tcx.hir.get(node_id) {
+ 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
// `blk`; reuse span of `blk` and shift `lo`
-> Scope {
let param_owner = tcx.parent_def_id(br.def_id).unwrap();
- let param_owner_id = tcx.hir.as_local_node_id(param_owner).unwrap();
- let scope = tcx.hir.maybe_body_owned_by(param_owner_id).map(|body_id| {
- tcx.hir.body(body_id).value.hir_id.local_id
+ let param_owner_id = tcx.hir().as_local_node_id(param_owner).unwrap();
+ let scope = tcx.hir().maybe_body_owned_by(param_owner_id).map(|body_id| {
+ tcx.hir().body(body_id).value.hir_id.local_id
}).unwrap_or_else(|| {
// The lifetime was defined on node that doesn't own a body,
// which in practice can only mean a trait or an impl, that
"free_scope: {:?} not recognized by the \
region scope tree for {:?} / {:?}",
param_owner,
- self.root_parent.map(|id| tcx.hir.local_def_id(id)),
+ self.root_parent.map(|id| tcx.hir().local_def_id(id)),
self.root_body.map(|hir_id| DefId::local(hir_id.owner)));
// The trait/impl lifetime is in scope for the method's body.
// on the same function that they ended up being freed in.
assert_eq!(param_owner, fr.scope);
- 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 { id: tcx.hir.body(body_id).value.hir_id.local_id, data: ScopeData::CallSite }
+ 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 { id: tcx.hir().body(body_id).value.hir_id.local_id, data: ScopeData::CallSite }
}
/// Checks whether the given scope contains a `yield`. If so,
// }, other_argument());
//
// Each of the statements within the block is a terminating
- // scope, and thus a temporary (e.g. the result of calling
+ // scope, and thus a temporary (e.g., the result of calling
// `bar()` in the initializer expression for `let inner = ...;`)
// will be cleaned up immediately after its corresponding
- // statement (i.e. `let inner = ...;`) executes.
+ // statement (i.e., `let inner = ...;`) executes.
//
// On the other hand, temporaries associated with evaluating the
// tail expression for the block are assigned lifetimes so that
}
fn resolve_stmt<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, stmt: &'tcx hir::Stmt) {
- let stmt_id = visitor.tcx.hir.node_to_hir_id(stmt.node.id()).local_id;
+ let stmt_id = visitor.tcx.hir().node_to_hir_id(stmt.node.id()).local_id;
debug!("resolve_stmt(stmt.id={:?})", stmt_id);
// Every statement will clean up the temporaries created during
// Manually recurse over closures, because they are the only
// case of nested bodies that share the parent environment.
hir::ExprKind::Closure(.., body, _, _) => {
- let body = visitor.tcx.hir.body(body);
+ let body = visitor.tcx.hir().body(body);
visitor.visit_body(body);
}
// As an exception to the normal rules governing temporary
// lifetimes, initializers in a let have a temporary lifetime
- // of the enclosing block. This means that e.g. a program
+ // of the enclosing block. This means that e.g., a program
// like the following is legal:
//
// let ref x = HashMap::new();
loop {
// Note: give all the expressions matching `ET` with the
// extended temporary lifetime, not just the innermost rvalue,
- // because in codegen if we must compile e.g. `*rvalue()`
+ // because in codegen if we must compile e.g., `*rvalue()`
// into a temporary, we request the temporary scope of the
// outer expression.
visitor.scope_tree.record_rvalue_scope(expr.hir_id.local_id, blk_scope);
fn visit_body(&mut self, body: &'tcx hir::Body) {
let body_id = body.id();
- let owner_id = self.tcx.hir.body_owner(body_id);
+ let owner_id = self.tcx.hir().body_owner(body_id);
debug!("visit_body(id={:?}, span={:?}, body.id={:?}, cx.parent={:?})",
owner_id,
// The body of the every fn is a root scope.
self.cx.parent = self.cx.var_parent;
- if let hir::BodyOwnerKind::Fn = self.tcx.hir.body_owner_kind(owner_id) {
+ if let hir::BodyOwnerKind::Fn = self.tcx.hir().body_owner_kind(owner_id) {
self.visit_expr(&body.value);
} else {
// Only functions have an outer terminating (drop) scope, while
// according to rvalue lifetime semantics, using the same
// syntactical rules used for let initializers.
//
- // E.g. in `let x = &f();`, the temporary holding the result from
+ // e.g., in `let x = &f();`, the temporary holding the result from
// the `f()` call lives for the entirety of the surrounding block.
//
// Similarly, `const X: ... = &f();` would have the result of `f()`
//
// However, `const Y: ... = g(&f());`, like `let y = g(&f());`,
// would *not* let the `f()` temporary escape into an outer scope
- // (i.e. `'static`), which means that after `g` returns, it drops,
+ // (i.e., `'static`), which means that after `g` returns, it drops,
// and all the associated destruction scope rules apply.
self.cx.var_parent = None;
resolve_local(self, None, Some(&body.value));
return tcx.region_scope_tree(closure_base_def_id);
}
- let id = tcx.hir.as_local_node_id(def_id).unwrap();
- let scope_tree = if let Some(body_id) = tcx.hir.maybe_body_owned_by(id) {
+ let id = tcx.hir().as_local_node_id(def_id).unwrap();
+ let scope_tree = if let Some(body_id) = tcx.hir().maybe_body_owned_by(id) {
let mut visitor = RegionResolutionVisitor {
tcx,
scope_tree: ScopeTree::default(),
terminating_scopes: Default::default(),
};
- let body = tcx.hir.body(body_id);
+ let body = tcx.hir().body(body_id);
visitor.scope_tree.root_body = Some(body.value.hir_id);
// If the item is an associated const or a method,
// record its impl/trait parent, as it can also have
// lifetime parameters free in this body.
- match tcx.hir.get(id) {
+ match tcx.hir().get(id) {
Node::ImplItem(_) |
Node::TraitItem(_) => {
- visitor.scope_tree.root_parent = Some(tcx.hir.get_parent(id));
+ visitor.scope_tree.root_parent = Some(tcx.hir().get_parent(id));
}
_ => {}
}