Remove box syntax from rustc_mir_build

This commit is contained in:
est31 2021-08-05 03:16:19 +02:00
parent cbe3afece5
commit 8b0b7ef812
14 changed files with 74 additions and 59 deletions

View File

@ -40,7 +40,7 @@ impl<'tcx> CFG<'tcx> {
) {
self.push(
block,
Statement { source_info, kind: StatementKind::Assign(box (place, rvalue)) },
Statement { source_info, kind: StatementKind::Assign(Box::new((place, rvalue))) },
);
}
@ -51,7 +51,12 @@ impl<'tcx> CFG<'tcx> {
temp: Place<'tcx>,
constant: Constant<'tcx>,
) {
self.push_assign(block, source_info, temp, Rvalue::Use(Operand::Constant(box constant)));
self.push_assign(
block,
source_info,
temp,
Rvalue::Use(Operand::Constant(Box::new(constant))),
);
}
crate fn push_assign_unit(
@ -65,11 +70,11 @@ impl<'tcx> CFG<'tcx> {
block,
source_info,
place,
Rvalue::Use(Operand::Constant(box Constant {
Rvalue::Use(Operand::Constant(Box::new(Constant {
span: source_info.span,
user_ty: None,
literal: ty::Const::zero_sized(tcx, tcx.types.unit).into(),
})),
}))),
);
}
@ -80,7 +85,7 @@ impl<'tcx> CFG<'tcx> {
cause: FakeReadCause,
place: Place<'tcx>,
) {
let kind = StatementKind::FakeRead(box (cause, place));
let kind = StatementKind::FakeRead(Box::new((cause, place)));
let stmt = Statement { source_info, kind };
self.push(block, stmt);
}

View File

@ -111,7 +111,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
match category {
Category::Constant => {
let constant = this.as_constant(expr);
block.and(Operand::Constant(box constant))
block.and(Operand::Constant(Box::new(constant)))
}
Category::Place | Category::Rvalue(..) => {
let operand = unpack!(block = this.as_temp(block, scope, expr, Mutability::Mut));

View File

@ -507,10 +507,10 @@ fn expr_as_place(
Statement {
source_info,
kind: StatementKind::AscribeUserType(
box (
Box::new((
place,
UserTypeProjection { base: annotation_index, projs: vec![] },
),
)),
Variance::Invariant,
),
},
@ -534,10 +534,10 @@ fn expr_as_place(
Statement {
source_info,
kind: StatementKind::AscribeUserType(
box (
Box::new((
Place::from(temp),
UserTypeProjection { base: annotation_index, projs: vec![] },
),
)),
Variance::Invariant,
),
},
@ -691,7 +691,7 @@ fn bounds_check(
lt,
Rvalue::BinaryOp(
BinOp::Lt,
box (Operand::Copy(Place::from(index)), Operand::Copy(len)),
Box::new((Operand::Copy(Place::from(index)), Operand::Copy(len))),
),
);
let msg = BoundsCheck { len: Operand::Move(len), index: Operand::Copy(Place::from(index)) };

View File

@ -73,7 +73,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block,
source_info,
is_min,
Rvalue::BinaryOp(BinOp::Eq, box (arg.to_copy(), minval)),
Rvalue::BinaryOp(BinOp::Eq, Box::new((arg.to_copy(), minval))),
);
block = this.assert(
@ -158,7 +158,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
.map(|f| unpack!(block = this.as_operand(block, scope, &this.thir[f])))
.collect();
block.and(Rvalue::Aggregate(box AggregateKind::Array(el_ty), fields))
block.and(Rvalue::Aggregate(Box::new(AggregateKind::Array(el_ty)), fields))
}
ExprKind::Tuple { ref fields } => {
// see (*) above
@ -169,7 +169,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
.map(|f| unpack!(block = this.as_operand(block, scope, &this.thir[f])))
.collect();
block.and(Rvalue::Aggregate(box AggregateKind::Tuple, fields))
block.and(Rvalue::Aggregate(Box::new(AggregateKind::Tuple), fields))
}
ExprKind::Closure { closure_id, substs, ref upvars, movability, ref fake_reads } => {
// Convert the closure fake reads, if any, from `ExprRef` to mir `Place`
@ -254,19 +254,21 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// We implicitly set the discriminant to 0. See
// librustc_mir/transform/deaggregator.rs for details.
let movability = movability.unwrap();
box AggregateKind::Generator(closure_id, substs, movability)
Box::new(AggregateKind::Generator(closure_id, substs, movability))
}
UpvarSubsts::Closure(substs) => {
Box::new(AggregateKind::Closure(closure_id, substs))
}
UpvarSubsts::Closure(substs) => box AggregateKind::Closure(closure_id, substs),
};
block.and(Rvalue::Aggregate(result, operands))
}
ExprKind::Assign { .. } | ExprKind::AssignOp { .. } => {
block = unpack!(this.stmt_expr(block, expr, None));
block.and(Rvalue::Use(Operand::Constant(box Constant {
block.and(Rvalue::Use(Operand::Constant(Box::new(Constant {
span: expr_span,
user_ty: None,
literal: ty::Const::zero_sized(this.tcx, this.tcx.types.unit).into(),
})))
}))))
}
ExprKind::Yield { .. }
| ExprKind::Literal { .. }
@ -327,7 +329,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block,
source_info,
result_value,
Rvalue::CheckedBinaryOp(op, box (lhs.to_copy(), rhs.to_copy())),
Rvalue::CheckedBinaryOp(op, Box::new((lhs.to_copy(), rhs.to_copy()))),
);
let val_fld = Field::new(0);
let of_fld = Field::new(1);
@ -360,7 +362,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block,
source_info,
is_zero,
Rvalue::BinaryOp(BinOp::Eq, box (rhs.to_copy(), zero)),
Rvalue::BinaryOp(BinOp::Eq, Box::new((rhs.to_copy(), zero))),
);
block = self.assert(block, Operand::Move(is_zero), false, zero_err, span);
@ -381,13 +383,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block,
source_info,
is_neg_1,
Rvalue::BinaryOp(BinOp::Eq, box (rhs.to_copy(), neg_1)),
Rvalue::BinaryOp(BinOp::Eq, Box::new((rhs.to_copy(), neg_1))),
);
self.cfg.push_assign(
block,
source_info,
is_min,
Rvalue::BinaryOp(BinOp::Eq, box (lhs.to_copy(), min)),
Rvalue::BinaryOp(BinOp::Eq, Box::new((lhs.to_copy(), min))),
);
let is_neg_1 = Operand::Move(is_neg_1);
@ -396,14 +398,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block,
source_info,
of,
Rvalue::BinaryOp(BinOp::BitAnd, box (is_neg_1, is_min)),
Rvalue::BinaryOp(BinOp::BitAnd, Box::new((is_neg_1, is_min))),
);
block = self.assert(block, Operand::Move(of), false, overflow_err, span);
}
}
block.and(Rvalue::BinaryOp(op, box (lhs, rhs)))
block.and(Rvalue::BinaryOp(op, Box::new((lhs, rhs))))
}
}

