Skip to content

Commit 13ff2d4

Browse files
authored
Rollup merge of #108958 - clubby789:unbox-the-hir, r=compiler-errors
Remove box expressions from HIR After #108516, `#[rustc_box]` is used at HIR->THIR lowering and this is no longer emitted, so it can be removed. This is based on top of #108471 to help with conflicts, so 43490488ccacd1a822e9c621f5ed6fca99959a0b is the only relevant commit (sorry for all the duplicated pings!) ````@rustbot```` label +S-blocked
2 parents 511364e + 9afffc5 commit 13ff2d4

File tree

27 files changed

+12
-73
lines changed

27 files changed

+12
-73
lines changed

compiler/rustc_ast/src/util/parser.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ pub enum ExprPrecedence {
259259
Assign,
260260
AssignOp,
261261

262-
Box,
263262
AddrOf,
264263
Let,
265264
Unary,
@@ -319,8 +318,7 @@ impl ExprPrecedence {
319318
ExprPrecedence::AssignOp => AssocOp::Assign.precedence() as i8,
320319

321320
// Unary, prefix
322-
ExprPrecedence::Box
323-
| ExprPrecedence::AddrOf
321+
ExprPrecedence::AddrOf
324322
// Here `let pats = expr` has `let pats =` as a "unary" prefix of `expr`.
325323
// However, this is not exactly right. When `let _ = a` is the LHS of a binop we
326324
// need parens sometimes. E.g. we can print `(let _ = a) && b` as `let _ = a && b`

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,6 @@ pub struct Expr<'hir> {
16731673
impl Expr<'_> {
16741674
pub fn precedence(&self) -> ExprPrecedence {
16751675
match self.kind {
1676-
ExprKind::Box(_) => ExprPrecedence::Box,
16771676
ExprKind::ConstBlock(_) => ExprPrecedence::ConstBlock,
16781677
ExprKind::Array(_) => ExprPrecedence::Array,
16791678
ExprKind::Call(..) => ExprPrecedence::Call,
@@ -1763,7 +1762,6 @@ impl Expr<'_> {
17631762
| ExprKind::Lit(_)
17641763
| ExprKind::ConstBlock(..)
17651764
| ExprKind::Unary(..)
1766-
| ExprKind::Box(..)
17671765
| ExprKind::AddrOf(..)
17681766
| ExprKind::Binary(..)
17691767
| ExprKind::Yield(..)
@@ -1851,7 +1849,6 @@ impl Expr<'_> {
18511849
| ExprKind::InlineAsm(..)
18521850
| ExprKind::AssignOp(..)
18531851
| ExprKind::ConstBlock(..)
1854-
| ExprKind::Box(..)
18551852
| ExprKind::Binary(..)
18561853
| ExprKind::Yield(..)
18571854
| ExprKind::DropTemps(..)
@@ -1862,8 +1859,7 @@ impl Expr<'_> {
18621859
/// To a first-order approximation, is this a pattern?
18631860
pub fn is_approximately_pattern(&self) -> bool {
18641861
match &self.kind {
1865-
ExprKind::Box(_)
1866-
| ExprKind::Array(_)
1862+
ExprKind::Array(_)
18671863
| ExprKind::Call(..)
18681864
| ExprKind::Tup(_)
18691865
| ExprKind::Lit(_)
@@ -1910,8 +1906,6 @@ pub fn is_range_literal(expr: &Expr<'_>) -> bool {
19101906

19111907
#[derive(Debug, HashStable_Generic)]
19121908
pub enum ExprKind<'hir> {
1913-
/// A `box x` expression.
1914-
Box(&'hir Expr<'hir>),
19151909
/// Allow anonymous constants from an inline `const` block
19161910
ConstBlock(AnonConst),
19171911
/// An array (e.g., `[a, b, c, d]`).

compiler/rustc_hir/src/intravisit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,6 @@ pub fn walk_anon_const<'v, V: Visitor<'v>>(visitor: &mut V, constant: &'v AnonCo
682682
pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) {
683683
visitor.visit_id(expression.hir_id);
684684
match expression.kind {
685-
ExprKind::Box(ref subexpression) => visitor.visit_expr(subexpression),
686685
ExprKind::Array(subexpressions) => {
687686
walk_list!(visitor, visit_expr, subexpressions);
688687
}

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,10 +1366,6 @@ impl<'a> State<'a> {
13661366
self.ibox(INDENT_UNIT);
13671367
self.ann.pre(self, AnnNode::Expr(expr));
13681368
match expr.kind {
1369-
hir::ExprKind::Box(expr) => {
1370-
self.word_space("Box::new");
1371-
self.print_call_post(std::slice::from_ref(expr));
1372-
}
13731369
hir::ExprKind::Array(exprs) => {
13741370
self.print_expr_vec(exprs);
13751371
}

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
284284

285285
let tcx = self.tcx;
286286
match expr.kind {
287-
ExprKind::Box(subexpr) => self.check_expr_box(subexpr, expected),
288287
ExprKind::Lit(ref lit) => self.check_lit(&lit, expected),
289288
ExprKind::Binary(op, lhs, rhs) => self.check_binop(expr, op, lhs, rhs, expected),
290289
ExprKind::Assign(lhs, rhs, span) => {
@@ -359,16 +358,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
359358
}
360359
}
361360

362-
fn check_expr_box(&self, expr: &'tcx hir::Expr<'tcx>, expected: Expectation<'tcx>) -> Ty<'tcx> {
363-
let expected_inner = expected.to_option(self).map_or(NoExpectation, |ty| match ty.kind() {
364-
ty::Adt(def, _) if def.is_box() => Expectation::rvalue_hint(self, ty.boxed_ty()),
365-
_ => NoExpectation,
366-
});
367-
let referent_ty = self.check_expr_with_expectation(expr, expected_inner);
368-
self.require_type_is_sized(referent_ty, expr.span, traits::SizedBoxType);
369-
self.tcx.mk_box(referent_ty)
370-
}
371-
372361
fn check_expr_unary(
373362
&self,
374363
unop: hir::UnOp,

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,6 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
356356
self.walk_captures(closure);
357357
}
358358

359-
hir::ExprKind::Box(ref base) => {
360-
self.consume_expr(base);
361-
}
362-
363359
hir::ExprKind::Yield(value, _) => {
364360
self.consume_expr(value);
365361
}

compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/cfg_build.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ impl<'a, 'tcx> DropRangeVisitor<'a, 'tcx> {
190190
//
191191
// Some of these may be interesting in the future
192192
ExprKind::Path(..)
193-
| ExprKind::Box(..)
194193
| ExprKind::ConstBlock(..)
195194
| ExprKind::Array(..)
196195
| ExprKind::Call(..)
@@ -478,7 +477,6 @@ impl<'a, 'tcx> Visitor<'tcx> for DropRangeVisitor<'a, 'tcx> {
478477
| ExprKind::AssignOp(..)
479478
| ExprKind::Binary(..)
480479
| ExprKind::Block(..)
481-
| ExprKind::Box(..)
482480
| ExprKind::Cast(..)
483481
| ExprKind::Closure { .. }
484482
| ExprKind::ConstBlock(..)

compiler/rustc_hir_typeck/src/mem_categorization.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
382382
| hir::ExprKind::Struct(..)
383383
| hir::ExprKind::Repeat(..)
384384
| hir::ExprKind::InlineAsm(..)
385-
| hir::ExprKind::Box(..)
386385
| hir::ExprKind::Err(_) => Ok(self.cat_rvalue(expr.hir_id, expr.span, expr_ty)),
387386
}
388387
}

compiler/rustc_middle/src/traits/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,6 @@ pub enum ObligationCauseCode<'tcx> {
305305
SizedReturnType,
306306
/// Yield type must be `Sized`.
307307
SizedYieldType,
308-
/// Box expression result type must be `Sized`.
309-
SizedBoxType,
310308
/// Inline asm operand type must be `Sized`.
311309
InlineAsmSized,
312310
/// `[expr; N]` requires `type_of(expr): Copy`.

compiler/rustc_mir_build/src/thir/cx/expr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,6 @@ impl<'tcx> Cx<'tcx> {
780780
hir::ExprKind::DropTemps(ref source) => {
781781
ExprKind::Use { source: self.mirror_expr(source) }
782782
}
783-
hir::ExprKind::Box(ref value) => ExprKind::Box { value: self.mirror_expr(value) },
784783
hir::ExprKind::Array(ref fields) => {
785784
ExprKind::Array { fields: self.mirror_exprs(fields) }
786785
}

0 commit comments

Comments
 (0)