Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove box_syntax #108471

Merged
merged 4 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,6 @@ impl Expr {

pub fn precedence(&self) -> ExprPrecedence {
match self.kind {
ExprKind::Box(_) => ExprPrecedence::Box,
ExprKind::Array(_) => ExprPrecedence::Array,
ExprKind::ConstBlock(_) => ExprPrecedence::ConstBlock,
ExprKind::Call(..) => ExprPrecedence::Call,
Expand Down Expand Up @@ -1291,8 +1290,7 @@ impl Expr {
/// To a first-order approximation, is this a pattern?
pub fn is_approximately_pattern(&self) -> bool {
match &self.peel_parens().kind {
ExprKind::Box(_)
| ExprKind::Array(_)
ExprKind::Array(_)
| ExprKind::Call(_, _)
| ExprKind::Tup(_)
| ExprKind::Lit(_)
Expand Down Expand Up @@ -1363,8 +1361,6 @@ pub struct StructExpr {

#[derive(Clone, Encodable, Decodable, Debug)]
pub enum ExprKind {
/// A `box x` expression.
Box(P<Expr>),
/// An array (`[a, b, c, d]`)
Array(ThinVec<P<Expr>>),
/// Allow anonymous constants from an inline `const` block
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,6 @@ pub fn noop_visit_expr<T: MutVisitor>(
vis: &mut T,
) {
match kind {
ExprKind::Box(expr) => vis.visit_expr(expr),
ExprKind::Array(exprs) => visit_thin_exprs(exprs, vis),
ExprKind::ConstBlock(anon_const) => {
vis.visit_anon_const(anon_const);
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_ast/src/util/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pub fn expr_trailing_brace(mut expr: &ast::Expr) -> Option<&ast::Expr> {
| Assign(_, e, _)
| AssignOp(_, _, e)
| Binary(_, _, e)
| Box(e)
| Break(_, Some(e))
| Let(_, e, _)
| Range(_, Some(e), _)
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,6 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
walk_list!(visitor, visit_attribute, expression.attrs.iter());

match &expression.kind {
ExprKind::Box(subexpression) => visitor.visit_expr(subexpression),
ExprKind::Array(subexpressions) => {
walk_list!(visitor, visit_expr, subexpressions);
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.lower_attrs(hir_id, &e.attrs);

let kind = match &e.kind {
ExprKind::Box(inner) => hir::ExprKind::Box(self.lower_expr(inner)),
ExprKind::Array(exprs) => hir::ExprKind::Array(self.lower_exprs(exprs)),
ExprKind::ConstBlock(anon_const) => {
let anon_const = self.lower_anon_const(anon_const);
Expand Down
9 changes: 0 additions & 9 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {

fn visit_expr(&mut self, e: &'a ast::Expr) {
match e.kind {
ast::ExprKind::Box(_) => {
gate_feature_post!(
&self,
box_syntax,
e.span,
"box expression syntax is experimental; you can call `Box::new` instead"
);
}
ast::ExprKind::Type(..) => {
if self.sess.parse_sess.span_diagnostic.err_count() == 0 {
// To avoid noise about type ascription in common syntax errors,
Expand Down Expand Up @@ -613,7 +605,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
gate_all!(box_patterns, "box pattern syntax is experimental");
gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");
gate_all!(try_blocks, "`try` blocks are unstable");
gate_all!(box_syntax, "box expression syntax is experimental; you can call `Box::new` instead");
gate_all!(type_ascription, "type ascription is experimental");

visit::walk_crate(&mut visitor, krate);
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_ast_pretty/src/pprust/state/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,6 @@ impl<'a> State<'a> {
self.ibox(INDENT_UNIT);
self.ann.pre(self, AnnNode::Expr(expr));
match &expr.kind {
ast::ExprKind::Box(expr) => {
self.word_space("box");
self.print_expr_maybe_paren(expr, parser::PREC_PREFIX);
}
ast::ExprKind::Array(exprs) => {
self.print_expr_vec(exprs);
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_builtin_macros/src/assert/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ impl<'cx, 'a> Context<'cx, 'a> {
| ExprKind::Async(_, _, _)
| ExprKind::Await(_)
| ExprKind::Block(_, _)
| ExprKind::Box(_)
| ExprKind::Break(_, _)
| ExprKind::Closure(_)
| ExprKind::ConstBlock(_)
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/example/alloc_example.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(start, core_intrinsics, alloc_error_handler, box_syntax)]
#![feature(start, core_intrinsics, alloc_error_handler)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you verified that these examples still work? They look simple enough but it would be nice to make sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried and failed before to get cranelift/gcc working 🙁 Would a try build check that these build?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not, try builds check just about nothing by default and we don't test these backends in CI right now anyways.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can fix up cg_clif on the next sync if necessary. I hope to get test integration for cg_clif working on rust's CI soon, which would also make it easier to check it locally, but for now I need to fixup tests every once in a while myself.

#![no_std]

extern crate alloc;
Expand Down Expand Up @@ -29,7 +29,7 @@ fn alloc_error_handler(_: alloc::alloc::Layout) -> ! {

#[start]
fn main(_argc: isize, _argv: *const *const u8) -> isize {
let world: Box<&str> = box "Hello World!\0";
let world: Box<&str> = Box::new("Hello World!\0");
unsafe {
puts(*world as *const str as *const u8);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(no_core, lang_items, never_type, linkage, extern_types, thread_local, box_syntax)]
#![feature(no_core, lang_items, never_type, linkage, extern_types, thread_local)]
#![no_core]
#![allow(dead_code, non_camel_case_types)]

Expand Down Expand Up @@ -178,7 +178,7 @@ fn main() {
let ptr: *const i8 = hello as *const [u8] as *const i8;
puts(ptr);

let world: Box<&str> = box "World!\0";
let world: Box<&str> = Box::new("World!\0");
puts(*world as *const str as *const i8);
world as Box<dyn SomeTrait>;

Expand Down Expand Up @@ -238,10 +238,10 @@ fn main() {
}
}

let _ = box NoisyDrop {
let _ = Box::new(NoisyDrop {
text: "Boxed outer got dropped!\0",
inner: NoisyDropInner,
} as Box<dyn SomeTrait>;
}) as Box<dyn SomeTrait>;

const FUNC_REF: Option<fn()> = Some(main);
match FUNC_REF {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_gcc/example/alloc_example.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(start, box_syntax, core_intrinsics, alloc_error_handler, lang_items)]
#![feature(start, core_intrinsics, alloc_error_handler, lang_items)]
#![no_std]

extern crate alloc;
Expand Down Expand Up @@ -38,7 +38,7 @@ unsafe extern "C" fn _Unwind_Resume() {

#[start]
fn main(_argc: isize, _argv: *const *const u8) -> isize {
let world: Box<&str> = box "Hello World!\0";
let world: Box<&str> = Box::new("Hello World!\0");
unsafe {
puts(*world as *const str as *const u8);
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_gcc/example/mini_core_hello_world.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Adapted from https://github.com/sunfishcode/mir2cranelift/blob/master/rust-examples/nocore-hello-world.rs

#![feature(
no_core, unboxed_closures, start, lang_items, box_syntax, never_type, linkage,
no_core, unboxed_closures, start, lang_items, never_type, linkage,
extern_types, thread_local
)]
#![no_core]
Expand Down Expand Up @@ -163,7 +163,7 @@ fn main() {
let ptr: *const u8 = hello as *const [u8] as *const u8;
puts(ptr);

let world: Box<&str> = box "World!\0";
let world: Box<&str> = Box::new("World!\0");
puts(*world as *const str as *const u8);
world as Box<dyn SomeTrait>;

Expand Down Expand Up @@ -223,10 +223,10 @@ fn main() {
}
}

let _ = box NoisyDrop {
let _ = Box::new(NoisyDrop {
text: "Boxed outer got dropped!\0",
inner: NoisyDropInner,
} as Box<dyn SomeTrait>;
}) as Box<dyn SomeTrait>;

const FUNC_REF: Option<fn()> = Some(main);
#[allow(unreachable_code)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/example/mod_bench.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(start, box_syntax, core_intrinsics, lang_items)]
#![feature(start, core_intrinsics, lang_items)]
#![no_std]

#[link(name = "c")]
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_error_codes/src/error_codes/E0010.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@ the heap at runtime, and therefore cannot be done at compile time.
Erroneous code example:

```compile_fail,E0010
clubby789 marked this conversation as resolved.
Show resolved Hide resolved
#![feature(box_syntax)]

const CON : Box<i32> = box 0;
const CON : Vec<i32> = vec![1, 2, 3];
```
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ declare_features! (
(active, auto_traits, "1.50.0", Some(13231), None),
/// Allows using `box` in patterns (RFC 469).
(active, box_patterns, "1.0.0", Some(29641), None),
/// Allows using the `box $expr` syntax.
(active, box_syntax, "1.0.0", Some(49733), None),
/// Allows `#[doc(notable_trait)]`.
/// Renamed from `doc_spotlight`.
(active, doc_notable_trait, "1.52.0", Some(45040), None),
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ declare_features! (
(removed, allow_fail, "1.19.0", Some(46488), None, Some("removed due to no clear use cases")),
(removed, await_macro, "1.38.0", Some(50547), None,
Some("subsumed by `.await` syntax")),
/// Allows using the `box $expr` syntax.
(removed, box_syntax, "CURRENT_RUSTC_VERSION", Some(49733), None, Some("replaced with `#[rustc_box]`")),
/// Allows capturing disjoint fields in a closure/generator (RFC 2229).
(removed, capture_disjoint_fields, "1.49.0", Some(53488), None, Some("stabilized in Rust 2021")),
/// Allows comparing raw pointers during const eval.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1367,8 +1367,8 @@ impl<'a> State<'a> {
self.ann.pre(self, AnnNode::Expr(expr));
match expr.kind {
hir::ExprKind::Box(expr) => {
self.word_space("box");
self.print_expr_maybe_paren(expr, parser::PREC_PREFIX);
self.word_space("Box::new");
self.print_call_post(std::slice::from_ref(expr));
}
hir::ExprKind::Array(exprs) => {
self.print_expr_vec(exprs);
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,6 @@ declare_lint_pass!(UnusedAllocation => [UNUSED_ALLOCATION]);
impl<'tcx> LateLintPass<'tcx> for UnusedAllocation {
fn check_expr(&mut self, cx: &LateContext<'_>, e: &hir::Expr<'_>) {
match e.kind {
hir::ExprKind::Box(_) => {}
hir::ExprKind::Call(path_expr, [_])
if let hir::ExprKind::Path(qpath) = &path_expr.kind
&& let Some(did) = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id()
Expand Down
45 changes: 25 additions & 20 deletions compiler/rustc_mir_transform/src/large_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,12 @@ impl EnumSizeOpt {
tmp_ty,
),
};
let rval = Rvalue::Use(Operand::Constant(box (constant_vals)));
let rval = Rvalue::Use(Operand::Constant(Box::new(constant_vals)));

let const_assign =
Statement { source_info, kind: StatementKind::Assign(box (place, rval)) };
let const_assign = Statement {
source_info,
kind: StatementKind::Assign(Box::new((place, rval))),
};

let discr_place = Place::from(
local_decls
Expand All @@ -170,48 +172,51 @@ impl EnumSizeOpt {

let store_discr = Statement {
source_info,
kind: StatementKind::Assign(box (discr_place, Rvalue::Discriminant(*rhs))),
kind: StatementKind::Assign(Box::new((
discr_place,
Rvalue::Discriminant(*rhs),
))),
};

let discr_cast_place =
Place::from(local_decls.push(LocalDecl::new(tcx.types.usize, span)));

let cast_discr = Statement {
source_info,
kind: StatementKind::Assign(box (
kind: StatementKind::Assign(Box::new((
discr_cast_place,
Rvalue::Cast(
CastKind::IntToInt,
Operand::Copy(discr_place),
tcx.types.usize,
),
)),
))),
};

let size_place =
Place::from(local_decls.push(LocalDecl::new(tcx.types.usize, span)));

let store_size = Statement {
source_info,
kind: StatementKind::Assign(box (
kind: StatementKind::Assign(Box::new((
size_place,
Rvalue::Use(Operand::Copy(Place {
local: size_array_local,
projection: tcx
.mk_place_elems(&[PlaceElem::Index(discr_cast_place.local)]),
})),
)),
))),
};

let dst =
Place::from(local_decls.push(LocalDecl::new(tcx.mk_mut_ptr(ty), span)));

let dst_ptr = Statement {
source_info,
kind: StatementKind::Assign(box (
kind: StatementKind::Assign(Box::new((
dst,
Rvalue::AddressOf(Mutability::Mut, *lhs),
)),
))),
};

let dst_cast_ty = tcx.mk_mut_ptr(tcx.types.u8);
Expand All @@ -220,21 +225,21 @@ impl EnumSizeOpt {

let dst_cast = Statement {
source_info,
kind: StatementKind::Assign(box (
kind: StatementKind::Assign(Box::new((
dst_cast_place,
Rvalue::Cast(CastKind::PtrToPtr, Operand::Copy(dst), dst_cast_ty),
)),
))),
};

let src =
Place::from(local_decls.push(LocalDecl::new(tcx.mk_imm_ptr(ty), span)));

let src_ptr = Statement {
source_info,
kind: StatementKind::Assign(box (
kind: StatementKind::Assign(Box::new((
src,
Rvalue::AddressOf(Mutability::Not, *rhs),
)),
))),
};

let src_cast_ty = tcx.mk_imm_ptr(tcx.types.u8);
Expand All @@ -243,24 +248,24 @@ impl EnumSizeOpt {

let src_cast = Statement {
source_info,
kind: StatementKind::Assign(box (
kind: StatementKind::Assign(Box::new((
src_cast_place,
Rvalue::Cast(CastKind::PtrToPtr, Operand::Copy(src), src_cast_ty),
)),
))),
};

let deinit_old =
Statement { source_info, kind: StatementKind::Deinit(box dst) };
Statement { source_info, kind: StatementKind::Deinit(Box::new(dst)) };

let copy_bytes = Statement {
source_info,
kind: StatementKind::Intrinsic(
box NonDivergingIntrinsic::CopyNonOverlapping(CopyNonOverlapping {
kind: StatementKind::Intrinsic(Box::new(
NonDivergingIntrinsic::CopyNonOverlapping(CopyNonOverlapping {
src: Operand::Copy(src_cast_place),
dst: Operand::Copy(dst_cast_place),
count: Operand::Copy(size_place),
}),
),
)),
};

let store_dead = Statement {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![allow(rustc::potential_query_instability)]
#![feature(box_patterns)]
#![feature(drain_filter)]
#![feature(box_syntax)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😭 why was this here

#![feature(let_chains)]
#![feature(map_try_insert)]
#![feature(min_specialization)]
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_parse/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -731,3 +731,6 @@ parse_unknown_start_of_token = unknown start of token: {$escaped}
[one] once more
*[other] {$repeats} more times
}

parse_box_syntax_removed = `box_syntax` has been removed
.suggestion = use `Box::new()` instead
Loading