Navigation Menu

Skip to content

Commit

Permalink
Remove box syntax from rustc_mir_build
Browse files Browse the repository at this point in the history
  • Loading branch information
est31 committed Aug 18, 2021
1 parent cbe3afe commit 8b0b7ef
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 59 deletions.
15 changes: 10 additions & 5 deletions compiler/rustc_mir_build/src/build/cfg.rs
Expand Up @@ -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))) },
);
}

Expand All @@ -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(
Expand All @@ -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(),
})),
}))),
);
}

Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/expr/as_operand.rs
Expand Up @@ -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));
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_mir_build/src/build/expr/as_place.rs
Expand Up @@ -507,10 +507,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Statement {
source_info,
kind: StatementKind::AscribeUserType(
box (
Box::new((
place,
UserTypeProjection { base: annotation_index, projs: vec![] },
),
)),
Variance::Invariant,
),
},
Expand All @@ -534,10 +534,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Statement {
source_info,
kind: StatementKind::AscribeUserType(
box (
Box::new((
Place::from(temp),
UserTypeProjection { base: annotation_index, projs: vec![] },
),
)),
Variance::Invariant,
),
},
Expand Down Expand Up @@ -691,7 +691,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
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)) };
Expand Down
28 changes: 15 additions & 13 deletions compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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`
Expand Down Expand Up @@ -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 { .. }
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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))))
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_mir_build/src/build/expr/as_temp.rs
Expand Up @@ -62,16 +62,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
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 }));
}
_ => {}
}
Expand Down
12 changes: 8 additions & 4 deletions compiler/rustc_mir_build/src/build/expr/into.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_build/src/build/expr/stmt.rs
Expand Up @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_mir_build/src/build/matches/mod.rs
Expand Up @@ -494,7 +494,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
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
Expand Down Expand Up @@ -2004,7 +2004,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Statement {
source_info,
kind: StatementKind::AscribeUserType(
box (ascription.source, user_ty),
Box::new((ascription.source, user_ty)),
ascription.variance,
),
},
Expand Down Expand Up @@ -2133,11 +2133,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
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
Expand All @@ -2148,7 +2148,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
opt_match_place,
pat_span,
},
)))),
))))),
};
let for_arm_body = self.local_decls.push(local);
self.var_debug_info.push(VarDebugInfo {
Expand All @@ -2166,9 +2166,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
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,
Expand Down
11 changes: 8 additions & 3 deletions compiler/rustc_mir_build/src/build/matches/test.rs
Expand Up @@ -346,7 +346,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
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(
Expand Down Expand Up @@ -429,7 +434,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
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
Expand All @@ -439,7 +444,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
user_ty: None,

literal: method.into(),
}),
})),
args: vec![val, expect],
destination: Some((eq_result, eq_block)),
cleanup: None,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/misc.rs
Expand Up @@ -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)
}

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_mir_build/src/build/mod.rs
Expand Up @@ -980,19 +980,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
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));
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_mir_build/src/lib.rs
Expand Up @@ -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)]
Expand Down

0 comments on commit 8b0b7ef

Please sign in to comment.