use super::lints;
-/// Construct the MIR for a given def-id.
+/// Construct the MIR for a given `DefId`.
pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'tcx> {
let id = tcx.hir().as_local_node_id(def_id).unwrap();
) => {
(*body_id, ty.span)
}
- Node::AnonConst(hir::AnonConst { body, id, .. }) => {
- (*body, tcx.hir().span(*id))
+ Node::AnonConst(hir::AnonConst { body, hir_id, .. }) => {
+ (*body, tcx.hir().span_by_hir_id(*hir_id))
}
_ => span_bug!(tcx.hir().span(id), "can't build MIR for {:?}", def_id),
Some(ArgInfo(liberated_closure_env_ty(tcx, id, body_id), None, None, None))
}
ty::Generator(..) => {
- let gen_ty = tcx.body_tables(body_id).node_id_to_type(fn_hir_id);
+ let gen_ty = tcx.body_tables(body_id).node_type(fn_hir_id);
Some(ArgInfo(gen_ty, None, None, None))
}
_ => None,
let self_arg;
if let Some(ref fn_decl) = tcx.hir().fn_decl(owner_id) {
let ty_hir_id = fn_decl.inputs[index].hir_id;
- let ty_span = tcx.hir().span(tcx.hir().hir_to_node_id(ty_hir_id));
+ let ty_span = tcx.hir().span_by_hir_id(ty_hir_id);
opt_ty_info = Some(ty_span);
self_arg = if index == 0 && fn_decl.implicit_self.has_implicit_self() {
match fn_decl.implicit_self {
})
}
-/// A pass to lift all the types and substitutions in a Mir
+/// A pass to lift all the types and substitutions in a MIR
/// to the global tcx. Sadly, we don't have a "folder" that
-/// can change 'tcx so we have to transmute afterwards.
+/// can change `'tcx` so we have to transmute afterwards.
struct GlobalizeMir<'a, 'gcx: 'a> {
tcx: TyCtxt<'a, 'gcx, 'gcx>,
span: Span
body_id: hir::BodyId)
-> Ty<'tcx> {
let closure_expr_hir_id = tcx.hir().node_to_hir_id(closure_expr_id);
- let closure_ty = tcx.body_tables(body_id).node_id_to_type(closure_expr_hir_id);
+ let closure_ty = tcx.body_tables(body_id).node_type(closure_expr_hir_id);
let (closure_def_id, closure_substs) = match closure_ty.sty {
ty::Closure(closure_def_id, closure_substs) => (closure_def_id, closure_substs),
fn_span: Span,
arg_count: usize,
- /// the current set of scopes, updated as we traverse;
- /// see the `scope` module for more details
+ /// The current set of scopes, updated as we traverse;
+ /// see the `scope` module for more details.
scopes: Vec<scope::Scope<'tcx>>,
- /// the block-context: each time we build the code within an hair::Block,
+ /// The block-context: each time we build the code within an hair::Block,
/// we push a frame here tracking whether we are building a statement or
/// if we are pushing the tail expression of the block. This is used to
/// embed information in generated temps about whether they were created
/// for a block tail expression or not.
///
/// It would be great if we could fold this into `self.scopes`
- /// somehow; but right now I think that is very tightly tied to
+ /// somehow, but right now I think that is very tightly tied to
/// the code generation in ways that we cannot (or should not)
/// start just throwing new entries onto that vector in order to
/// distinguish the context of EXPR1 from the context of EXPR2 in
- /// `{ STMTS; EXPR1 } + EXPR2`
+ /// `{ STMTS; EXPR1 } + EXPR2`.
block_context: BlockContext,
/// The current unsafe block in scope, even if it is hidden by
- /// a PushUnsafeBlock
+ /// a `PushUnsafeBlock`.
unpushed_unsafe: Safety,
- /// The number of `push_unsafe_block` levels in scope
+ /// The number of `push_unsafe_block` levels in scope.
push_unsafe_count: usize,
- /// the current set of breakables; see the `scope` module for more
- /// details
+ /// The current set of breakables; see the `scope` module for more
+ /// details.
breakable_scopes: Vec<scope::BreakableScope<'tcx>>,
- /// the vector of all scopes that we have created thus far;
- /// we track this for debuginfo later
+ /// The vector of all scopes that we have created thus far;
+ /// we track this for debuginfo later.
source_scopes: IndexVec<SourceScope, SourceScopeData>,
source_scope_local_data: IndexVec<SourceScope, SourceScopeLocalData>,
source_scope: SourceScope,
- /// the guard-context: each time we build the guard expression for
+ /// The guard-context: each time we build the guard expression for
/// a match arm, we push onto this stack, and then pop when we
/// finish building it.
guard_context: Vec<GuardFrame>,
- /// Maps node ids of variable bindings to the `Local`s created for them.
+ /// Maps `NodeId`s of variable bindings to the `Local`s created for them.
/// (A match binding can have two locals; the 2nd is for the arm's guard.)
var_indices: NodeMap<LocalsForNode>,
local_decls: IndexVec<Local, LocalDecl<'tcx>>,
upvar_decls: Vec<UpvarDecl>,
unit_temp: Option<Place<'tcx>>,
- /// cached block with the RESUME terminator; this is created
+ /// Cached block with the `RESUME` terminator; this is created
/// when first set of cleanups are built.
cached_resume_block: Option<BasicBlock>,
- /// cached block with the RETURN terminator
+ /// Cached block with the `RETURN` terminator.
cached_return_block: Option<BasicBlock>,
- /// cached block with the UNREACHABLE terminator
+ /// Cached block with the `UNREACHABLE` terminator.
cached_unreachable_block: Option<BasicBlock>,
}
fn push(&mut self, bf: BlockFrame) { self.0.push(bf); }
fn pop(&mut self) -> Option<BlockFrame> { self.0.pop() }
- /// Traverses the frames on the BlockContext, searching for either
+ /// Traverses the frames on the `BlockContext`, searching for either
/// the first block-tail expression frame with no intervening
/// statement frame.
///
#[derive(Debug)]
enum LocalsForNode {
- /// In the usual case, a node-id for an identifier maps to at most
- /// one Local declaration.
+ /// In the usual case, a `NodeId` for an identifier maps to at most
+ /// one `Local` declaration.
One(Local),
/// The exceptional case is identifiers in a match arm's pattern
/// that are referenced in a guard of that match arm. For these,
- /// we can have `2+k` Locals, where `k` is the number of candidate
- /// patterns (separated by `|`) in the arm.
+ /// we have `2` Locals.
///
/// * `for_arm_body` is the Local used in the arm body (which is
/// just like the `One` case above),
/// * `ref_for_guard` is the Local used in the arm's guard (which
/// is a reference to a temp that is an alias of
/// `for_arm_body`).
- ///
- /// * `vals_for_guard` is the `k` Locals; at most one of them will
- /// get initialized by the arm's execution, and after it is
- /// initialized, `ref_for_guard` will be assigned a reference to
- /// it.
- ///
- /// There reason we have `k` Locals rather than just 1 is to
- /// accommodate some restrictions imposed by two-phase borrows,
- /// which apply when we have a `ref mut` pattern.
- ForGuard { vals_for_guard: Vec<Local>, ref_for_guard: Local, for_arm_body: Local },
+ ForGuard { ref_for_guard: Local, for_arm_body: Local },
}
#[derive(Debug)]
/// P1(id1) if (... (match E2 { P2(id2) if ... => B2 })) => B1,
/// }
///
- /// here, when building for FIXME
+ /// here, when building for FIXME.
locals: Vec<GuardFrameLocal>,
}
-/// ForGuard indicates whether we are talking about:
-/// 1. the temp for a local binding used solely within guard expressions,
-/// 2. the temp that holds reference to (1.), which is actually what the
-/// guard expressions see, or
-/// 3. the temp for use outside of guard expressions.
+/// `ForGuard` indicates whether we are talking about:
+/// 1. The variable for use outside of guard expressions, or
+/// 2. The temp that holds reference to (1.), which is actually what the
+/// guard expressions see.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
enum ForGuard {
- /// The `usize` identifies for which candidate pattern we want the
- /// local binding. We keep a temp per-candidate to accommodate
- /// two-phase borrows (see `LocalsForNode` documentation).
- ValWithinGuard(usize),
RefWithinGuard,
OutsideGuard,
}
(&LocalsForNode::ForGuard { for_arm_body: local_id, .. }, ForGuard::OutsideGuard) =>
local_id,
- (&LocalsForNode::ForGuard { ref vals_for_guard, .. },
- ForGuard::ValWithinGuard(pat_idx)) =>
- vals_for_guard[pat_idx],
-
- (&LocalsForNode::One(_), ForGuard::ValWithinGuard(_)) |
(&LocalsForNode::One(_), ForGuard::RefWithinGuard) =>
bug!("anything with one local should never be within a guard."),
}
}
_ => {
scope = self.declare_bindings(scope, ast_body.span,
- LintLevel::Inherited, &[pattern.clone()],
+ LintLevel::Inherited, &pattern,
matches::ArmHasGuard(false),
Some((Some(&place), span)));
unpack!(block = self.place_into_pattern(block, pattern, &place, false));