Skip to content

Commit 11a80a0

Browse files
authored
Rollup merge of rust-lang#108958 - clubby789:unbox-the-hir, r=compiler-errors
Remove box expressions from HIR After rust-lang#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 rust-lang#108471 to help with conflicts, so 43490488ccacd1a822e9c621f5ed6fca99959a0b is the only relevant commit (sorry for all the duplicated pings!) `@rustbot` label +S-blocked
2 parents e386217 + 9afffc5 commit 11a80a0

File tree

27 files changed

+12
-73
lines changed

27 files changed

+12
-73
lines changed

compiler/rustc_ast/src/util/parser.rs

+1-3
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

+1-7
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

-1
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

-4
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

-11
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

-4
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

-2
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

-1
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

-2
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

-1
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
}

compiler/rustc_passes/src/hir_stats.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
300300
record_variants!(
301301
(self, e, e.kind, Id::Node(e.hir_id), hir, Expr, ExprKind),
302302
[
303-
Box, ConstBlock, Array, Call, MethodCall, Tup, Binary, Unary, Lit, Cast, Type,
303+
ConstBlock, Array, Call, MethodCall, Tup, Binary, Unary, Lit, Cast, Type,
304304
DropTemps, Let, If, Loop, Match, Closure, Block, Assign, AssignOp, Field, Index,
305305
Path, AddrOf, Break, Continue, Ret, InlineAsm, Struct, Repeat, Yield, Err
306306
]

compiler/rustc_passes/src/liveness.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
473473
| hir::ExprKind::Struct(..)
474474
| hir::ExprKind::Repeat(..)
475475
| hir::ExprKind::InlineAsm(..)
476-
| hir::ExprKind::Box(..)
477476
| hir::ExprKind::Type(..)
478477
| hir::ExprKind::Err(_)
479478
| hir::ExprKind::Path(hir::QPath::TypeRelative(..))
@@ -1059,8 +1058,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10591058
self.propagate_through_expr(&l, r_succ)
10601059
}
10611060

1062-
hir::ExprKind::Box(ref e)
1063-
| hir::ExprKind::AddrOf(_, _, ref e)
1061+
hir::ExprKind::AddrOf(_, _, ref e)
10641062
| hir::ExprKind::Cast(ref e, _)
10651063
| hir::ExprKind::Type(ref e, _)
10661064
| hir::ExprKind::DropTemps(ref e)
@@ -1425,7 +1423,6 @@ fn check_expr<'tcx>(this: &mut Liveness<'_, 'tcx>, expr: &'tcx Expr<'tcx>) {
14251423
| hir::ExprKind::Closure { .. }
14261424
| hir::ExprKind::Path(_)
14271425
| hir::ExprKind::Yield(..)
1428-
| hir::ExprKind::Box(..)
14291426
| hir::ExprKind::Type(..)
14301427
| hir::ExprKind::Err(_) => {}
14311428
}