View File

@ -62,16 +62,16 @@ fn as_temp_inner(
assert!(!this.tcx.is_thread_local_static(def_id));
local_decl.internal = true;
local_decl.local_info =
Some(box LocalInfo::StaticRef { def_id, is_thread_local: false });
Some(Box::new(LocalInfo::StaticRef { def_id, is_thread_local: false }));
}
ExprKind::ThreadLocalRef(def_id) => {
assert!(this.tcx.is_thread_local_static(def_id));
local_decl.internal = true;
local_decl.local_info =
Some(box LocalInfo::StaticRef { def_id, is_thread_local: true });
Some(Box::new(LocalInfo::StaticRef { def_id, is_thread_local: true }));
}
ExprKind::Literal { const_id: Some(def_id), .. } => {
local_decl.local_info = Some(box LocalInfo::ConstRef { def_id });
local_decl.local_info = Some(Box::new(LocalInfo::ConstRef { def_id }));
}
_ => {}
}

View File

@ -346,13 +346,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
inferred_ty,
})
});
let adt = box AggregateKind::Adt(
let adt = Box::new(AggregateKind::Adt(
adt_def,
variant_index,
substs,
user_ty,
active_field_index,
);
));
this.cfg.push_assign(
block,
source_info,
@ -403,11 +403,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
thir::InlineAsmOperand::Const { value, span } => {
mir::InlineAsmOperand::Const {
value: box Constant { span, user_ty: None, literal: value.into() },
value: Box::new(Constant {
span,
user_ty: None,
literal: value.into(),
}),
}
}
thir::InlineAsmOperand::SymFn { expr } => mir::InlineAsmOperand::SymFn {
value: box this.as_constant(&this.thir[expr]),
value: Box::new(this.as_constant(&this.thir[expr])),
},
thir::InlineAsmOperand::SymStatic { def_id } => {
mir::InlineAsmOperand::SymStatic { def_id }

View File

@ -123,11 +123,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block,
Statement {
source_info,
kind: StatementKind::LlvmInlineAsm(box LlvmInlineAsm {
kind: StatementKind::LlvmInlineAsm(Box::new(LlvmInlineAsm {
asm: asm.clone(),
outputs,
inputs,
}),
})),
},
);
this.block_context.pop();

View File

@ -494,7 +494,7 @@ pub(super) fn expr_into_pattern(
Statement {
source_info: ty_source_info,
kind: StatementKind::AscribeUserType(
box (place, user_ty),
Box::new((place, user_ty)),
// We always use invariant as the variance here. This is because the
// variance field from the ascription refers to the variance to use
// when applying the type to the value being matched, but this
@ -2004,7 +2004,7 @@ fn ascribe_types<'b>(
Statement {
source_info,
kind: StatementKind::AscribeUserType(
box (ascription.source, user_ty),
Box::new((ascription.source, user_ty)),
ascription.variance,
),
},
@ -2133,11 +2133,11 @@ fn declare_binding(
let local = LocalDecl::<'tcx> {
mutability,
ty: var_ty,
user_ty: if user_ty.is_empty() { None } else { Some(box user_ty) },
user_ty: if user_ty.is_empty() { None } else { Some(Box::new(user_ty)) },
source_info,
internal: false,
is_block_tail: None,
local_info: Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(
local_info: Some(Box::new(LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(
VarBindingForm {
binding_mode,
// hypothetically, `visit_primary_bindings` could try to unzip
@ -2148,7 +2148,7 @@ fn declare_binding(
opt_match_place,
pat_span,
},
)))),
))))),
};
let for_arm_body = self.local_decls.push(local);
self.var_debug_info.push(VarDebugInfo {
@ -2166,9 +2166,9 @@ fn declare_binding(
source_info,
internal: false,
is_block_tail: None,
local_info: Some(box LocalInfo::User(ClearCrossCrate::Set(
local_info: Some(Box::new(LocalInfo::User(ClearCrossCrate::Set(
BindingForm::RefForGuard,
))),
)))),
});
self.var_debug_info.push(VarDebugInfo {
name,

View File

@ -346,7 +346,12 @@ fn compare(
let result = self.temp(bool_ty, source_info.span);
// result = op(left, right)
self.cfg.push_assign(block, source_info, result, Rvalue::BinaryOp(op, box (left, right)));
self.cfg.push_assign(
block,
source_info,
result,
Rvalue::BinaryOp(op, Box::new((left, right))),
);
// branch based on result
self.cfg.terminate(
@ -429,7 +434,7 @@ fn non_scalar_compare(
block,
source_info,
TerminatorKind::Call {
func: Operand::Constant(box Constant {
func: Operand::Constant(Box::new(Constant {
span: source_info.span,
// FIXME(#54571): This constant comes from user input (a
@ -439,7 +444,7 @@ fn non_scalar_compare(
user_ty: None,
literal: method.into(),
}),
})),
args: vec![val, expect],
destination: Some((eq_result, eq_block)),
cleanup: None,

View File

@ -31,7 +31,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
literal: &'tcx ty::Const<'tcx>,
) -> Operand<'tcx> {
let literal = literal.into();
let constant = box Constant { span, user_ty: None, literal };
let constant = Box::new(Constant { span, user_ty: None, literal });
Operand::Constant(constant)
}

View File

@ -980,19 +980,19 @@ fn args_and_body(
self.local_decls[local].mutability = mutability;
self.local_decls[local].source_info.scope = self.source_scope;
self.local_decls[local].local_info = if let Some(kind) = self_binding {
Some(box LocalInfo::User(ClearCrossCrate::Set(
Some(Box::new(LocalInfo::User(ClearCrossCrate::Set(
BindingForm::ImplicitSelf(*kind),
)))
))))
} else {
let binding_mode = ty::BindingMode::BindByValue(mutability);
Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(
Some(Box::new(LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(
VarBindingForm {
binding_mode,
opt_ty_info,
opt_match_place: Some((Some(place), span)),
pat_span: span,
},
))))
)))))
};
self.var_indices.insert(var, LocalsForNode::One(local));
}

View File

@ -2,7 +2,6 @@
//!
//! This crate also contains the match exhaustiveness and usefulness checking.
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(control_flow_enum)]
#![feature(crate_visibility_modifier)]
#![feature(bool_to_option)]

