Skip to content
Open
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 @@ -685,8 +685,7 @@ impl Pat {
| PatKind::Or(s) => s.iter().for_each(|p| p.walk(it)),

// Trivial wrappers over inner patterns.
PatKind::Box(s)
| PatKind::Deref(s)
PatKind::Deref(s)
| PatKind::Ref(s, _, _)
| PatKind::Paren(s)
| PatKind::Guard(s, _) => s.walk(it),
Expand Down Expand Up @@ -900,9 +899,6 @@ pub enum PatKind {
/// A tuple pattern (`(a, b)`).
Tuple(ThinVec<Pat>),

/// A `box` pattern.
Box(Box<Pat>),

/// A `deref` pattern (currently `deref!()` macro-based syntax).
Deref(Box<Pat>),

Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_ast_lowering/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
let (pats, ddpos) = self.lower_pat_tuple(pats, "tuple");
break hir::PatKind::Tuple(pats, ddpos);
}
PatKind::Box(inner) => {
break hir::PatKind::Box(self.lower_pat(inner));
}
PatKind::Deref(inner) => {
break hir::PatKind::Deref(self.lower_pat(inner));
}
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}
}
}
PatKind::Box(..) => {
gate!(self, box_patterns, pattern.span, "box pattern syntax is experimental");
}
_ => {}
}
visit::walk_pat(self, pattern)
Expand Down Expand Up @@ -608,7 +605,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {

// tidy-alphabetical-start
soft_gate_all_legacy_dont_use!(auto_traits, "`auto` traits are unstable");
soft_gate_all_legacy_dont_use!(box_patterns, "box pattern syntax is experimental");
soft_gate_all_legacy_dont_use!(decl_macro, "`macro` is experimental");
soft_gate_all_legacy_dont_use!(negative_impls, "negative impls are experimental");
soft_gate_all_legacy_dont_use!(specialization, "specialization is experimental");
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2011,10 +2011,6 @@ impl<'a> State<'a> {
}
self.pclose();
}
PatKind::Box(inner) => {
self.word("box ");
self.print_pat_paren_if_or(inner);
}
PatKind::Deref(inner) => {
self.word("deref!");
self.popen();
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 @@ -65,6 +65,8 @@ declare_features! (
Some("merged into `min_generic_const_args`")),
(removed, await_macro, "1.38.0", Some(50547),
Some("subsumed by `.await` syntax"), 62293),
/// Allows using `box` in patterns (RFC 469).
(removed, box_patterns, "CURRENT_RUSTC_VERSION", Some(29641), Some("superseded by `deref_patterns`")),
/// Allows using the `box $expr` syntax.
(removed, box_syntax, "1.70.0", Some(49733), Some("replaced with `#[rustc_box]`"), 108471),
/// Allows capturing disjoint fields in a closure/coroutine (RFC 2229).
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,6 @@ declare_features! (
/// Allows features specific to auto traits.
/// Renamed from `optin_builtin_traits`.
(unstable, auto_traits, "1.50.0", Some(13231)),
/// Allows using `box` in patterns (RFC 469).
(unstable, box_patterns, "1.0.0", Some(29641)),
/// Allows builtin # foo() syntax
(internal, builtin_syntax, "1.71.0", Some(110680)),
/// Allows `#[doc(notable_trait)]`.
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_lint/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,6 @@ impl EarlyLintPass for BadUseOfFindAttr {
find_attr_kind_in_pat(cx, pat);
}
}
PatKind::Box(pat) => {
find_attr_kind_in_pat(cx, pat);
}
PatKind::Deref(pat) => {
find_attr_kind_in_pat(cx, pat);
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,8 @@ impl EarlyLintPass for UnusedParens {
self.check_unused_parens_pat(cx, &f.pat, false, false, keep_space);
}
}
// Avoid linting on `i @ (p0 | .. | pn)` and `box (p0 | .. | pn)`, #64106.
Ident(.., Some(p)) | Box(p) | Deref(p) | Guard(p, _) => {
// Avoid linting on `i @ (p0 | .. | pn)`, #64106.
Ident(.., Some(p)) | Deref(p) | Guard(p, _) => {
self.check_unused_parens_pat(cx, p, true, false, keep_space)
}
// Avoid linting on `&(mut x)` as `&mut x` has a different meaning, #55342.
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_parse/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3728,6 +3728,13 @@ pub(crate) struct AddBoxNew {
pub hi: Span,
}

#[derive(Diagnostic)]
#[diag("`box_patterns` has been removed")]
pub(crate) struct BoxPatternsRemoved {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag("return type not allowed with return type notation")]
pub(crate) struct BadReturnTypeNotationOutput {
Expand Down
23 changes: 11 additions & 12 deletions compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ impl<'a> Parser<'a> {

// Sub-patterns
// FIXME: this doesn't work with recursive subpats (`&mut &mut <err>`)
PatKind::Box(subpat) | PatKind::Ref(subpat, _, _)
PatKind::Ref(subpat, _, _)
if matches!(subpat.kind, PatKind::Err(_) | PatKind::Expr(_)) =>
{
self.maybe_add_suggestions_then_emit(subpat.span, p.span, false)
Expand Down Expand Up @@ -1490,9 +1490,11 @@ impl<'a> Parser<'a> {

Ok(PatKind::Ident(BindingMode::NONE, Ident::new(kw::Box, box_span), sub))
} else {
let pat = Box::new(self.parse_pat_with_range_pat(false, None, None)?);
self.psess.gated_spans.gate(sym::box_patterns, box_span.to(self.prev_token.span));
Ok(PatKind::Box(pat))
self.parse_pat_with_range_pat(false, None, None)?;
let guar = self.dcx().emit_err(diagnostics::BoxPatternsRemoved {
span: box_span.to(self.prev_token.span),
});
Ok(PatKind::Err(guar))
}
}

Expand Down Expand Up @@ -1726,7 +1728,7 @@ impl<'a> Parser<'a> {
/// Parse a field in a struct pattern.
///
/// ```ebnf
/// PatField = FieldName ":" Pat | "box"? "mut"? ByRef? Ident
/// PatField = FieldName ":" Pat | "mut"? ByRef? Ident
/// ```
fn parse_pat_field(&mut self, lo: Span, attrs: AttrVec) -> PResult<'a, PatField> {
let hi;
Expand All @@ -1744,7 +1746,9 @@ impl<'a> Parser<'a> {
} else {
let is_box = self.eat_keyword(exp!(Box));
if is_box {
self.psess.gated_spans.gate(sym::box_patterns, self.prev_token.span);
return Err(self
.dcx()
.create_err(diagnostics::BoxPatternsRemoved { span: self.prev_token.span }));
}
let boxed_span = self.token.span;
let mutability = self.parse_mutability();
Expand All @@ -1760,12 +1764,7 @@ impl<'a> Parser<'a> {
) {
self.psess.gated_spans.gate(sym::mut_ref, fieldpat.span);
}
let subpat = if is_box {
self.mk_pat(lo.to(hi), PatKind::Box(Box::new(fieldpat)))
} else {
fieldpat
};
(subpat, fieldname, true)
(fieldpat, fieldname, true)
};

Ok(PatField {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_passes/src/input_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,6 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
Or,
Path,
Tuple,
Box,
Deref,
Ref,
Expr,
Expand Down
34 changes: 0 additions & 34 deletions src/doc/unstable-book/src/language-features/box-patterns.md

This file was deleted.

5 changes: 2 additions & 3 deletions src/doc/unstable-book/src/language-features/deref-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The tracking issue for this feature is: [#87121]

------------------------

> **Note**: This feature supersedes [`box_patterns`].
> **Note**: This feature supersedes `box_patterns`.

This feature permits pattern matching on [smart pointers in the standard library] through their
`Deref` target types, either implicitly or with explicit `deref!(_)` patterns (the syntax of which
Expand Down Expand Up @@ -52,7 +52,7 @@ if let [b] = &mut *v {
assert_eq!(v, [Box::new(Some(2))]);
```

Like [`box_patterns`], deref patterns may move out of boxes:
Deref patterns may move out of boxes:

```rust
# #![feature(deref_patterns)]
Expand Down Expand Up @@ -98,5 +98,4 @@ match *(b"test" as &[u8]) {
}
```

[`box_patterns`]: ./box-patterns.md
[smart pointers in the standard library]: https://doc.rust-lang.org/std/ops/trait.DerefPure.html#implementors
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/assigning_clones.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fn clone_source_borrows_from_dest(cx: &LateContext<'_>, lhs: &Expr<'_>, call_spa
.find(|stmt| {
!matches!(stmt.kind, mir::StatementKind::StorageDead(_) | mir::StatementKind::StorageLive(_))
})
&& let mir::StatementKind::Assign(box (borrowed, _)) = &assignment.kind
&& let mir::StatementKind::Assign((borrowed, _)) = &assignment.kind
&& let Some(borrowers) = borrow_map.get(&borrowed.local)
{
borrowers.contains(source.local)
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/double_parens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl EarlyLintPass for DoubleParens {
// ^^^^^^^^^ expr
// ^^^ arg
// ^ inner
ExprKind::Call(_, args) | ExprKind::MethodCall(box MethodCall { args, .. })
ExprKind::Call(_, args) | ExprKind::MethodCall(MethodCall { args, .. })
if let [arg] = &**args
&& let ExprKind::Paren(inner) = &arg.kind
&& expr.span.eq_ctxt(arg.span)
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(box_patterns)]
#![feature(deref_patterns)]
#![feature(control_flow_into_value)]
#![feature(exact_div)]
#![feature(f128)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ fn referent_used_exactly_once<'tcx>(
&& let [location] = *local_assignments(mir, local).as_slice()
&& let block_data = &mir.basic_blocks[location.block]
&& let Some(statement) = block_data.statements.get(location.statement_index)
&& let StatementKind::Assign(box (_, Rvalue::Ref(_, _, place))) = statement.kind
&& let StatementKind::Assign((_, Rvalue::Ref(_, _, place))) = statement.kind
&& !place.is_indirect_first_projection()
{
let body_owner_local_def_id = cx.tcx.hir_enclosing_body_owner(reference.hir_id);
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/non_expressive_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ impl EarlyLintPass for NonExpressiveNames {
return;
}

if let ItemKind::Fn(box ast::Fn {
if let ItemKind::Fn(ast::Fn {
ref sig,
body: Some(ref blk),
..
Expand All @@ -419,7 +419,7 @@ impl EarlyLintPass for NonExpressiveNames {
return;
}

if let AssocItemKind::Fn(box ast::Fn {
if let AssocItemKind::Fn(ast::Fn {
ref sig,
body: Some(ref blk),
..
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/option_env_unwrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ declare_lint_pass!(OptionEnvUnwrap => [OPTION_ENV_UNWRAP]);

impl EarlyLintPass for OptionEnvUnwrap {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
if let ExprKind::MethodCall(box MethodCall { seg, receiver, .. }) = &expr.kind
if let ExprKind::MethodCall(MethodCall { seg, receiver, .. }) = &expr.kind
&& matches!(seg.ident.name, sym::expect | sym::unwrap)
&& is_direct_expn_of(receiver.span, sym::option_env).is_some()
{
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/redundant_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ fn find_stmt_assigns_to<'tcx>(
bb: mir::BasicBlock,
) -> Option<(mir::Local, CannotMoveOut)> {
let rvalue = mir.basic_blocks[bb].statements.iter().rev().find_map(|stmt| {
if let mir::StatementKind::Assign(box (mir::Place { local, .. }, v)) = &stmt.kind {
if let mir::StatementKind::Assign((mir::Place { local, .. }, v)) = &stmt.kind {
return if *local == to_local { Some(v) } else { None };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ impl EarlyLintPass for RedundantStaticLifetimes {
}

if !item.span.from_expansion() {
if let ItemKind::Const(box ConstItem { ty: ref var_type, .. }) = item.kind {
if let ItemKind::Const(ConstItem { ty: ref var_type, .. }) = item.kind {
Self::visit_type(var_type, cx, "constants have by default a `'static` lifetime");
// Don't check associated consts because `'static` cannot be elided on those (issue
// #2438)
}

if let ItemKind::Static(box StaticItem { ty: ref var_type, .. }) = item.kind {
if let ItemKind::Static(StaticItem { ty: ref var_type, .. }) = item.kind {
Self::visit_type(var_type, cx, "statics have by default a `'static` lifetime");
}
}
Expand Down
15 changes: 7 additions & 8 deletions src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ fn insert_necessary_parens(pat: &mut Pat) {
use ast::BindingMode;
walk_pat(self, pat);
let target = match &mut pat.kind {
// `i @ a | b`, `box a | b`, and `& mut? a | b`.
Ident(.., Some(p)) | Box(p) | Ref(p, _, _)
// `i @ a | b` and `& mut? a | b`.
Ident(.., Some(p)) | Ref(p, _, _)
if let Or(ps) = &p.kind
&& ps.len() > 1 =>
{
Expand Down Expand Up @@ -248,17 +248,16 @@ fn transform_with_focus_on_idx(alternatives: &mut ThinVec<Pat>, focus_idx: usize
// FIXME(pin_ergonomics): handle pinned patterns
| Ref(_, _, Mutability::Not)
// Dealt with elsewhere.
| Or(_) | Paren(_) | Deref(_) | Guard(..) => false,
// Transform `box x | ... | box y` into `box (x | y)`.
| Or(_) | Paren(_) | Guard(..) => false,
// Transform `deref!(x) | ... | deref!(y)` into `deref!(x | y)`.
//
// The cases below until `Slice(...)` deal with *singleton* products.
// These patterns have the shape `C(p)`, and not e.g., `C(p0, ..., pn)`.
Box(target) => extend_with_matching(
Deref(target) => extend_with_matching(
target, start, alternatives,
|k| matches!(k, Box(_)),
|k| always_pat!(k, Box(p) => *p),
|k| matches!(k, Deref(_)),
|k| always_pat!(k, Deref(p) => *p),
),
// Transform `&mut x | ... | &mut y` into `&mut (x | y)`.
Ref(target, _, Mutability::Mut) => extend_with_matching(
target, start, alternatives,
|k| matches!(k, Ref(_, _, Mutability::Mut)),
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/unused_rounding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ declare_clippy_lint! {
declare_lint_pass!(UnusedRounding => [UNUSED_ROUNDING]);

fn is_useless_rounding(cx: &EarlyContext<'_>, expr: &Expr) -> Option<(Symbol, String)> {
if let ExprKind::MethodCall(box MethodCall {
if let ExprKind::MethodCall(MethodCall {
seg: name_ident,
receiver,
..
Expand Down
Loading
Loading