compiler/rustc_passes/src/naked_functions.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ enum ItemKind {
179179
impl<'tcx> CheckInlineAssembly<'tcx> {
180180
fn check_expr(&mut self, expr: &'tcx hir::Expr<'tcx>, span: Span) {
181181
match expr.kind {
182-
ExprKind::Box(..)
183-
| ExprKind::ConstBlock(..)
182+
ExprKind::ConstBlock(..)
184183
| ExprKind::Array(..)
185184
| ExprKind::Call(..)
186185
| ExprKind::MethodCall(..)

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

-3
Original file line numberDiff line numberDiff line change
@@ -2944,9 +2944,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
29442944
ObligationCauseCode::SizedYieldType => {
29452945
err.note("the yield type of a generator must have a statically known size");
29462946
}
2947-
ObligationCauseCode::SizedBoxType => {
2948-
err.note("the type of a box expression must have a statically known size");
2949-
}
29502947
ObligationCauseCode::AssignmentLhsSized => {
29512948
err.note("the left-hand-side of an assignment must have a statically known size");
29522949
}

src/tools/clippy/clippy_lints/src/infinite_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
167167
Finite
168168
},
169169
ExprKind::Block(block, _) => block.expr.as_ref().map_or(Finite, |e| is_infinite(cx, e)),
170-
ExprKind::Box(e) | ExprKind::AddrOf(BorrowKind::Ref, _, e) => is_infinite(cx, e),
170+
ExprKind::AddrOf(BorrowKind::Ref, _, e) => is_infinite(cx, e),
171171
ExprKind::Call(path, _) => {
172172
if let ExprKind::Path(ref qpath) = path.kind {
173173
cx.qpath_res(qpath, path.hir_id)

src/tools/clippy/clippy_lints/src/loops/never_loop.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ fn stmt_to_expr<'tcx>(stmt: &Stmt<'tcx>) -> Option<(&'tcx Expr<'tcx>, Option<&'t
124124
#[allow(clippy::too_many_lines)]
125125
fn never_loop_expr(expr: &Expr<'_>, ignore_ids: &mut Vec<HirId>, main_loop_id: HirId) -> NeverLoopResult {
126126
match expr.kind {
127-
ExprKind::Box(e)
128-
| ExprKind::Unary(_, e)
127+
ExprKind::Unary(_, e)
129128
| ExprKind::Cast(e, _)
130129
| ExprKind::Type(e, _)
131130
| ExprKind::Field(e, _)

src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs

-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ impl<'a, 'tcx> Visitor<'tcx> for SigDropHelper<'a, 'tcx> {
321321
self.has_significant_drop = true;
322322
}
323323
}
324-
ExprKind::Box(..) |
325324
ExprKind::Array(..) |
326325
ExprKind::Call(..) |
327326
ExprKind::Unary(..) |

src/tools/clippy/clippy_lints/src/methods/unnecessary_sort_by.rs

-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ struct SortByKeyDetection {
3333
/// contains a and the other replaces it with b)
3434
fn mirrored_exprs(a_expr: &Expr<'_>, a_ident: &Ident, b_expr: &Expr<'_>, b_ident: &Ident) -> bool {
3535
match (&a_expr.kind, &b_expr.kind) {
36-
// Two boxes with mirrored contents
37-
(ExprKind::Box(left_expr), ExprKind::Box(right_expr)) => {
38-
mirrored_exprs(left_expr, a_ident, right_expr, b_ident)
39-
},
4036
// Two arrays with mirrored contents
4137
(ExprKind::Array(left_exprs), ExprKind::Array(right_exprs)) => {
4238
iter::zip(*left_exprs, *right_exprs).all(|(left, right)| mirrored_exprs(left, a_ident, right, b_ident))

src/tools/clippy/clippy_lints/src/no_effect.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ fn has_no_effect(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
127127
| ExprKind::Type(inner, _)
128128
| ExprKind::Unary(_, inner)
129129
| ExprKind::Field(inner, _)
130-
| ExprKind::AddrOf(_, _, inner)
131-
| ExprKind::Box(inner) => has_no_effect(cx, inner),
130+
| ExprKind::AddrOf(_, _, inner) => has_no_effect(cx, inner),
132131
ExprKind::Struct(_, fields, ref base) => {
133132
!has_drop(cx, cx.typeck_results().expr_ty(expr))
134133
&& fields.iter().all(|field| has_no_effect(cx, field.expr))
@@ -234,8 +233,7 @@ fn reduce_expression<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<Vec
234233
| ExprKind::Type(inner, _)
235234
| ExprKind::Unary(_, inner)
236235
| ExprKind::Field(inner, _)
237-
| ExprKind::AddrOf(_, _, inner)
238-
| ExprKind::Box(inner) => reduce_expression(cx, inner).or_else(|| Some(vec![inner])),
236+
| ExprKind::AddrOf(_, _, inner) => reduce_expression(cx, inner).or_else(|| Some(vec![inner])),
239237
ExprKind::Struct(_, fields, ref base) => {
240238
if has_drop(cx, cx.typeck_results().expr_ty(expr)) {
241239
None

src/tools/clippy/clippy_lints/src/shadow.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ fn is_self_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, mut expr: &Expr<'_>, hir_
213213
}
214214
loop {
215215
expr = match expr.kind {
216-
ExprKind::Box(e)
217-
| ExprKind::AddrOf(_, _, e)
216+
ExprKind::AddrOf(_, _, e)
218217
| ExprKind::Block(
219218
&Block {
220219
stmts: [],

src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs

-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ impl<'cx, 'sdt, 'tcx> Visitor<'tcx> for SigDropFinder<'cx, 'sdt, 'tcx> {
380380
| hir::ExprKind::Assign(..)
381381
| hir::ExprKind::AssignOp(..)
382382
| hir::ExprKind::Binary(..)
383-
| hir::ExprKind::Box(..)
384383
| hir::ExprKind::Call(..)
385384
| hir::ExprKind::Field(..)
386385
| hir::ExprKind::If(..)

src/tools/clippy/clippy_lints/src/utils/author.rs

-5
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,6 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
395395
}
396396
self.expr(field!(let_expr.init));
397397
},
398-
ExprKind::Box(inner) => {
399-
bind!(self, inner);
400-
kind!("Box({inner})");
401-
self.expr(inner);
402-
},
403398
ExprKind::Array(elements) => {
404399
bind!(self, elements);
405400
kind!("Array({elements})");

src/tools/clippy/clippy_utils/src/check_proc_macro.rs

-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ fn qpath_search_pat(path: &QPath<'_>) -> (Pat, Pat) {
112112
/// Get the search patterns to use for the given expression
113113
fn expr_search_pat(tcx: TyCtxt<'_>, e: &Expr<'_>) -> (Pat, Pat) {
114114
match e.kind {
115-
ExprKind::Box(e) => (Pat::Str("box"), expr_search_pat(tcx, e).1),
116115
ExprKind::ConstBlock(_) => (Pat::Str("const"), Pat::Str("}")),
117116
ExprKind::Tup([]) => (Pat::Str(")"), Pat::Str("(")),
118117
ExprKind::Unary(UnOp::Deref, e) => (Pat::Str("*"), expr_search_pat(tcx, e).1),

src/tools/clippy/clippy_utils/src/eager_or_lazy.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS
199199
},
200200

201201
// Memory allocation, custom operator, loop, or call to an unknown function
202-
ExprKind::Box(_)
203-
| ExprKind::Unary(..)
202+
ExprKind::Unary(..)
204203
| ExprKind::Binary(..)
205204
| ExprKind::Loop(..)
206205
| ExprKind::Call(..) => self.eagerness = Lazy,

src/tools/clippy/clippy_utils/src/hir_utils.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ impl HirEqInterExpr<'_, '_, '_> {
249249
both(&li.label, &ri.label, |l, r| l.ident.name == r.ident.name)
250250
&& both(le, re, |l, r| self.eq_expr(l, r))
251251
},
252-
(&ExprKind::Box(l), &ExprKind::Box(r)) => self.eq_expr(l, r),
253252
(&ExprKind::Call(l_fun, l_args), &ExprKind::Call(r_fun, r_args)) => {
254253
self.inner.allow_side_effects && self.eq_expr(l_fun, r_fun) && self.eq_exprs(l_args, r_args)
255254
},
@@ -628,7 +627,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
628627
self.hash_expr(j);
629628
}
630629
},
631-
ExprKind::Box(e) | ExprKind::DropTemps(e) | ExprKind::Yield(e, _) => {
630+
ExprKind::DropTemps(e) | ExprKind::Yield(e, _) => {
632631
self.hash_expr(e);
633632
},
634633
ExprKind::Call(fun, args) => {

src/tools/clippy/clippy_utils/src/sugg.rs

-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ impl<'a> Sugg<'a> {
133133

134134
match expr.kind {
135135
hir::ExprKind::AddrOf(..)
136-
| hir::ExprKind::Box(..)
137136
| hir::ExprKind::If(..)
138137
| hir::ExprKind::Let(..)
139138
| hir::ExprKind::Closure { .. }

src/tools/clippy/clippy_utils/src/visitors.rs

-1
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,6 @@ pub fn for_each_unconsumed_temporary<'tcx, B>(
600600
helper(typeck, false, e, f)?;
601601
},
602602
ExprKind::Block(&Block { expr: Some(e), .. }, _)
603-
| ExprKind::Box(e)
604603
| ExprKind::Cast(e, _)
605604
| ExprKind::Unary(_, e) => {
606605
helper(typeck, true, e, f)?;

0 commit comments

Comments
 (0)