diff options
| author | bors <bors@rust-lang.org> | 2023-03-13 10:41:50 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-03-13 10:41:50 +0000 |
| commit | f1b1ed7e18f1fbe5226a96626827c625985f8285 (patch) | |
| tree | d424952e590d63a8e4020f65d8d74304daa1397b /compiler/rustc_parse/src/parser/expr.rs | |
| parent | d610b0c514b9ccb0dad5d0b77ce4c518f71b92c8 (diff) | |
| parent | 8b186dfdb70ebfe722975970458c6230841e6911 (diff) | |
| download | rust-f1b1ed7e18f1fbe5226a96626827c625985f8285.tar.gz rust-f1b1ed7e18f1fbe5226a96626827c625985f8285.zip | |
Auto merge of #108471 - clubby789:unbox-the-syntax, r=Nilstrieb,est31
Remove `box_syntax` r? `@Nilstrieb` This removes the feature `box_syntax`, which allows the use of `box <expr>` to create a Box, and finalises removing use of the feature from the compiler. `box_patterns` (allowing the use of `box <pat>` in a pattern) is unaffected. It also removes `ast::ExprKind::Box` - the only way to create a 'box' expression now is with the rustc-internal `#[rustc_box]` attribute. As a temporary measure to help users move away, `box <expr>` now parses the inner expression, and emits a `MachineApplicable` lint to replace it with `Box::new` Closes #49733
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 1d12dd47094..296eb4d653c 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -8,6 +8,7 @@ use super::{ use crate::errors; use crate::maybe_recover_from_interpolated_ty_qpath; +use ast::{Path, PathSegment}; use core::mem; use rustc_ast::ptr::P; use rustc_ast::token::{self, Delimiter, Token, TokenKind}; @@ -29,6 +30,7 @@ use rustc_session::errors::{report_lit_error, ExprParenthesesNeeded}; use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP; use rustc_session::lint::BuiltinLintDiagnostics; use rustc_span::source_map::{self, Span, Spanned}; +use rustc_span::symbol::kw::PathRoot; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{BytePos, Pos}; use thin_vec::{thin_vec, ThinVec}; @@ -636,11 +638,27 @@ impl<'a> Parser<'a> { self.parse_expr_unary(lo, UnOp::Not) } - /// Parse `box expr`. + /// Parse `box expr` - this syntax has been removed, but we still parse this + /// for now to provide an automated way to fix usages of it fn parse_expr_box(&mut self, lo: Span) -> PResult<'a, (Span, ExprKind)> { let (span, expr) = self.parse_expr_prefix_common(lo)?; - self.sess.gated_spans.gate(sym::box_syntax, span); - Ok((span, ExprKind::Box(expr))) + let code = self.sess.source_map().span_to_snippet(span.with_lo(lo.hi())).unwrap(); + self.sess.emit_err(errors::BoxSyntaxRemoved { span, code: code.trim() }); + // So typechecking works, parse `box <expr>` as `::std::boxed::Box::new(expr)` + let path = Path { + span, + segments: [ + PathSegment::from_ident(Ident::with_dummy_span(PathRoot)), + PathSegment::from_ident(Ident::with_dummy_span(sym::std)), + PathSegment::from_ident(Ident::from_str("boxed")), + PathSegment::from_ident(Ident::from_str("Box")), + PathSegment::from_ident(Ident::with_dummy_span(sym::new)), + ] + .into(), + tokens: None, + }; + let path = self.mk_expr(span, ExprKind::Path(None, path)); + Ok((span, self.mk_call(path, ThinVec::from([expr])))) } fn is_mistaken_not_ident_negation(&self) -> bool { |
