Skip to content

Commit 2ff0fae

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

File tree

32 files changed

+87
-301
lines changed

32 files changed

+87
-301
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,17 +1537,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
15371537
}
15381538
}
15391539
CastKind::Transmute => {
1540-
// FIXME: `init_box_via_move` lowering really wants to use this.
1541-
// What do we have to do here?
1542-
// let ty_from = op.ty(self.body, tcx);
1543-
// match ty_from.kind() {
1544-
// ty::Pat(base, _) if base == ty => {}
1545-
// _ => span_mirbug!(
1546-
// self,
1547-
// rvalue,
1548-
// "Unexpected CastKind::Transmute {ty_from:?} -> {ty:?}, which is not permitted in Analysis MIR",
1549-
// ),
1550-
// }
1540+
// Transmutes are always well-typed, nothing to check here.
15511541
}
15521542
CastKind::Subtype => {
15531543
bug!("CastKind::Subtype shouldn't exist in borrowck")
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
#### Note: this error code is no longer emitted by the compiler.
2+
13
The value of statics and constants must be known at compile time, and they live
24
for the entire lifetime of a program. Creating a boxed value allocates memory on
35
the heap at runtime, and therefore cannot be done at compile time.
46

57
Erroneous code example:
68

7-
```compile_fail,E0010
9+
```
810
const CON : Vec<i32> = vec![1, 2, 3];
911
```

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 { .. }

0 commit comments

Comments
 (0)