View File

@ -132,7 +132,7 @@ fn apply_adjustment(
},
};
let expr = box [self.thir.exprs.push(expr)];
let expr = Box::new([self.thir.exprs.push(expr)]);
self.overloaded_place(hir_expr, adjustment.target, Some(call), expr, deref.span)
}
@ -190,7 +190,7 @@ fn make_mirror_unadjusted(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Expr<'tcx>
ExprKind::Call {
ty: method.ty,
fun: self.thir.exprs.push(method),
args: box [self.mirror_expr(fun), tupled_args],
args: Box::new([self.mirror_expr(fun), tupled_args]),
from_hir_call: true,
fn_span: expr.span,
}
@ -266,7 +266,7 @@ fn make_mirror_unadjusted(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Expr<'tcx>
if self.typeck_results().is_method_call(expr) {
let lhs = self.mirror_expr(lhs);
let rhs = self.mirror_expr(rhs);
self.overloaded_operator(expr, box [lhs, rhs])
self.overloaded_operator(expr, Box::new([lhs, rhs]))
} else {
ExprKind::AssignOp {
op: bin_op(op.node),
@ -286,7 +286,7 @@ fn make_mirror_unadjusted(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Expr<'tcx>
if self.typeck_results().is_method_call(expr) {
let lhs = self.mirror_expr(lhs);
let rhs = self.mirror_expr(rhs);
self.overloaded_operator(expr, box [lhs, rhs])
self.overloaded_operator(expr, Box::new([lhs, rhs]))
} else {
// FIXME overflow
match op.node {
@ -317,7 +317,7 @@ fn make_mirror_unadjusted(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Expr<'tcx>
if self.typeck_results().is_method_call(expr) {
let lhs = self.mirror_expr(lhs);
let index = self.mirror_expr(index);
self.overloaded_place(expr, expr_ty, None, box [lhs, index], expr.span)
self.overloaded_place(expr, expr_ty, None, Box::new([lhs, index]), expr.span)
} else {
ExprKind::Index { lhs: self.mirror_expr(lhs), index: self.mirror_expr(index) }
}
@ -326,7 +326,7 @@ fn make_mirror_unadjusted(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Expr<'tcx>
hir::ExprKind::Unary(hir::UnOp::Deref, ref arg) => {
if self.typeck_results().is_method_call(expr) {
let arg = self.mirror_expr(arg);
self.overloaded_place(expr, expr_ty, None, box [arg], expr.span)
self.overloaded_place(expr, expr_ty, None, Box::new([arg]), expr.span)
} else {
ExprKind::Deref { arg: self.mirror_expr(arg) }
}
@ -335,7 +335,7 @@ fn make_mirror_unadjusted(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Expr<'tcx>
hir::ExprKind::Unary(hir::UnOp::Not, ref arg) => {
if self.typeck_results().is_method_call(expr) {
let arg = self.mirror_expr(arg);
self.overloaded_operator(expr, box [arg])
self.overloaded_operator(expr, Box::new([arg]))
} else {
ExprKind::Unary { op: UnOp::Not, arg: self.mirror_expr(arg) }
}
@ -344,7 +344,7 @@ fn make_mirror_unadjusted(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Expr<'tcx>
hir::ExprKind::Unary(hir::UnOp::Neg, ref arg) => {
if self.typeck_results().is_method_call(expr) {
let arg = self.mirror_expr(arg);
self.overloaded_operator(expr, box [arg])
self.overloaded_operator(expr, Box::new([arg]))
} else if let hir::ExprKind::Lit(ref lit) = arg.kind {
ExprKind::Literal {
literal: self.const_eval_literal(&lit.node, expr_ty, lit.span, true),
@ -914,7 +914,7 @@ fn convert_path_expr(&mut self, expr: &'tcx hir::Expr<'tcx>, res: Res) -> ExprKi
variant_index: adt_def.variant_index_with_ctor_id(def_id),
substs,
user_ty: user_provided_type,
fields: box [],
fields: Box::new([]),
base: None,
})),
_ => bug!("unexpected ty: {:?}", ty),

View File

@ -600,7 +600,7 @@ fn fold_pattern_kind(&mut self, kind: &PatKind<'tcx>) -> PatKind<'tcx> {
impl<'tcx, T: PatternFoldable<'tcx>> PatternFoldable<'tcx> for Box<T> {
fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
let content: T = (**self).fold_with(folder);
box content
Box::new(content)
}
}