Skip to content

Commit a3cd68b

Browse files
committed
get rid of ExprKind::Box
1 parent eae44ed commit a3cd68b

File tree

12 files changed

+0
-81
lines changed

12 files changed

+0
-81
lines changed

compiler/rustc_middle/src/thir.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,6 @@ pub enum ExprKind<'tcx> {
284284
lint_level: LintLevel,
285285
value: ExprId,
286286
},
287-
/// A `box <value>` expression.
288-
Box {
289-
value: ExprId,
290-
},
291287
/// An `if` expression.
292288
If {
293289
if_then_scope: region::Scope,

compiler/rustc_middle/src/thir/visit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ pub fn walk_expr<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
5050
Scope { value, region_scope: _, lint_level: _ } => {
5151
visitor.visit_expr(&visitor.thir()[value])
5252
}
53-
Box { value } => visitor.visit_expr(&visitor.thir()[value]),
5453
If { cond, then, else_opt, if_then_scope: _ } => {
5554
visitor.visit_expr(&visitor.thir()[cond]);
5655
visitor.visit_expr(&visitor.thir()[then]);

compiler/rustc_mir_build/src/builder/expr/as_place.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
554554
| ExprKind::Unary { .. }
555555
| ExprKind::Binary { .. }
556556
| ExprKind::LogicalOp { .. }
557-
| ExprKind::Box { .. }
558557
| ExprKind::Cast { .. }
559558
| ExprKind::Use { .. }
560559
| ExprKind::NeverToAny { .. }

compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! See docs in `build/expr/mod.rs`.
22
33
use rustc_abi::FieldIdx;
4-
use rustc_hir::lang_items::LangItem;
54
use rustc_index::{Idx, IndexVec};
65
use rustc_middle::bug;
76
use rustc_middle::middle::region;
@@ -121,65 +120,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
121120
}
122121
block.and(Rvalue::UnaryOp(op, arg))
123122
}
124-
ExprKind::Box { value } => {
125-
let value_ty = this.thir[value].ty;
126-
let tcx = this.tcx;
127-
let source_info = this.source_info(expr_span);
128-
129-
let size = tcx.require_lang_item(LangItem::SizeOf, expr_span);
130-
let size = Operand::unevaluated_constant(tcx, size, &[value_ty.into()], expr_span);
131-
132-
let align = tcx.require_lang_item(LangItem::AlignOf, expr_span);
133-
let align =
134-
Operand::unevaluated_constant(tcx, align, &[value_ty.into()], expr_span);
135-
136-
// malloc some memory of suitable size and align:
137-
let exchange_malloc = Operand::function_handle(
138-
tcx,
139-
tcx.require_lang_item(LangItem::ExchangeMalloc, expr_span),
140-
[],
141-
expr_span,
142-
);
143-
let storage = this.temp(Ty::new_mut_ptr(tcx, tcx.types.u8), expr_span);
144-
let success = this.cfg.start_new_block();
145-
this.cfg.terminate(
146-
block,
147-
source_info,
148-
TerminatorKind::Call {
149-
func: exchange_malloc,
150-
args: [
151-
Spanned { node: size, span: DUMMY_SP },
152-
Spanned { node: align, span: DUMMY_SP },
153-
]
154-
.into(),
155-
destination: storage,
156-
target: Some(success),
157-
unwind: UnwindAction::Continue,
158-
call_source: CallSource::Misc,
159-
fn_span: expr_span,
160-
},
161-
);
162-
this.diverge_from(block);
163-
block = success;
164-
165-
let result = this.local_decls.push(LocalDecl::new(expr.ty, expr_span));
166-
this.cfg
167-
.push(block, Statement::new(source_info, StatementKind::StorageLive(result)));
168-
if let Some(scope) = scope.temp_lifetime {
169-
// schedule a shallow free of that memory, lest we unwind:
170-
this.schedule_drop_storage_and_value(expr_span, scope, result);
171-
}
172-
173-
// Transmute `*mut u8` to the box (thus far, uninitialized):
174-
let box_ = Rvalue::ShallowInitBox(Operand::Move(storage), value_ty);
175-
this.cfg.push_assign(block, source_info, Place::from(result), box_);
176-
177-
// initialize the box contents:
178-
block = this
179-
.expr_into_dest(this.tcx.mk_place_deref(Place::from(result)), block, value)
180-
.into_block();
181-
block.and(Rvalue::Use(Operand::Move(Place::from(result))))
182-
}
183123
ExprKind::Cast { source } => {
184124
let source_expr = &this.thir[source];
185125

compiler/rustc_mir_build/src/builder/expr/category.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ impl Category {
6464
| ExprKind::Closure { .. }
6565
| ExprKind::Unary { .. }
6666
| ExprKind::Binary { .. }
67-
| ExprKind::Box { .. }
6867
| ExprKind::Cast { .. }
6968
| ExprKind::PointerCoercion { .. }
7069
| ExprKind::Repeat { .. }

compiler/rustc_mir_build/src/builder/expr/into.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
876876
// these are the cases that are more naturally handled by some other mode
877877
ExprKind::Unary { .. }
878878
| ExprKind::Binary { .. }
879-
| ExprKind::Box { .. }
880879
| ExprKind::Cast { .. }
881880
| ExprKind::PointerCoercion { .. }
882881
| ExprKind::Repeat { .. }

compiler/rustc_mir_build/src/check_unsafety.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,6 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
474474
| ExprKind::LoopMatch { .. }
475475
| ExprKind::Let { .. }
476476
| ExprKind::Match { .. }
477-
| ExprKind::Box { .. }
478477
| ExprKind::If { .. }
479478
| ExprKind::InlineAsm { .. }
480479
| ExprKind::OffsetOf { .. }

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
353353
| Binary { .. }
354354
| Block { .. }
355355
| Borrow { .. }
356-
| Box { .. }
357356
| Call { .. }
358357
| ByUse { .. }
359358
| Closure { .. }

compiler/rustc_mir_build/src/thir/print.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,6 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
205205
self.print_expr(*value, depth_lvl + 2);
206206
print_indented!(self, "}", depth_lvl);
207207
}
208-
Box { value } => {
209-
print_indented!(self, "Box {", depth_lvl);
210-
self.print_expr(*value, depth_lvl + 1);
211-
print_indented!(self, "}", depth_lvl);
212-
}
213208
If { if_then_scope, cond, then, else_opt } => {
214209
print_indented!(self, "If {", depth_lvl);
215210
print_indented!(self, format!("if_then_scope: {:?}", if_then_scope), depth_lvl + 1);

compiler/rustc_ty_utils/messages.ftl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ ty_utils_block_not_supported = blocks are not supported in generic constants
1212
1313
ty_utils_borrow_not_supported = borrowing is not supported in generic constants
1414
15-
ty_utils_box_not_supported = allocations are not allowed in generic constants
16-
1715
ty_utils_by_use_not_supported = .use is not allowed in generic constants
1816
1917
ty_utils_closure_and_return_not_supported = closures and function keywords are not supported in generic constants

0 commit comments

Comments
 (0)