Skip to content

Commit

Permalink
Get the type of a local from local_decls in schedule_drop
Browse files Browse the repository at this point in the history
Passing around a separate type is unnecessary and error-prone.
  • Loading branch information
matthewjasper committed Sep 29, 2019
1 parent d046ffd commit 1dfc3e7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 17 deletions.
2 changes: 0 additions & 2 deletions src/librustc_mir/build/expr/as_rvalue.rs
Expand Up @@ -128,7 +128,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
expr_span,
scope,
result,
expr.ty,
);
}

Expand Down Expand Up @@ -569,7 +568,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
upvar_span,
temp_lifetime,
temp,
upvar_ty,
);
}

Expand Down
1 change: 0 additions & 1 deletion src/librustc_mir/build/expr/as_temp.rs
Expand Up @@ -103,7 +103,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
expr_span,
temp_lifetime,
temp,
expr_ty,
DropKind::Storage,
);
}
Expand Down
5 changes: 1 addition & 4 deletions src/librustc_mir/build/matches/mod.rs
Expand Up @@ -535,21 +535,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
kind: StatementKind::StorageLive(local_id),
},
);
let var_ty = self.local_decls[local_id].ty;
let region_scope = self.hir.region_scope_tree.var_scope(var.local_id);
self.schedule_drop(span, region_scope, local_id, var_ty, DropKind::Storage);
self.schedule_drop(span, region_scope, local_id, DropKind::Storage);
Place::from(local_id)
}

pub fn schedule_drop_for_binding(&mut self, var: HirId, span: Span, for_guard: ForGuard) {
let local_id = self.var_local_id(var, for_guard);
let var_ty = self.local_decls[local_id].ty;
let region_scope = self.hir.region_scope_tree.var_scope(var.local_id);
self.schedule_drop(
span,
region_scope,
local_id,
var_ty,
DropKind::Value,
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/build/mod.rs
Expand Up @@ -829,12 +829,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Function arguments always get the first Local indices after the return place
let local = Local::new(index + 1);
let place = Place::from(local);
let &ArgInfo(ty, opt_ty_info, arg_opt, ref self_binding) = arg_info;
let &ArgInfo(_, opt_ty_info, arg_opt, ref self_binding) = arg_info;

// Make sure we drop (parts of) the argument even when not matched on.
self.schedule_drop(
arg_opt.as_ref().map_or(ast_body.span, |arg| arg.pat.span),
argument_scope, local, ty, DropKind::Value,
argument_scope, local, DropKind::Value,
);

if let Some(arg) = arg_opt {
Expand Down
14 changes: 6 additions & 8 deletions src/librustc_mir/build/scope.rs
Expand Up @@ -85,7 +85,6 @@ should go to.
use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder, CFG};
use crate::hair::{Expr, ExprRef, LintLevel};
use rustc::middle::region;
use rustc::ty::Ty;
use rustc::hir;
use rustc::mir::*;
use syntax_pos::{DUMMY_SP, Span};
Expand Down Expand Up @@ -173,11 +172,11 @@ struct BreakableScope<'tcx> {
region_scope: region::Scope,
/// Where the body of the loop begins. `None` if block
continue_block: Option<BasicBlock>,
/// Block to branch into when the loop or block terminates (either by being `break`-en out
/// from, or by having its condition to become false)
/// Block to branch into when the loop or block terminates (either by being
/// `break`-en out from, or by having its condition to become false)
break_block: BasicBlock,
/// The destination of the loop/block expression itself (i.e., where to put the result of a
/// `break` expression)
/// The destination of the loop/block expression itself (i.e., where to put
/// the result of a `break` expression)
break_destination: Place<'tcx>,
}

Expand Down Expand Up @@ -728,10 +727,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
span: Span,
region_scope: region::Scope,
local: Local,
place_ty: Ty<'tcx>,
) {
self.schedule_drop(span, region_scope, local, place_ty, DropKind::Storage);
self.schedule_drop(span, region_scope, local, place_ty, DropKind::Value);
self.schedule_drop(span, region_scope, local, DropKind::Storage);
self.schedule_drop(span, region_scope, local, DropKind::Value);
}

/// Indicates that `place` should be dropped on exit from
Expand Down

0 comments on commit 1dfc3e7

Please sign in to comment.