diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 45ea2dcd121ff..a5dc0bd57f173 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -686,8 +686,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), @@ -901,9 +900,6 @@ pub enum PatKind { /// A tuple pattern (`(a, b)`). Tuple(ThinVec), - /// A `box` pattern. - Box(Box), - /// A `deref` pattern (currently `deref!()` macro-based syntax). Deref(Box), diff --git a/compiler/rustc_ast_lowering/src/pat.rs b/compiler/rustc_ast_lowering/src/pat.rs index f83658d815bb1..a65b228e335c1 100644 --- a/compiler/rustc_ast_lowering/src/pat.rs +++ b/compiler/rustc_ast_lowering/src/pat.rs @@ -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)); } diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 01d81bab55075..bb64892337dd1 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -351,9 +351,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) @@ -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"); diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 462ac4a317611..977eb0ee4592d 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -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(); diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs index 43de680bfa747..f42ff9a2d93a4 100644 --- a/compiler/rustc_feature/src/removed.rs +++ b/compiler/rustc_feature/src/removed.rs @@ -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). diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 00ca1e07c93fd..3e0686f28010b 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -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)]`. diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 37b2ca7718498..7837c8ea82cf3 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1535,9 +1535,7 @@ impl<'hir> Pat<'hir> { match self.kind { Missing => unreachable!(), Wild | Never | Expr(_) | Range(..) | Binding(.., None) | Err(_) => true, - Box(s) | Deref(s) | Ref(s, _, _) | Binding(.., Some(s)) | Guard(s, _) => { - s.walk_short_(it) - } + Deref(s) | Ref(s, _, _) | Binding(.., Some(s)) | Guard(s, _) => s.walk_short_(it), Struct(_, fields, _) => fields.iter().all(|field| field.pat.walk_short_(it)), TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().all(|p| p.walk_short_(it)), Slice(before, slice, after) => { @@ -1564,7 +1562,7 @@ impl<'hir> Pat<'hir> { use PatKind::*; match self.kind { Missing | Wild | Never | Expr(_) | Range(..) | Binding(.., None) | Err(_) => {} - Box(s) | Deref(s) | Ref(s, _, _) | Binding(.., Some(s)) | Guard(s, _) => s.walk_(it), + Deref(s) | Ref(s, _, _) | Binding(.., Some(s)) | Guard(s, _) => s.walk_(it), Struct(_, fields, _) => fields.iter().for_each(|field| field.pat.walk_(it)), TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().for_each(|p| p.walk_(it)), Slice(before, slice, after) => { @@ -1646,7 +1644,6 @@ impl<'hir> Pat<'hir> { | PatKind::Struct(_, _, _) | PatKind::TupleStruct(_, _, _) | PatKind::Tuple(_, _) - | PatKind::Box(_) | PatKind::Ref(_, _, _) | PatKind::Deref(_) | PatKind::Expr(_) @@ -1792,9 +1789,6 @@ pub enum PatKind<'hir> { /// `0 <= position <= subpats.len()` Tuple(&'hir [Pat<'hir>], DotDotPos), - /// A `box` pattern. - Box(&'hir Pat<'hir>), - /// A `deref` pattern (currently `deref!()` macro-based syntax). Deref(&'hir Pat<'hir>), diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index 3b721392519a7..0d5da20b9b10a 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -746,9 +746,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) -> V: PatKind::Tuple(tuple_elements, _) => { walk_list!(visitor, visit_pat, tuple_elements); } - PatKind::Box(ref subpattern) - | PatKind::Deref(ref subpattern) - | PatKind::Ref(ref subpattern, _, _) => { + PatKind::Deref(ref subpattern) | PatKind::Ref(ref subpattern, _, _) => { try_visit!(visitor.visit_pat(subpattern)); } PatKind::Binding(_, _hir_id, ident, ref optional_subpattern) => { diff --git a/compiler/rustc_hir_analysis/src/check/region.rs b/compiler/rustc_hir_analysis/src/check/region.rs index b41eb832a6964..96acfd2f97177 100644 --- a/compiler/rustc_hir_analysis/src/check/region.rs +++ b/compiler/rustc_hir_analysis/src/check/region.rs @@ -585,9 +585,7 @@ fn resolve_local<'tcx>( | PatKind::TupleStruct(_, subpats, _) | PatKind::Tuple(subpats, _) => subpats.iter().any(|p| is_binding_pat(p)), - PatKind::Box(subpat) | PatKind::Deref(subpat) | PatKind::Guard(subpat, _) => { - is_binding_pat(subpat) - } + PatKind::Deref(subpat) | PatKind::Guard(subpat, _) => is_binding_pat(subpat), PatKind::Ref(_, _, _) | PatKind::Binding(hir::BindingMode(hir::ByRef::No, _), ..) diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index f2f485a30300a..a28f8c8a048b6 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -2088,17 +2088,6 @@ impl<'a> State<'a> { } self.pclose(); } - PatKind::Box(inner) => { - let is_range_inner = matches!(inner.kind, PatKind::Range(..)); - self.word("box "); - if is_range_inner { - self.popen(); - } - self.print_pat(inner); - if is_range_inner { - self.pclose(); - } - } PatKind::Deref(inner) => { self.word("deref!"); self.popen(); diff --git a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs index a3b7816ca8a92..e8f912165a4c5 100644 --- a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs @@ -953,7 +953,6 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx } } PatKind::Or(_) - | PatKind::Box(_) | PatKind::Ref(..) | PatKind::Guard(..) | PatKind::Tuple(..) @@ -1763,8 +1762,8 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx self.cat_pattern(place_with_id, subpat, op)?; } - PatKind::Box(subpat) | PatKind::Ref(subpat, _, _) => { - // box p1, &p1, &mut p1. we can ignore the mutability of + PatKind::Ref(subpat, _, _) => { + // &p1, &mut p1. we can ignore the mutability of // PatKind::Ref since that information is already contained // in the type. let subplace = self.cat_deref(pat.hir_id, place_with_id)?; diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index 19ba8e401fb54..7413215b15ba1 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -653,7 +653,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { PatKind::Tuple(elements, ddpos) => { self.check_pat_tuple(pat.span, elements, ddpos, expected, pat_info) } - PatKind::Box(inner) => self.check_pat_box(pat.span, inner, expected, pat_info), PatKind::Deref(inner) => self.check_pat_deref(pat.span, inner, expected, pat_info), PatKind::Ref(inner, pinned, mutbl) => { self.check_pat_ref(pat, inner, pinned, mutbl, expected, pat_info) @@ -762,9 +761,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // that the expected type be of those types and not reference types. PatKind::Tuple(..) | PatKind::Range(..) | PatKind::Slice(..) => AdjustMode::peel_all(), // When checking an explicit deref pattern, only peel reference types. - // FIXME(deref_patterns): If box patterns and deref patterns need to coexist, box - // patterns may want `PeelKind::Implicit`, stopping on encountering a box. - PatKind::Box(_) | PatKind::Deref(_) => { + PatKind::Deref(_) => { AdjustMode::Peel { kind: PeelKind::ExplicitDerefPat } } // A never pattern behaves somewhat like a literal or unit variant. @@ -1386,7 +1383,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | PatKind::Wild | PatKind::Never | PatKind::Binding(..) - | PatKind::Box(..) | PatKind::Deref(_) | PatKind::Ref(..) | PatKind::Expr(..) @@ -2709,32 +2705,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err } - fn check_pat_box( - &self, - span: Span, - inner: &'tcx Pat<'tcx>, - expected: Ty<'tcx>, - pat_info: PatInfo<'tcx>, - ) -> Ty<'tcx> { - let tcx = self.tcx; - let (box_ty, inner_ty) = self - .check_dereferenceable(span, expected, inner) - .and_then(|()| { - // Here, `demand::subtype` is good enough, but I don't - // think any errors can be introduced by using `demand::eqtype`. - let inner_ty = self.next_ty_var(inner.span); - let box_ty = Ty::new_box(tcx, inner_ty); - self.demand_eqtype_pat(span, expected, box_ty, &pat_info.top_info)?; - Ok((box_ty, inner_ty)) - }) - .unwrap_or_else(|guar| { - let err = Ty::new_error(tcx, guar); - (err, err) - }); - self.check_pat(inner, inner_ty, pat_info); - box_ty - } - fn check_pat_deref( &self, span: Span, diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index fb9fda0e94989..9746b52dda41e 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -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); } @@ -763,7 +760,6 @@ fn pat_is_not_exhaustive_heuristic(pat: &hir::Pat<'_>) -> Option<(Span, &'static hir::PatKind::Or(..) => None, hir::PatKind::Never => None, hir::PatKind::Tuple(..) => None, - hir::PatKind::Box(pat) => pat_is_not_exhaustive_heuristic(&*pat), hir::PatKind::Deref(pat) => pat_is_not_exhaustive_heuristic(&*pat), hir::PatKind::Ref(pat, _, _) => pat_is_not_exhaustive_heuristic(&*pat), hir::PatKind::Expr(..) => None, diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 0d4903afc32e2..c78c2de5f8dd1 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -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. diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 8e7d3d0d9c656..f65295080f61d 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -817,8 +817,6 @@ pub enum PatKind<'tcx> { /// Explicit or implicit `deref!(..)` pattern, under `feature(deref_patterns)`. /// Represents a call to `Deref` or `DerefMut`, or a deref-move of `Box`. - /// - /// `box P` patterns also lower to this, under `feature(box_patterns)`. DerefPattern { subpattern: Box>, /// Whether the pattern scrutinee needs to be borrowed in order to call `Deref::deref` or diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index 07a3c8cc530e9..b69519f3c714f 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -16,7 +16,7 @@ use rustc_hir::pat_util::EnumerateAndAdjustIterator; use rustc_hir::{self as hir, RangeEnd}; use rustc_index::Idx; use rustc_middle::thir::{ - Ascription, DerefPatBorrowMode, FieldPat, LocalVarId, Pat, PatKind, PatRange, PatRangeBoundary, + Ascription, FieldPat, LocalVarId, Pat, PatKind, PatRange, PatRangeBoundary, }; use rustc_middle::ty::adjustment::{PatAdjust, PatAdjustment}; use rustc_middle::ty::layout::IntegerExt; @@ -352,11 +352,6 @@ impl<'tcx, 'ptcx> PatCtxt<'tcx, 'ptcx> { } PatKind::Deref { pin, subpattern } } - hir::PatKind::Box(subpattern) => PatKind::DerefPattern { - subpattern: self.lower_pattern(subpattern), - borrow: DerefPatBorrowMode::Box, - }, - hir::PatKind::Slice(prefix, slice, suffix) => { return self.slice_or_array_pattern(pat, prefix, slice, suffix); } diff --git a/compiler/rustc_parse/src/diagnostics.rs b/compiler/rustc_parse/src/diagnostics.rs index 397baa0ae4ddb..2be549703e4e6 100644 --- a/compiler/rustc_parse/src/diagnostics.rs +++ b/compiler/rustc_parse/src/diagnostics.rs @@ -3749,6 +3749,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 { diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 6fa8bdcccaee4..4d6a09039f63b 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -666,7 +666,7 @@ impl<'a> Parser<'a> { // Sub-patterns // FIXME: this doesn't work with recursive subpats (`&mut &mut `) - 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) @@ -1623,7 +1623,8 @@ impl<'a> Parser<'a> { }) } - /// Parses `box pat` + // FIXME: remove this entirely eventually + /// Parses the removed `box pat` syntax to provide a more helpful error message. fn parse_pat_box(&mut self) -> PResult<'a, PatKind> { let box_span = self.prev_token.span; @@ -1647,8 +1648,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.dcx().emit_err(diagnostics::BoxPatternsRemoved { + span: box_span.to(self.prev_token.span), + }); + // Treat the box pattern like a deref pattern to avoid lots of "value not found" errors. + Ok(PatKind::Deref(pat)) } } @@ -1882,7 +1886,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; @@ -1898,9 +1902,12 @@ impl<'a> Parser<'a> { hi = pat.span; (pat, fieldname, false) } else { + // FIXME: remove the recovery for parsing box patterrns entirely let is_box = self.eat_keyword(exp!(Box)); if is_box { - self.psess.gated_spans.gate(sym::box_patterns, self.prev_token.span); + self.dcx() + .create_err(diagnostics::BoxPatternsRemoved { span: self.prev_token.span }) + .emit(); } let boxed_span = self.token.span; let mutability = self.parse_mutability(); @@ -1917,7 +1924,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))) + self.mk_pat(lo.to(hi), PatKind::Deref(Box::new(fieldpat))) } else { fieldpat }; diff --git a/compiler/rustc_passes/src/input_stats.rs b/compiler/rustc_passes/src/input_stats.rs index 87193b73a1a95..05a8f08fba69d 100644 --- a/compiler/rustc_passes/src/input_stats.rs +++ b/compiler/rustc_passes/src/input_stats.rs @@ -324,7 +324,6 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { Or, Never, Tuple, - Box, Deref, Ref, Expr, @@ -635,7 +634,6 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { Or, Path, Tuple, - Box, Deref, Ref, Expr, diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs index fc32e31474e00..ae5eefa1cded8 100644 --- a/compiler/rustc_pattern_analysis/src/rustc.rs +++ b/compiler/rustc_pattern_analysis/src/rustc.rs @@ -824,14 +824,6 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { print::write_ref_like(&mut s, pat.ty().inner(), &print(&pat.fields[0])).unwrap(); s } - DerefPattern(_) if pat.ty().is_box() && !self.tcx.features().deref_patterns() => { - // FIXME(deref_patterns): Remove this special handling once `box_patterns` is gone. - // HACK(@dianne): `box _` syntax is exposed on stable in diagnostics, e.g. to - // witness non-exhaustiveness of `match Box::new(0) { Box { .. } if false => {} }`. - // To avoid changing diagnostics before deref pattern syntax is finalized, let's use - // `box _` syntax unless `deref_patterns` is enabled. - format!("box {}", print(&pat.fields[0])) - } DerefPattern(_) => format!("deref!({})", print(&pat.fields[0])), Slice(slice) => { let (prefix_len, has_dot_dot) = match slice.kind { diff --git a/src/doc/unstable-book/src/language-features/box-patterns.md b/src/doc/unstable-book/src/language-features/box-patterns.md deleted file mode 100644 index c8a15b8477eee..0000000000000 --- a/src/doc/unstable-book/src/language-features/box-patterns.md +++ /dev/null @@ -1,34 +0,0 @@ -# `box_patterns` - -The tracking issue for this feature is: [#29641] - -[#29641]: https://github.com/rust-lang/rust/issues/29641 - ------------------------- - -> **Note**: This feature will be superseded by [`deref_patterns`] in the future. - -Box patterns let you match on `Box`s: - - -```rust -#![feature(box_patterns)] - -fn main() { - let b = Some(Box::new(5)); - match b { - Some(box n) if n < 0 => { - println!("Box contains negative number {n}"); - }, - Some(box n) if n >= 0 => { - println!("Box contains non-negative number {n}"); - }, - None => { - println!("No box"); - }, - _ => unreachable!() - } -} -``` - -[`deref_patterns`]: ./deref-patterns.md diff --git a/src/doc/unstable-book/src/language-features/deref-patterns.md b/src/doc/unstable-book/src/language-features/deref-patterns.md index a0c9a7e30277e..ffae28cadc15c 100644 --- a/src/doc/unstable-book/src/language-features/deref-patterns.md +++ b/src/doc/unstable-book/src/language-features/deref-patterns.md @@ -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 @@ -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)] @@ -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 diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 20a466fd3dee9..d13a3fdb864bf 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -313,7 +313,7 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol { return kw::Underscore; } PatKind::Binding(_, _, ident, _) => return ident.name, - PatKind::Box(p) | PatKind::Ref(p, _, _) | PatKind::Guard(p, _) => return name_from_pat(p), + PatKind::Ref(p, _, _) | PatKind::Guard(p, _) => return name_from_pat(p), PatKind::TupleStruct(p, ..) | PatKind::Expr(PatExpr { kind: PatExprKind::Path(p), .. }) => { qpath_to_string(p) } diff --git a/src/tools/clippy/clippy_lints/src/equatable_if_let.rs b/src/tools/clippy/clippy_lints/src/equatable_if_let.rs index 5719561b99ca1..5c5626fa5eda3 100644 --- a/src/tools/clippy/clippy_lints/src/equatable_if_let.rs +++ b/src/tools/clippy/clippy_lints/src/equatable_if_let.rs @@ -55,7 +55,7 @@ fn is_unary_pattern(pat: &Pat<'_>) -> bool { | PatKind::Err(_) => false, PatKind::Struct(_, a, etc) => etc.is_none() && a.iter().all(|x| is_unary_pattern(x.pat)), PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => etc.as_opt_usize().is_none() && array_rec(a), - PatKind::Ref(x, _, _) | PatKind::Box(x) | PatKind::Deref(x) | PatKind::Guard(x, _) => is_unary_pattern(x), + PatKind::Ref(x, _, _) | PatKind::Deref(x) | PatKind::Guard(x, _) => is_unary_pattern(x), PatKind::Expr(_) => true, } } diff --git a/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs b/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs index df93f142fddaa..4673fa194d0b0 100644 --- a/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs +++ b/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs @@ -265,7 +265,6 @@ impl<'a> NormalizedPat<'a> { PatKind::Missing => unreachable!(), PatKind::Wild | PatKind::Binding(.., None) => Self::Wild, PatKind::Binding(.., Some(pat)) - | PatKind::Box(pat) | PatKind::Deref(pat) | PatKind::Ref(pat, _, _) | PatKind::Guard(pat, _) => Self::from_pat(cx, arena, pat), diff --git a/src/tools/clippy/clippy_lints/src/matches/single_match.rs b/src/tools/clippy/clippy_lints/src/matches/single_match.rs index 4a1e2090224d2..f3e7d080237c8 100644 --- a/src/tools/clippy/clippy_lints/src/matches/single_match.rs +++ b/src/tools/clippy/clippy_lints/src/matches/single_match.rs @@ -375,7 +375,6 @@ impl<'a> PatState<'a> { // Patterns for things which can only contain a single sub-pattern. PatKind::Binding(_, _, _, Some(pat)) | PatKind::Ref(pat, _, _) - | PatKind::Box(pat) | PatKind::Deref(pat) => { self.add_pat(cx, pat) }, diff --git a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs index 23c137c25f823..184427c4dba7e 100644 --- a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs +++ b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs @@ -147,8 +147,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 => { @@ -254,15 +254,8 @@ fn transform_with_focus_on_idx(alternatives: &mut ThinVec, focus_idx: usize |k| matches!(k, Deref(_)), |k| always_pat!(k, Deref(p) => *p), ), - // Transform `box x | ... | box y` into `box (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( - target, start, alternatives, - |k| matches!(k, Box(_)), - |k| always_pat!(k, Box(p) => *p), - ), // Transform `&mut x | ... | &mut y` into `&mut (x | y)`. Ref(target, _, Mutability::Mut) => extend_with_matching( target, start, alternatives, diff --git a/src/tools/clippy/clippy_lints/src/utils/author.rs b/src/tools/clippy/clippy_lints/src/utils/author.rs index 0619fafb798c2..a32a641c34ee5 100644 --- a/src/tools/clippy/clippy_lints/src/utils/author.rs +++ b/src/tools/clippy/clippy_lints/src/utils/author.rs @@ -804,11 +804,6 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> { kind!("Tuple({fields}, {skip_pos:?})"); self.slice(fields, |field| self.pat(field)); }, - PatKind::Box(pat) => { - bind!(self, pat); - kind!("Box({pat})"); - self.pat(pat); - }, PatKind::Deref(pat) => { bind!(self, pat); kind!("Deref({pat})"); diff --git a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs index 03af2609d250a..944dedb775729 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs @@ -47,7 +47,6 @@ pub fn eq_pat(l: &Pat, r: &Pat) -> bool { && eq_expr_opt(lt.as_deref(), rt.as_deref()) && eq_range_end(le.node, re.node) }, - (Box(l), Box(r)) => eq_pat(l, r), (Ref(l, l_pin, l_mut), Ref(r, r_pin, r_mut)) => l_pin == r_pin && l_mut == r_mut && eq_pat(l, r), (Tuple(l), Tuple(r)) | (Slice(l), Slice(r)) => over(l, r, eq_pat), (Path(lq, lp), Path(rq, rp)) => both(lq.as_deref(), rq.as_deref(), eq_qself) && eq_path(lp, rp), @@ -159,13 +158,13 @@ fn eq_expr(l: &Expr, r: &Expr) -> bool { (Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value), (Call(lc, la), Call(rc, ra)) => eq_expr(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)), ( - MethodCall(box ast::MethodCall { + MethodCall(ast::MethodCall { seg: ls, receiver: lr, args: la, .. }), - MethodCall(box ast::MethodCall { + MethodCall(ast::MethodCall { seg: rs, receiver: rr, args: ra, @@ -206,7 +205,7 @@ fn eq_expr(l: &Expr, r: &Expr) -> bool { (Field(lp, lf), Field(rp, rf)) => eq_id(*lf, *rf) && eq_expr(lp, rp), (Match(ls, la, lkind), Match(rs, ra, rkind)) => (lkind == rkind) && eq_expr(ls, rs) && over(la, ra, eq_arm), ( - Closure(box ast::Closure { + Closure(ast::Closure { binder: lb, capture_clause: lc, coroutine_marker: lcm, @@ -215,7 +214,7 @@ fn eq_expr(l: &Expr, r: &Expr) -> bool { body: le, .. }), - Closure(box ast::Closure { + Closure(ast::Closure { binder: rb, capture_clause: rc, coroutine_marker: rcm, @@ -312,7 +311,7 @@ fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { (ExternCrate(ls, li), ExternCrate(rs, ri)) => ls == rs && eq_id(*li, *ri), (Use(l), Use(r)) => eq_use_tree(l, r), ( - Static(box StaticItem { + Static(StaticItem { ident: li, ty: lt, mutability: lm, @@ -321,7 +320,7 @@ fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { define_opaque: _, eii_impl: _, }), - Static(box StaticItem { + Static(StaticItem { ident: ri, ty: rt, mutability: rm, @@ -332,7 +331,7 @@ fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { }), ) => eq_id(*li, *ri) && lm == rm && ls == rs && eq_ty(lt, rt) && eq_expr_opt(le.as_deref(), re.as_deref()), ( - Const(box ConstItem { + Const(ConstItem { defaultness: ld, ident: li, generics: lg, @@ -341,7 +340,7 @@ fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { kind: lk, define_opaque: _, }), - Const(box ConstItem { + Const(ConstItem { defaultness: rd, ident: ri, generics: rg, @@ -360,7 +359,7 @@ fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { && both(lb.as_deref(), rb.as_deref(), eq_expr) }, ( - Fn(box ast::Fn { + Fn(ast::Fn { defaultness: ld, sig: lf, ident: li, @@ -370,7 +369,7 @@ fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { define_opaque: _, eii_impl: _, }), - Fn(box ast::Fn { + Fn(ast::Fn { defaultness: rd, sig: rf, ident: ri, @@ -404,14 +403,14 @@ fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { && over(&l.items, &r.items, |l, r| eq_item(l, r, eq_foreign_item_kind)) }, ( - TyAlias(box ast::TyAlias { + TyAlias(ast::TyAlias { defaultness: ld, generics: lg, bounds: lb, ty: lt, .. }), - TyAlias(box ast::TyAlias { + TyAlias(ast::TyAlias { defaultness: rd, generics: rg, bounds: rb, @@ -431,7 +430,7 @@ fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { eq_id(*li, *ri) && eq_generics(lg, rg) && eq_variant_data(lv, rv) }, ( - Trait(box ast::Trait { + Trait(ast::Trait { impl_restriction: liprt, constness: lc, is_auto: la, @@ -441,7 +440,7 @@ fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { bounds: lb, items: lis, }), - Trait(box ast::Trait { + Trait(ast::Trait { impl_restriction: riprt, constness: rc, is_auto: ra, @@ -462,13 +461,13 @@ fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { && over(lis, ris, |l, r| eq_item(l, r, eq_assoc_item_kind)) }, ( - TraitAlias(box ast::TraitAlias { + TraitAlias(ast::TraitAlias { ident: li, generics: lg, bounds: lb, constness: lc, }), - TraitAlias(box ast::TraitAlias { + TraitAlias(ast::TraitAlias { ident: ri, generics: rg, bounds: rb, @@ -519,7 +518,7 @@ fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { use ForeignItemKind::*; match (l, r) { ( - Static(box StaticItem { + Static(StaticItem { ident: li, ty: lt, mutability: lm, @@ -528,7 +527,7 @@ fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { define_opaque: _, eii_impl: _, }), - Static(box StaticItem { + Static(StaticItem { ident: ri, ty: rt, mutability: rm, @@ -539,7 +538,7 @@ fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { }), ) => eq_id(*li, *ri) && eq_ty(lt, rt) && lm == rm && eq_expr_opt(le.as_deref(), re.as_deref()) && ls == rs, ( - Fn(box ast::Fn { + Fn(ast::Fn { defaultness: ld, sig: lf, ident: li, @@ -549,7 +548,7 @@ fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { define_opaque: _, eii_impl: _, }), - Fn(box ast::Fn { + Fn(ast::Fn { defaultness: rd, sig: rf, ident: ri, @@ -568,7 +567,7 @@ fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { && both(lb.as_ref(), rb.as_ref(), |l, r| eq_block(l, r)) }, ( - TyAlias(box ast::TyAlias { + TyAlias(ast::TyAlias { defaultness: ld, ident: li, generics: lg, @@ -576,7 +575,7 @@ fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { bounds: lb, ty: lt, }), - TyAlias(box ast::TyAlias { + TyAlias(ast::TyAlias { defaultness: rd, ident: ri, generics: rg, @@ -601,7 +600,7 @@ fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { use AssocItemKind::*; match (l, r) { ( - Const(box ConstItem { + Const(ConstItem { defaultness: ld, ident: li, generics: lg, @@ -610,7 +609,7 @@ fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { kind: lk, define_opaque: _, }), - Const(box ConstItem { + Const(ConstItem { defaultness: rd, ident: ri, generics: rg, @@ -628,7 +627,7 @@ fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { && both(lb.as_deref(), rb.as_deref(), eq_expr) }, ( - Fn(box ast::Fn { + Fn(ast::Fn { defaultness: ld, sig: lf, ident: li, @@ -638,7 +637,7 @@ fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { define_opaque: _, eii_impl: _, }), - Fn(box ast::Fn { + Fn(ast::Fn { defaultness: rd, sig: rf, ident: ri, @@ -657,7 +656,7 @@ fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { && both(lb.as_ref(), rb.as_ref(), |l, r| eq_block(l, r)) }, ( - Type(box TyAlias { + Type(TyAlias { defaultness: ld, ident: li, generics: lg, @@ -665,7 +664,7 @@ fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { bounds: lb, ty: lt, }), - Type(box TyAlias { + Type(TyAlias { defaultness: rd, ident: ri, generics: rg, diff --git a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs index 9f69c74596d50..cbbbca7e60388 100644 --- a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs +++ b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs @@ -634,10 +634,6 @@ fn pat_search_pat(tcx: TyCtxt<'_>, pat: &rustc_hir::Pat<'_>) -> (Pat, Pat) { (start, end) }, PatKind::Never => (Pat::Str("!"), Pat::Str("")), - PatKind::Box(p) => { - let (_, end) = pat_search_pat(tcx, p); - (Pat::Str("box"), end) - }, PatKind::Deref(_) => (Pat::Str("deref!"), Pat::Str("")), PatKind::Ref(p, _, _) => { let (_, end) = pat_search_pat(tcx, p); diff --git a/src/tools/clippy/clippy_utils/src/hir_utils.rs b/src/tools/clippy/clippy_utils/src/hir_utils.rs index 75987ea96ce90..a229de847b92e 100644 --- a/src/tools/clippy/clippy_utils/src/hir_utils.rs +++ b/src/tools/clippy/clippy_utils/src/hir_utils.rs @@ -788,7 +788,6 @@ impl HirEqInterExpr<'_, '_, '_> { /// Checks whether two patterns are the same. fn eq_pat(&mut self, left: &Pat<'_>, right: &Pat<'_>) -> bool { match (&left.kind, &right.kind) { - (PatKind::Box(l), PatKind::Box(r)) => self.eq_pat(l, r), (PatKind::Struct(lp, la, ..), PatKind::Struct(rp, ra, ..)) => { self.eq_qpath(lp, rp) && over(la, ra, |l, r| self.eq_pat_field(l, r)) }, @@ -1468,7 +1467,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_pat(pat); } }, - PatKind::Box(pat) | PatKind::Deref(pat) => self.hash_pat(pat), + PatKind::Deref(pat) => self.hash_pat(pat), PatKind::Expr(expr) => self.hash_pat_expr(expr), PatKind::Or(pats) => { for pat in *pats { diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 8b47c79aa6da2..464b5fcfeb04e 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(box_patterns)] #![feature(deref_patterns)] #![feature(macro_metavar_expr)] #![feature(rustc_private)] @@ -1490,7 +1489,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { PatKind::Missing => unreachable!(), PatKind::Wild | PatKind::Never => false, // If `!` typechecked then the type is empty, so not refutable. PatKind::Binding(_, _, _, pat) => pat.is_some_and(|pat| is_refutable(cx, pat)), - PatKind::Box(pat) | PatKind::Ref(pat, _, _) => is_refutable(cx, pat), + PatKind::Ref(pat, _, _) => is_refutable(cx, pat), PatKind::Expr(PatExpr { kind: PatExprKind::Path(qpath), hir_id, diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs index 820c8b550548c..3033755423387 100644 --- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs +++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs @@ -194,7 +194,7 @@ fn check_rvalue<'tcx>( "transmute can attempt to turn pointers into integers, so is unstable in const fn".into(), )), // binops are fine on integers - Rvalue::BinaryOp(_, box (lhs, rhs)) => { + Rvalue::BinaryOp(_, (lhs, rhs)) => { check_operand(cx, lhs, span, body, msrv)?; check_operand(cx, rhs, span, body, msrv)?; let ty = lhs.ty(body, cx.tcx); @@ -236,18 +236,18 @@ fn check_statement<'tcx>( ) -> McfResult { let span = statement.source_info.span; match &statement.kind { - StatementKind::Assign(box (place, rval)) => { + StatementKind::Assign((place, rval)) => { check_place(cx, *place, span, body, msrv)?; check_rvalue(cx, body, def_id, rval, span, msrv) }, - StatementKind::FakeRead(box (_, place)) => check_place(cx, *place, span, body, msrv), + StatementKind::FakeRead((_, place)) => check_place(cx, *place, span, body, msrv), // just an assignment StatementKind::SetDiscriminant { place, .. } => check_place(cx, **place, span, body, msrv), - StatementKind::Intrinsic(box NonDivergingIntrinsic::Assume(op)) => check_operand(cx, op, span, body, msrv), + StatementKind::Intrinsic(NonDivergingIntrinsic::Assume(op)) => check_operand(cx, op, span, body, msrv), - StatementKind::Intrinsic(box NonDivergingIntrinsic::CopyNonOverlapping( + StatementKind::Intrinsic(NonDivergingIntrinsic::CopyNonOverlapping( rustc_middle::mir::CopyNonOverlapping { dst, src, count }, )) => { check_operand(cx, dst, span, body, msrv)?; diff --git a/src/tools/rustfmt/src/patterns.rs b/src/tools/rustfmt/src/patterns.rs index 2fad1d41ae9f7..62a72c4dc433e 100644 --- a/src/tools/rustfmt/src/patterns.rs +++ b/src/tools/rustfmt/src/patterns.rs @@ -70,10 +70,9 @@ fn is_short_pattern_inner(context: &RewriteContext<'_>, pat: &ast::Pat) -> bool ast::PatKind::TupleStruct(_, ref path, ref subpats) => { path.segments.len() <= 1 && subpats.len() <= 1 } - ast::PatKind::Box(ref p) - | PatKind::Deref(ref p) - | ast::PatKind::Ref(ref p, _, _) - | ast::PatKind::Paren(ref p) => is_short_pattern_inner(context, &*p), + PatKind::Deref(ref p) | ast::PatKind::Ref(ref p, _, _) | ast::PatKind::Paren(ref p) => { + is_short_pattern_inner(context, &*p) + } PatKind::Or(ref pats) => pats.iter().all(|p| is_short_pattern_inner(context, p)), } } @@ -114,7 +113,6 @@ impl Rewrite for Pat { .ends_with_newline(false); write_list(&items, &fmt) } - PatKind::Box(ref pat) => rewrite_unary_prefix(context, "box ", &**pat, shape), PatKind::Ident(BindingMode(by_ref, mutability), ident, ref sub_pat) => { let mut_prefix = format_mutability(mutability).trim(); @@ -528,7 +526,7 @@ pub(crate) fn can_be_overflowed_pat( | ast::PatKind::Tuple(..) | ast::PatKind::Struct(..) | ast::PatKind::TupleStruct(..) => context.use_block_indent() && len == 1, - ast::PatKind::Ref(ref p, _, _) | ast::PatKind::Box(ref p) => { + ast::PatKind::Ref(ref p, _, _) => { can_be_overflowed_pat(context, &TuplePatField::Pat(p), len) } ast::PatKind::Expr(ref expr) => can_be_overflowed_expr(context, expr, len), diff --git a/tests/debuginfo/destructured-fn-argument.rs b/tests/debuginfo/destructured-fn-argument.rs index c61f0240049d7..439aeb1d491c1 100644 --- a/tests/debuginfo/destructured-fn-argument.rs +++ b/tests/debuginfo/destructured-fn-argument.rs @@ -300,7 +300,7 @@ //@ lldb-command:continue #![allow(unused_variables)] -#![feature(box_patterns)] +#![feature(deref_patterns)] use self::Univariant::Unit; @@ -370,7 +370,7 @@ fn contained_borrowed_pointer((&cc, _): (&isize, isize)) { zzz(); // #break } -fn unique_pointer(box dd: Box<(isize, isize, isize)>) { +fn unique_pointer(deref!(dd): Box<(isize, isize, isize)>) { zzz(); // #break } diff --git a/tests/debuginfo/destructured-for-loop-variable.rs b/tests/debuginfo/destructured-for-loop-variable.rs index 7e5420f167631..b8cde881b9ce6 100644 --- a/tests/debuginfo/destructured-for-loop-variable.rs +++ b/tests/debuginfo/destructured-for-loop-variable.rs @@ -142,7 +142,7 @@ //@ lldb-command:continue #![allow(unused_variables)] -#![feature(box_patterns)] +#![feature(deref_patterns)] struct Struct { x: i16, @@ -186,7 +186,7 @@ fn main() { for &(v1, &Struct { x: x1, y: ref y1, z: z1 }, Struct { x: ref x2, y: y2, z: ref z2 }, - box v2) in [more_complex].iter() { + deref!(v2)) in [more_complex].iter() { zzz(); // #break } diff --git a/tests/debuginfo/destructured-local.rs b/tests/debuginfo/destructured-local.rs index 07f35540483ef..a98b6efd27c72 100644 --- a/tests/debuginfo/destructured-local.rs +++ b/tests/debuginfo/destructured-local.rs @@ -233,7 +233,7 @@ #![allow(unused_variables)] -#![feature(box_patterns)] +#![feature(deref_patterns)] use self::Univariant::Unit; @@ -291,7 +291,7 @@ fn main() { let (&cc, _) = (&38, 39); // unique pointer - let box dd = Box::new((40, 41, 42)); + let deref!(dd) = Box::new((40, 41, 42)); // ref binding let ref ee = (43, 44, 45); diff --git a/tests/pretty/or-pattern-paren.pp b/tests/pretty/or-pattern-paren.pp index 6ea94eb7b91f8..2a0300dac4682 100644 --- a/tests/pretty/or-pattern-paren.pp +++ b/tests/pretty/or-pattern-paren.pp @@ -1,6 +1,6 @@ #![feature(prelude_import)] #![no_std] -#![feature(box_patterns)] +#![feature(deref_patterns)] extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; @@ -23,5 +23,5 @@ } } fn check_ref(x: &i32) { match x { &(1 | 2 | 3) => {} _ => {} } } -fn check_box(x: Box) { match x { box (1 | 2 | 3) => {} _ => {} } } +fn check_box(x: Box) { match x { deref!(1 | 2 | 3) => {} _ => {} } } fn main() { check_at(Some(2)); check_ref(&1); check_box(Box::new(1)); } diff --git a/tests/pretty/or-pattern-paren.rs b/tests/pretty/or-pattern-paren.rs index ea6a8f3de9e49..3ab32543c11fb 100644 --- a/tests/pretty/or-pattern-paren.rs +++ b/tests/pretty/or-pattern-paren.rs @@ -1,4 +1,4 @@ -#![feature(box_patterns)] +#![feature(deref_patterns)] //@ pretty-compare-only //@ pretty-mode:expanded @@ -24,7 +24,7 @@ fn check_ref(x: &i32) { fn check_box(x: Box) { match x { - box or_pat!(1, 2, 3) => {} + deref!(or_pat!(1, 2, 3)) => {} _ => {} } } diff --git a/tests/ui/README.md b/tests/ui/README.md index a3617fb6b07c9..b80c8215c1cf8 100644 --- a/tests/ui/README.md +++ b/tests/ui/README.md @@ -179,12 +179,11 @@ Tests for borrow checking. E.g. lifetime analysis, borrowing rules, and diagnost ## `tests/ui/box/`: Box Behavior -Tests for `Box` smart pointer and `#![feature(box_patterns)]`. E.g. allocation, deref coercion, and edge cases in box pattern matching and placement. +Tests for the `Box` smart pointer. E.g. allocation, deref coercion, and edge cases in box pattern matching and placement. See: - [`std::box::Boxed`](https://doc.rust-lang.org/std/boxed/struct.Box.html) -- [Tracking issue for `box_patterns` feature #29641](https://github.com/rust-lang/rust/issues/29641) ## `tests/ui/builtin-superkinds/`: Built-in Trait Hierarchy Tests diff --git a/tests/ui/binding/func-arg-ref-pattern.rs b/tests/ui/binding/func-arg-ref-pattern.rs index 56634544bc9e2..113d22616fb2b 100644 --- a/tests/ui/binding/func-arg-ref-pattern.rs +++ b/tests/ui/binding/func-arg-ref-pattern.rs @@ -4,14 +4,14 @@ // boxes. Make sure that we don't free the box as we match the // pattern. -#![feature(box_patterns)] +#![feature(deref_patterns)] -fn getaddr(box ref x: Box) -> *const usize { +fn getaddr(deref!(ref x): Box) -> *const usize { let addr: *const usize = &*x; addr } -fn checkval(box ref x: Box) -> usize { +fn checkval(deref!(ref x): Box) -> usize { *x } diff --git a/tests/ui/binding/range-inclusive-pattern-precedence.rs b/tests/ui/binding/range-inclusive-pattern-precedence.rs index 378ea00ee6917..da936021bc57f 100644 --- a/tests/ui/binding/range-inclusive-pattern-precedence.rs +++ b/tests/ui/binding/range-inclusive-pattern-precedence.rs @@ -1,5 +1,4 @@ //@ run-pass -#![feature(box_patterns)] const VALUE: usize = 21; @@ -12,12 +11,4 @@ pub fn main() { &(VALUE..=VALUE) => {} _ => { unreachable!(); } } - match Box::new(18) { - box (18..=18) => {} - _ => { unreachable!(); } - } - match Box::new(21) { - box (VALUE..=VALUE) => {} - _ => { unreachable!(); } - } } diff --git a/tests/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs b/tests/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs similarity index 76% rename from tests/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs rename to tests/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs index baf31bd89f40a..1bf008e05e3b2 100644 --- a/tests/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs +++ b/tests/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs @@ -1,5 +1,5 @@ // Tests using a combination of pattern features has the expected borrow checking behavior -#![feature(box_patterns)] +#![feature(deref_patterns)] enum Test { Foo, @@ -101,11 +101,11 @@ fn bindings_after_at_or_patterns_borrows_mut(mut x: Option) { drop(r); } -// bindings_after_at + box_patterns +// bindings_after_at + deref_patterns -fn bindings_after_at_box_patterns_borrows_both(mut x: Option>) { +fn bindings_after_at_deref_patterns_borrows_both(mut x: Option>) { let r = match x { - ref foo @ Some(box ref s) => Some(foo), + ref foo @ Some(deref!(ref s)) => Some(foo), _ => None, }; @@ -115,9 +115,9 @@ fn bindings_after_at_box_patterns_borrows_both(mut x: Option>) { drop(r); } -fn bindings_after_at_box_patterns_borrows_mut(mut x: Option>) { +fn bindings_after_at_deref_patterns_borrows_mut(mut x: Option>) { match x { - ref foo @ Some(box ref mut s) => (), + ref foo @ Some(deref!(ref mut s)) => (), //~^ ERROR cannot borrow _ => (), }; @@ -159,11 +159,11 @@ fn bindings_after_at_slice_patterns_or_patterns_borrows_slice(mut x: [Option>; 4]) { +fn bindings_after_at_slice_patterns_deref_patterns_borrows(mut x: [Option>; 4]) { let r = match x { - [_, ref a @ Some(box ref b), ..] => Some(a), + [_, ref a @ Some(deref!(ref b)), ..] => Some(a), _ => None, }; @@ -173,13 +173,13 @@ fn bindings_after_at_slice_patterns_box_patterns_borrows(mut x: [Option>; 4] ) { let r = match x { - [_, ref a @ Some(box Test::Foo | box Test::Bar), ..] => Some(a), + [_, ref a @ Some(deref!(Test::Foo) | deref!(Test::Bar)), ..] => Some(a), _ => None, }; @@ -189,11 +189,11 @@ fn bindings_after_at_slice_patterns_or_patterns_box_patterns_borrows( drop(r); } -fn bindings_after_at_slice_patterns_or_patterns_box_patterns_borrows_mut( +fn bindings_after_at_slice_patterns_or_patterns_deref_patterns_borrows_mut( mut x: [Option>; 4] ) { let r = match x { - [_, ref mut a @ Some(box Test::Foo | box Test::Bar), ..] => Some(a), + [_, ref mut a @ Some(deref!(Test::Foo) | deref!(Test::Bar)), ..] => Some(a), _ => None, }; @@ -203,11 +203,11 @@ fn bindings_after_at_slice_patterns_or_patterns_box_patterns_borrows_mut( drop(r); } -fn bindings_after_at_slice_patterns_or_patterns_box_patterns_borrows_binding( +fn bindings_after_at_slice_patterns_or_patterns_deref_patterns_borrows_binding( mut x: [Option>; 4] ) { let r = match x { - ref a @ [_, ref b @ Some(box Test::Foo | box Test::Bar), ..] => Some(a), + ref a @ [_, ref b @ Some(deref!(Test::Foo) | deref!(Test::Bar)), ..] => Some(a), _ => None, }; diff --git a/tests/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-box-patterns.stderr b/tests/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-deref-patterns.stderr similarity index 76% rename from tests/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-box-patterns.stderr rename to tests/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-deref-patterns.stderr index 047175626e366..7920abe1e0cfa 100644 --- a/tests/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-box-patterns.stderr +++ b/tests/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-deref-patterns.stderr @@ -1,5 +1,5 @@ error[E0382]: borrow of moved value: `x` - --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:18:5 + --> $DIR/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs:18:5 | LL | fn bindings_after_at_slice_patterns_move_binding(x: [String; 4]) { | - move occurs because `x` has type `[String; 4]`, which does not implement the `Copy` trait @@ -16,7 +16,7 @@ LL | ref a @ [.., _] => (), | +++ error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable - --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:28:5 + --> $DIR/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs:28:5 | LL | ref mut foo @ [.., _] => Some(foo), | ----------- mutable borrow occurs here @@ -28,7 +28,7 @@ LL | drop(r); | - mutable borrow later used here error: cannot borrow value as mutable because it is also borrowed as immutable - --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:36:9 + --> $DIR/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs:36:9 | LL | ref foo @ [.., ref mut bar] => (), | ^^^^^^^ ----------- value is mutably borrowed by `bar` here @@ -36,7 +36,7 @@ LL | ref foo @ [.., ref mut bar] => (), | value is borrowed by `foo` here error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable - --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:50:5 + --> $DIR/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs:50:5 | LL | [ref foo @ .., ref bar] => Some(foo), | ------- immutable borrow occurs here @@ -48,7 +48,7 @@ LL | drop(r); | - immutable borrow later used here error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable - --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:62:5 + --> $DIR/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs:62:5 | LL | ref foo @ [.., ref bar] => Some(foo), | ------- immutable borrow occurs here @@ -60,7 +60,7 @@ LL | drop(r); | - immutable borrow later used here error[E0382]: borrow of moved value: `x` - --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:76:5 + --> $DIR/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs:76:5 | LL | fn bindings_after_at_or_patterns_move(x: Option) { | - move occurs because `x` has type `Option`, which does not implement the `Copy` trait @@ -77,7 +77,7 @@ LL | ref foo @ Some(Test::Foo | Test::Bar) => (), | +++ error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable - --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:86:5 + --> $DIR/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs:86:5 | LL | ref foo @ Some(Test::Foo | Test::Bar) => Some(foo), | ------- immutable borrow occurs here @@ -89,7 +89,7 @@ LL | drop(r); | - immutable borrow later used here error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable - --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:98:5 + --> $DIR/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs:98:5 | LL | ref mut foo @ Some(Test::Foo | Test::Bar) => Some(foo), | ----------- mutable borrow occurs here @@ -101,9 +101,9 @@ LL | drop(r); | - mutable borrow later used here error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable - --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:112:5 + --> $DIR/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs:112:5 | -LL | ref foo @ Some(box ref s) => Some(foo), +LL | ref foo @ Some(deref!(ref s)) => Some(foo), | ------- immutable borrow occurs here ... LL | &mut x; @@ -113,15 +113,15 @@ LL | drop(r); | - immutable borrow later used here error: cannot borrow value as mutable because it is also borrowed as immutable - --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:120:9 + --> $DIR/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs:120:9 | -LL | ref foo @ Some(box ref mut s) => (), - | ^^^^^^^ --------- value is mutably borrowed by `s` here +LL | ref foo @ Some(deref!(ref mut s)) => (), + | ^^^^^^^ --------- value is mutably borrowed by `s` here | | | value is borrowed by `foo` here error[E0382]: borrow of moved value: `x` - --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:134:5 + --> $DIR/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs:134:5 | LL | fn bindings_after_at_slice_patterns_or_patterns_moves(x: [Option; 4]) { | - move occurs because `x` has type `[Option; 4]`, which does not implement the `Copy` trait @@ -138,7 +138,7 @@ LL | ref a @ [.., Some(Test::Foo | Test::Bar)] => (), | +++ error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable - --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:144:5 + --> $DIR/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs:144:5 | LL | ref a @ [ref b @ .., Some(Test::Foo | Test::Bar)] => Some(a), | ----- immutable borrow occurs here @@ -150,7 +150,7 @@ LL | drop(r); | - immutable borrow later used here error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable - --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:156:5 + --> $DIR/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs:156:5 | LL | ref a @ [ref b @ .., Some(Test::Foo | Test::Bar)] => Some(b), | ----- immutable borrow occurs here @@ -162,9 +162,9 @@ LL | drop(r); | - immutable borrow later used here error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable - --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:170:5 + --> $DIR/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs:170:5 | -LL | [_, ref a @ Some(box ref b), ..] => Some(a), +LL | [_, ref a @ Some(deref!(ref b)), ..] => Some(a), | ----- immutable borrow occurs here ... LL | &mut x; @@ -174,9 +174,9 @@ LL | drop(r); | - immutable borrow later used here error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable - --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:186:5 + --> $DIR/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs:186:5 | -LL | [_, ref a @ Some(box Test::Foo | box Test::Bar), ..] => Some(a), +LL | [_, ref a @ Some(deref!(Test::Foo) | deref!(Test::Bar)), ..] => Some(a), | ----- immutable borrow occurs here ... LL | &mut x; @@ -186,9 +186,9 @@ LL | drop(r); | - immutable borrow later used here error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable - --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:200:5 + --> $DIR/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs:200:5 | -LL | [_, ref mut a @ Some(box Test::Foo | box Test::Bar), ..] => Some(a), +LL | [_, ref mut a @ Some(deref!(Test::Foo) | deref!(Test::Bar)), ..] => Some(a), | --------- mutable borrow occurs here ... LL | &x; @@ -198,9 +198,9 @@ LL | drop(r); | - mutable borrow later used here error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable - --> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:214:5 + --> $DIR/bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs:214:5 | -LL | ref a @ [_, ref b @ Some(box Test::Foo | box Test::Bar), ..] => Some(a), +LL | ref a @ [_, ref b @ Some(deref!(Test::Foo) | deref!(Test::Bar)), ..] => Some(a), | ----- immutable borrow occurs here ... LL | &mut x; diff --git a/tests/ui/borrowck/borrowck-loan-in-overloaded-op.rs b/tests/ui/borrowck/borrowck-loan-in-overloaded-op.rs index b8f1650fcdc59..cf8155816cffc 100644 --- a/tests/ui/borrowck/borrowck-loan-in-overloaded-op.rs +++ b/tests/ui/borrowck/borrowck-loan-in-overloaded-op.rs @@ -1,6 +1,3 @@ -#![feature(box_patterns)] - - use std::ops::Add; #[derive(Clone)] @@ -10,9 +7,9 @@ impl Add for Foo { type Output = Foo; fn add(self, f: Foo) -> Foo { - let Foo(box i) = self; - let Foo(box j) = f; - Foo(Box::new(i + j)) + let Foo(i) = self; + let Foo(j) = f; + Foo(Box::new(*i + *j)) } } diff --git a/tests/ui/borrowck/borrowck-loan-in-overloaded-op.stderr b/tests/ui/borrowck/borrowck-loan-in-overloaded-op.stderr index 5f1e3994af207..e50cc02e31c79 100644 --- a/tests/ui/borrowck/borrowck-loan-in-overloaded-op.stderr +++ b/tests/ui/borrowck/borrowck-loan-in-overloaded-op.stderr @@ -1,5 +1,5 @@ error[E0382]: borrow of moved value: `x` - --> $DIR/borrowck-loan-in-overloaded-op.rs:21:20 + --> $DIR/borrowck-loan-in-overloaded-op.rs:18:20 | LL | let x = Foo(Box::new(3)); | - move occurs because `x` has type `Foo`, which does not implement the `Copy` trait diff --git a/tests/ui/borrowck/borrowck-macro-interaction-issue-6304.rs b/tests/ui/borrowck/borrowck-macro-interaction-issue-6304.rs index af4fdc48da1c2..2b48014504a4d 100644 --- a/tests/ui/borrowck/borrowck-macro-interaction-issue-6304.rs +++ b/tests/ui/borrowck/borrowck-macro-interaction-issue-6304.rs @@ -6,7 +6,7 @@ // Check that we do not ICE when compiling this // macro, which reuses the expression `$id` -#![feature(box_patterns)] +#![feature(deref_patterns)] struct Foo { a: isize @@ -25,7 +25,7 @@ impl Foo { }) } match s { - box Bar::Bar2(id, rest) => declare!(id, self.elaborate_stm(rest)), + Bar::Bar2(id, rest) => declare!(id, self.elaborate_stm(rest)), _ => panic!() } } diff --git a/tests/ui/borrowck/borrowck-vec-pattern-nesting.rs b/tests/ui/borrowck/borrowck-vec-pattern-nesting.rs index 657c4789aa30f..f9bcfe8be13f1 100644 --- a/tests/ui/borrowck/borrowck-vec-pattern-nesting.rs +++ b/tests/ui/borrowck/borrowck-vec-pattern-nesting.rs @@ -1,10 +1,10 @@ -#![feature(box_patterns)] +#![feature(deref_patterns)] fn a() { let mut vec = [Box::new(1), Box::new(2), Box::new(3)]; match vec { - [box ref _a, _, _] => { + [deref!(ref _a), _, _] => { //~^ NOTE `vec[_]` is borrowed here vec[0] = Box::new(4); //~ ERROR cannot assign //~^ NOTE `vec[_]` is assigned to here diff --git a/tests/ui/borrowck/borrowck-vec-pattern-nesting.stderr b/tests/ui/borrowck/borrowck-vec-pattern-nesting.stderr index a002b7e3d7f65..9a60d3cd46adf 100644 --- a/tests/ui/borrowck/borrowck-vec-pattern-nesting.stderr +++ b/tests/ui/borrowck/borrowck-vec-pattern-nesting.stderr @@ -1,8 +1,8 @@ error[E0506]: cannot assign to `vec[_]` because it is borrowed --> $DIR/borrowck-vec-pattern-nesting.rs:9:13 | -LL | [box ref _a, _, _] => { - | ------ `vec[_]` is borrowed here +LL | [deref!(ref _a), _, _] => { + | ------ `vec[_]` is borrowed here LL | LL | vec[0] = Box::new(4); | ^^^^^^ `vec[_]` is assigned to here but it was already borrowed diff --git a/tests/ui/borrowck/non-ADT-struct-pattern-box-pattern-ice-121463.rs b/tests/ui/borrowck/non-ADT-struct-pattern-box-pattern-ice-121463.rs index 48466af504815..52561630c223c 100644 --- a/tests/ui/borrowck/non-ADT-struct-pattern-box-pattern-ice-121463.rs +++ b/tests/ui/borrowck/non-ADT-struct-pattern-box-pattern-ice-121463.rs @@ -1,12 +1,11 @@ // issue rust-lang/rust#121463 // ICE non-ADT in struct pattern -#![feature(box_patterns)] fn main() { let mut a = E::StructVar { boxed: Box::new(5_i32) }; //~^ ERROR cannot find type `E` match a { - E::StructVar { box boxed } => { } + E::StructVar { boxed } => { } //~^ ERROR cannot find type `E` } } diff --git a/tests/ui/borrowck/non-ADT-struct-pattern-box-pattern-ice-121463.stderr b/tests/ui/borrowck/non-ADT-struct-pattern-box-pattern-ice-121463.stderr index 7be9ed27db0e3..235bdac743265 100644 --- a/tests/ui/borrowck/non-ADT-struct-pattern-box-pattern-ice-121463.stderr +++ b/tests/ui/borrowck/non-ADT-struct-pattern-box-pattern-ice-121463.stderr @@ -1,5 +1,5 @@ error[E0433]: cannot find type `E` in this scope - --> $DIR/non-ADT-struct-pattern-box-pattern-ice-121463.rs:6:17 + --> $DIR/non-ADT-struct-pattern-box-pattern-ice-121463.rs:5:17 | LL | let mut a = E::StructVar { boxed: Box::new(5_i32) }; | ^ use of undeclared type `E` @@ -10,14 +10,14 @@ LL | let mut a = Eq::StructVar { boxed: Box::new(5_i32) }; | + error[E0433]: cannot find type `E` in this scope - --> $DIR/non-ADT-struct-pattern-box-pattern-ice-121463.rs:9:9 + --> $DIR/non-ADT-struct-pattern-box-pattern-ice-121463.rs:8:9 | -LL | E::StructVar { box boxed } => { } +LL | E::StructVar { boxed } => { } | ^ use of undeclared type `E` | help: a trait with a similar name exists | -LL | Eq::StructVar { box boxed } => { } +LL | Eq::StructVar { boxed } => { } | + error: aborting due to 2 previous errors diff --git a/tests/ui/box/box-patterns-feature-usage-6557.rs b/tests/ui/box/box-patterns-feature-usage-6557.rs deleted file mode 100644 index e0d9b25c366d4..0000000000000 --- a/tests/ui/box/box-patterns-feature-usage-6557.rs +++ /dev/null @@ -1,9 +0,0 @@ -// https://github.com/rust-lang/rust/issues/6557 -//@ check-pass -#![allow(dead_code)] - -#![feature(box_patterns)] - -fn foo(box (_x, _y): Box<(isize, isize)>) {} - -pub fn main() {} diff --git a/tests/ui/box/unit/unique-pat.rs b/tests/ui/box/unit/unique-pat.rs deleted file mode 100644 index 395d06127d653..0000000000000 --- a/tests/ui/box/unit/unique-pat.rs +++ /dev/null @@ -1,14 +0,0 @@ -//@ run-pass - -#![feature(box_patterns)] - -fn simple() { - match Box::new(true) { - box true => { } - _ => { panic!(); } - } -} - -pub fn main() { - simple(); -} diff --git a/tests/ui/cfg/cfg-false-feature.rs b/tests/ui/cfg/cfg-false-feature.rs index f66e4722440c5..b23f4be2b3917 100644 --- a/tests/ui/cfg/cfg-false-feature.rs +++ b/tests/ui/cfg/cfg-false-feature.rs @@ -2,10 +2,11 @@ //@ check-pass //@ compile-flags: --crate-type lib +//@ edition: 2018 #![feature(decl_macro)] #![cfg(false)] -#![feature(box_patterns)] +#![feature(try_blocks)] macro mac() {} // OK @@ -13,6 +14,6 @@ trait A = Clone; //~ WARN trait aliases are experimental //~| WARN unstable syntax can change at any point in the future fn main() { - let box _ = Box::new(0); //~ WARN box pattern syntax is experimental - //~| WARN unstable syntax can change at any point in the future + try {} //~ WARN `try` blocks are unstable + //~| WARN unstable syntax can change at any point in the future } diff --git a/tests/ui/cfg/cfg-false-feature.stderr b/tests/ui/cfg/cfg-false-feature.stderr index 25c221369bcc9..9239eed25a9ce 100644 --- a/tests/ui/cfg/cfg-false-feature.stderr +++ b/tests/ui/cfg/cfg-false-feature.stderr @@ -1,23 +1,23 @@ -warning: box pattern syntax is experimental - --> $DIR/cfg-false-feature.rs:16:9 +warning: trait aliases are experimental + --> $DIR/cfg-false-feature.rs:13:1 | -LL | let box _ = Box::new(0); - | ^^^^^ +LL | trait A = Clone; + | ^^^^^^^^^^^^^^^^ | - = note: see issue #29641 for more information - = help: add `#![feature(box_patterns)]` to the crate attributes to enable + = note: see issue #41517 for more information + = help: add `#![feature(trait_alias)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date = warning: unstable syntax can change at any point in the future, causing a hard error! = note: for more information, see issue #154045 -warning: trait aliases are experimental - --> $DIR/cfg-false-feature.rs:12:1 +warning: `try` blocks are unstable + --> $DIR/cfg-false-feature.rs:17:5 | -LL | trait A = Clone; - | ^^^^^^^^^^^^^^^^ +LL | try {} + | ^^^^^^ | - = note: see issue #41517 for more information - = help: add `#![feature(trait_alias)]` to the crate attributes to enable + = note: see issue #154391 for more information + = help: add `#![feature(try_blocks)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date = warning: unstable syntax can change at any point in the future, causing a hard error! = note: for more information, see issue #154045 diff --git a/tests/ui/deref/box-pattern-trait-object-cannot-deref.rs b/tests/ui/deref/box-pattern-trait-object-cannot-deref.rs deleted file mode 100644 index a144fb3605132..0000000000000 --- a/tests/ui/deref/box-pattern-trait-object-cannot-deref.rs +++ /dev/null @@ -1,19 +0,0 @@ -//! Regression test for https://github.com/rust-lang/rust/issues/4972 - -#![feature(box_patterns)] - -trait MyTrait { - fn dummy(&self) {} -} - -pub enum TraitWrapper { - A(Box), -} - -fn get_tw_map(tw: &TraitWrapper) -> &dyn MyTrait { - match *tw { - TraitWrapper::A(box ref map) => map, //~ ERROR cannot be dereferenced - } -} - -pub fn main() {} diff --git a/tests/ui/deref/box-pattern-trait-object-cannot-deref.stderr b/tests/ui/deref/box-pattern-trait-object-cannot-deref.stderr deleted file mode 100644 index 451fbf4fbcd35..0000000000000 --- a/tests/ui/deref/box-pattern-trait-object-cannot-deref.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0033]: type `Box<(dyn MyTrait + 'static)>` cannot be dereferenced - --> $DIR/box-pattern-trait-object-cannot-deref.rs:15:25 - | -LL | TraitWrapper::A(box ref map) => map, - | ^^^^^^^^^^^ type `Box<(dyn MyTrait + 'static)>` cannot be dereferenced - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0033`. diff --git a/tests/ui/deref/deref-mut-closure-drop-order.rs b/tests/ui/deref/deref-mut-closure-drop-order.rs index b95ae68f1734f..6e058e02f52a0 100644 --- a/tests/ui/deref/deref-mut-closure-drop-order.rs +++ b/tests/ui/deref/deref-mut-closure-drop-order.rs @@ -1,7 +1,7 @@ //! Regression test for https://github.com/rust-lang/rust/issues/16774 //@ run-pass -#![feature(box_patterns)] +#![feature(deref_patterns)] use std::ops::{Deref, DerefMut}; @@ -22,14 +22,14 @@ impl Deref for X { type Target = isize; fn deref(&self) -> &isize { - let &X(box ref x) = self; + let &X(ref x) = self; x } } impl DerefMut for X { fn deref_mut(&mut self) -> &mut isize { - let &mut X(box ref mut x) = self; + let &mut X(ref mut x) = self; x } } diff --git a/tests/ui/feature-gates/feature-gate-box_patterns.stderr b/tests/ui/feature-gates/feature-gate-box_patterns.stderr deleted file mode 100644 index 6f5ee20925eea..0000000000000 --- a/tests/ui/feature-gates/feature-gate-box_patterns.stderr +++ /dev/null @@ -1,23 +0,0 @@ -error[E0658]: box pattern syntax is experimental - --> $DIR/feature-gate-box_patterns.rs:2:9 - | -LL | let box x = Box::new('c'); - | ^^^^^ - | - = note: see issue #29641 for more information - = help: add `#![feature(box_patterns)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: box pattern syntax is experimental - --> $DIR/feature-gate-box_patterns.rs:7:18 - | -LL | let Packet { box x } = Packet { x: Box::new(0) }; - | ^^^^^ - | - = note: see issue #29641 for more information - = help: add `#![feature(box_patterns)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/feature-gates/feature-gate-deref_patterns.rs b/tests/ui/feature-gates/feature-gate-deref_patterns.rs index 53b4301f10c0c..fdcf7abf12340 100644 --- a/tests/ui/feature-gates/feature-gate-deref_patterns.rs +++ b/tests/ui/feature-gates/feature-gate-deref_patterns.rs @@ -1,9 +1,7 @@ fn main() { - // We reuse the `box` syntax so this doesn't actually test the feature gate but eh. - let box x = Box::new('c'); //~ ERROR box pattern syntax is experimental - println!("x: {}", x); - - // `box` syntax is allowed to be cfg-ed out for historical reasons (#65742). - #[cfg(false)] - let box _x = Box::new('c'); + let x = Box::new('c'); + match x { + 'c' => (), //~ ERROR mismatched types + _ => (), + } } diff --git a/tests/ui/feature-gates/feature-gate-deref_patterns.stderr b/tests/ui/feature-gates/feature-gate-deref_patterns.stderr index 48426b50d8948..8e9bebd533e59 100644 --- a/tests/ui/feature-gates/feature-gate-deref_patterns.stderr +++ b/tests/ui/feature-gates/feature-gate-deref_patterns.stderr @@ -1,13 +1,18 @@ -error[E0658]: box pattern syntax is experimental - --> $DIR/feature-gate-deref_patterns.rs:3:9 +error[E0308]: mismatched types + --> $DIR/feature-gate-deref_patterns.rs:4:9 | -LL | let box x = Box::new('c'); - | ^^^^^ +LL | match x { + | - this expression has type `Box` +LL | 'c' => (), + | ^^^ expected `Box`, found `char` | - = note: see issue #29641 for more information - = help: add `#![feature(box_patterns)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + = note: expected struct `Box` + found type `char` +help: consider dereferencing the boxed value + | +LL | match *x { + | + error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0658`. +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/feature-gates/soft-feature-gate-box_patterns.rs b/tests/ui/feature-gates/soft-feature-gate-box_patterns.rs deleted file mode 100644 index 9fdaa7a0ec08c..0000000000000 --- a/tests/ui/feature-gates/soft-feature-gate-box_patterns.rs +++ /dev/null @@ -1,17 +0,0 @@ -// For historical reasons, box patterns don't have an erroring pre-expansion feature gate. -// We're now at least issuing a warning for those that only exist before macro expansion. -// FIXME(#154045): Turn this pre-expansion warning into an error and remove the post-expansion gate. -// As part of this, move these test cases into `feature-gate-box_patterns.rs`. -//@ check-pass - -fn main() { - #[cfg(false)] - let box x; - //~^ WARN box pattern syntax is experimental - //~| WARN unstable syntax can change at any point in the future - - #[cfg(false)] - let Packet { box x }; - //~^ WARN box pattern syntax is experimental - //~| WARN unstable syntax can change at any point in the future -} diff --git a/tests/ui/feature-gates/soft-feature-gate-box_patterns.stderr b/tests/ui/feature-gates/soft-feature-gate-box_patterns.stderr deleted file mode 100644 index 2a191417d6e2d..0000000000000 --- a/tests/ui/feature-gates/soft-feature-gate-box_patterns.stderr +++ /dev/null @@ -1,26 +0,0 @@ -warning: box pattern syntax is experimental - --> $DIR/soft-feature-gate-box_patterns.rs:9:9 - | -LL | let box x; - | ^^^^^ - | - = note: see issue #29641 for more information - = help: add `#![feature(box_patterns)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = warning: unstable syntax can change at any point in the future, causing a hard error! - = note: for more information, see issue #154045 - -warning: box pattern syntax is experimental - --> $DIR/soft-feature-gate-box_patterns.rs:14:18 - | -LL | let Packet { box x }; - | ^^^ - | - = note: see issue #29641 for more information - = help: add `#![feature(box_patterns)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = warning: unstable syntax can change at any point in the future, causing a hard error! - = note: for more information, see issue #154045 - -warning: 2 warnings emitted - diff --git a/tests/ui/lifetimes/rvalue-lifetime-drop-timing.rs b/tests/ui/lifetimes/rvalue-lifetime-drop-timing.rs index 9e7b84bfccfd2..8c967d7612684 100644 --- a/tests/ui/lifetimes/rvalue-lifetime-drop-timing.rs +++ b/tests/ui/lifetimes/rvalue-lifetime-drop-timing.rs @@ -3,8 +3,6 @@ //@ run-pass -#![feature(box_patterns)] - static mut FLAGS: u64 = 0; struct Box { @@ -85,8 +83,6 @@ fn main() { end_of_block!(AddFlags { bits: ref _x }, add_flags(1)); end_of_block!(&AddFlags { bits: _ }, &add_flags(1)); end_of_block!((_, ref _y), (add_flags(1), 22)); - end_of_block!(box ref _x, std::boxed::Box::new(add_flags(1))); - end_of_block!(box _x, std::boxed::Box::new(add_flags(1))); end_of_block!(_, { { check_flags(0); diff --git a/tests/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.rs b/tests/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.rs index 10a69ff618001..63e534709c60e 100644 --- a/tests/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.rs +++ b/tests/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.rs @@ -1,7 +1,5 @@ //@ check-pass -#![feature(box_patterns)] - #![warn(unused)] // UI tests pass `-A unused` (#43896) struct SoulHistory { @@ -66,11 +64,6 @@ fn main() { &Large::Suit { case } => {} //~ WARNING unused variable: `case` }; - // Boxed struct - match Box::new(bag) { - box Large::Suit { case } => {} //~ WARNING unused variable: `case` - }; - // Tuple with struct match (bag,) { (Large::Suit { case },) => {} //~ WARNING unused variable: `case` diff --git a/tests/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.stderr b/tests/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.stderr index c378b307b8b54..ff4632dc8eabc 100644 --- a/tests/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.stderr +++ b/tests/ui/lint/unused/issue-47390-unused-variable-in-struct-pattern.stderr @@ -1,5 +1,5 @@ warning: variable does not need to be mutable - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:33:9 + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:31:9 | LL | let mut mut_unused_var = 1; | ----^^^^^^^^^^^^^^ @@ -7,14 +7,14 @@ LL | let mut mut_unused_var = 1; | help: remove this `mut` | note: the lint level is defined here - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:5:9 + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:3:9 | LL | #![warn(unused)] // UI tests pass `-A unused` (#43896) | ^^^^^^ = note: `#[warn(unused_mut)]` implied by `#[warn(unused)]` warning: variable does not need to be mutable - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:37:10 + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:35:10 | LL | let (mut var, unused_var) = (1, 2); | ----^^^ @@ -22,7 +22,7 @@ LL | let (mut var, unused_var) = (1, 2); | help: remove this `mut` warning: unused variable: `i_think_continually` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:26:9 + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:24:9 | LL | let i_think_continually = 2; | ^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_i_think_continually` @@ -30,31 +30,31 @@ LL | let i_think_continually = 2; = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]` warning: unused variable: `mut_unused_var` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:33:9 + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:31:9 | LL | let mut mut_unused_var = 1; | ^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_mut_unused_var` warning: unused variable: `var` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:37:10 + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:35:10 | LL | let (mut var, unused_var) = (1, 2); | ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_var` warning: unused variable: `unused_var` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:37:19 + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:35:19 | LL | let (mut var, unused_var) = (1, 2); | ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused_var` warning: unused variable: `corridors_of_light` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:45:26 + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:43:26 | LL | if let SoulHistory { corridors_of_light, | ^^^^^^^^^^^^^^^^^^ help: try ignoring the field: `corridors_of_light: _` warning: variable `hours_are_suns` is assigned to, but never used - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:46:26 + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:44:26 | LL | mut hours_are_suns, | ^^^^^^^^^^^^^^^^^^ @@ -62,49 +62,43 @@ LL | mut hours_are_suns, = note: consider using `_hours_are_suns` instead warning: unused variable: `fire` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:52:32 + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:50:32 | LL | let LovelyAmbition { lips, fire } = the_spirit; | ^^^^ help: try ignoring the field: `fire: _` warning: unused variable: `case` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:61:23 + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:59:23 | LL | Large::Suit { case } => {} | ^^^^ help: try ignoring the field: `case: _` warning: unused variable: `case` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:66:24 + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:64:24 | LL | &Large::Suit { case } => {} | ^^^^ help: try ignoring the field: `case: _` warning: unused variable: `case` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:71:27 - | -LL | box Large::Suit { case } => {} - | ^^^^ help: try ignoring the field: `case: _` - -warning: unused variable: `case` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:76:24 + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:69:24 | LL | (Large::Suit { case },) => {} | ^^^^ help: try ignoring the field: `case: _` warning: unused variable: `case` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:81:24 + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:74:24 | LL | [Large::Suit { case }] => {} | ^^^^ help: try ignoring the field: `case: _` warning: unused variable: `case` - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:86:29 + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:79:29 | LL | Tuple(Large::Suit { case }, ()) => {} | ^^^^ help: try ignoring the field: `case: _` warning: value assigned to `hours_are_suns` is never read - --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:48:9 + --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:46:9 | LL | hours_are_suns = false; | ^^^^^^^^^^^^^^^^^^^^^^ @@ -112,5 +106,5 @@ LL | hours_are_suns = false; = help: maybe it is overwritten before being read? = note: `#[warn(unused_assignments)]` implied by `#[warn(unused)]` -warning: 16 warnings emitted +warning: 15 warnings emitted diff --git a/tests/ui/lint/unused/issue-54538-unused-parens-lint.fixed b/tests/ui/lint/unused/issue-54538-unused-parens-lint.fixed index 6eba47ed585ed..147da718fc33f 100644 --- a/tests/ui/lint/unused/issue-54538-unused-parens-lint.fixed +++ b/tests/ui/lint/unused/issue-54538-unused-parens-lint.fixed @@ -1,7 +1,7 @@ //@ edition:2015..2021 //@ run-rustfix -#![feature(box_patterns, stmt_expr_attributes, yeet_expr)] +#![feature(stmt_expr_attributes, yeet_expr)] #![allow( dead_code, @@ -52,11 +52,6 @@ fn lint_break_if_not_followed_by_block() { // Don't lint in these cases (#64106). fn or_patterns_no_lint() { - match Box::new(0) { - box (0 | 1) => {} // Should not lint as `box 0 | 1` binds as `(box 0) | 1`. - _ => {} - } - match 0 { x @ (0 | 1) => {} // Should not lint as `x @ 0 | 1` binds as `(x @ 0) | 1`. _ => {} diff --git a/tests/ui/lint/unused/issue-54538-unused-parens-lint.rs b/tests/ui/lint/unused/issue-54538-unused-parens-lint.rs index f14d37d4d91d5..907d45b0b0699 100644 --- a/tests/ui/lint/unused/issue-54538-unused-parens-lint.rs +++ b/tests/ui/lint/unused/issue-54538-unused-parens-lint.rs @@ -1,7 +1,7 @@ //@ edition:2015..2021 //@ run-rustfix -#![feature(box_patterns, stmt_expr_attributes, yeet_expr)] +#![feature(stmt_expr_attributes, yeet_expr)] #![allow( dead_code, @@ -52,11 +52,6 @@ fn lint_break_if_not_followed_by_block() { // Don't lint in these cases (#64106). fn or_patterns_no_lint() { - match Box::new(0) { - box (0 | 1) => {} // Should not lint as `box 0 | 1` binds as `(box 0) | 1`. - _ => {} - } - match 0 { x @ (0 | 1) => {} // Should not lint as `x @ 0 | 1` binds as `(x @ 0) | 1`. _ => {} diff --git a/tests/ui/lint/unused/issue-54538-unused-parens-lint.stderr b/tests/ui/lint/unused/issue-54538-unused-parens-lint.stderr index e96350f099830..3122dcc6fb83f 100644 --- a/tests/ui/lint/unused/issue-54538-unused-parens-lint.stderr +++ b/tests/ui/lint/unused/issue-54538-unused-parens-lint.stderr @@ -129,7 +129,7 @@ LL + loop { if (break println!("hello")) {} } | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:74:12 + --> $DIR/issue-54538-unused-parens-lint.rs:69:12 | LL | if let (0 | 1) = 0 {} | ^ ^ @@ -141,7 +141,7 @@ LL + if let 0 | 1 = 0 {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:75:13 + --> $DIR/issue-54538-unused-parens-lint.rs:70:13 | LL | if let ((0 | 1),) = (0,) {} | ^ ^ @@ -153,7 +153,7 @@ LL + if let (0 | 1,) = (0,) {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:76:13 + --> $DIR/issue-54538-unused-parens-lint.rs:71:13 | LL | if let [(0 | 1)] = [0] {} | ^ ^ @@ -165,7 +165,7 @@ LL + if let [0 | 1] = [0] {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:77:16 + --> $DIR/issue-54538-unused-parens-lint.rs:72:16 | LL | if let 0 | (1 | 2) = 0 {} | ^ ^ @@ -177,7 +177,7 @@ LL + if let 0 | 1 | 2 = 0 {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:79:15 + --> $DIR/issue-54538-unused-parens-lint.rs:74:15 | LL | if let TS((0 | 1)) = TS(0) {} | ^ ^ @@ -189,7 +189,7 @@ LL + if let TS(0 | 1) = TS(0) {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:81:20 + --> $DIR/issue-54538-unused-parens-lint.rs:76:20 | LL | if let NS { f: (0 | 1) } = (NS { f: 0 }) {} | ^ ^ @@ -201,7 +201,7 @@ LL + if let NS { f: 0 | 1 } = (NS { f: 0 }) {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:91:9 + --> $DIR/issue-54538-unused-parens-lint.rs:86:9 | LL | (_) => {} | ^ ^ @@ -213,7 +213,7 @@ LL + _ => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:92:9 + --> $DIR/issue-54538-unused-parens-lint.rs:87:9 | LL | (y) => {} | ^ ^ @@ -225,7 +225,7 @@ LL + y => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:93:9 + --> $DIR/issue-54538-unused-parens-lint.rs:88:9 | LL | (ref r) => {} | ^ ^ @@ -237,7 +237,7 @@ LL + ref r => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:94:9 + --> $DIR/issue-54538-unused-parens-lint.rs:89:9 | LL | (e @ 1...2) => {} | ^ ^ @@ -249,7 +249,7 @@ LL + e @ 1...2 => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:100:9 + --> $DIR/issue-54538-unused-parens-lint.rs:95:9 | LL | (e @ &(1...2)) => {} | ^ ^ @@ -261,7 +261,7 @@ LL + e @ &(1...2) => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:101:10 + --> $DIR/issue-54538-unused-parens-lint.rs:96:10 | LL | &(_) => {} | ^ ^ @@ -273,7 +273,7 @@ LL + &_ => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:112:9 + --> $DIR/issue-54538-unused-parens-lint.rs:107:9 | LL | (_) => {} | ^ ^ @@ -285,7 +285,7 @@ LL + _ => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:113:9 + --> $DIR/issue-54538-unused-parens-lint.rs:108:9 | LL | (y) => {} | ^ ^ @@ -297,7 +297,7 @@ LL + y => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:114:9 + --> $DIR/issue-54538-unused-parens-lint.rs:109:9 | LL | (ref r) => {} | ^ ^ @@ -309,7 +309,7 @@ LL + ref r => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:115:9 + --> $DIR/issue-54538-unused-parens-lint.rs:110:9 | LL | (e @ 1..=2) => {} | ^ ^ @@ -321,7 +321,7 @@ LL + e @ 1..=2 => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:121:9 + --> $DIR/issue-54538-unused-parens-lint.rs:116:9 | LL | (e @ &(1..=2)) => {} | ^ ^ @@ -333,7 +333,7 @@ LL + e @ &(1..=2) => {} | error: unnecessary parentheses around pattern - --> $DIR/issue-54538-unused-parens-lint.rs:122:10 + --> $DIR/issue-54538-unused-parens-lint.rs:117:10 | LL | &(_) => {} | ^ ^ diff --git a/tests/ui/macros/stringify.rs b/tests/ui/macros/stringify.rs index 1a65ef7200f52..242a91cab7e77 100644 --- a/tests/ui/macros/stringify.rs +++ b/tests/ui/macros/stringify.rs @@ -5,7 +5,6 @@ #![allow(incomplete_features)] #![allow(unused_features)] #![feature(auto_traits)] -#![feature(box_patterns)] #![feature(const_block_items)] #![feature(const_trait_impl)] #![feature(coroutines)] @@ -579,9 +578,6 @@ fn test_pat() { c1!(pat, [ (true,) ], "(true,)"); c1!(pat, [ (true, false) ], "(true, false)"); - // PatKind::Box - c1!(pat, [ box pat ], "box pat"); - // PatKind::Ref c1!(pat, [ &pat ], "&pat"); c1!(pat, [ &mut pat ], "&mut pat"); diff --git a/tests/ui/match/issue-42679.rs b/tests/ui/match/issue-42679.rs index d41ed43a65f17..277b0b7b93384 100644 --- a/tests/ui/match/issue-42679.rs +++ b/tests/ui/match/issue-42679.rs @@ -1,5 +1,5 @@ //@ run-pass -#![feature(box_patterns)] +#![feature(deref_patterns)] #[derive(Debug, PartialEq)] enum Test { @@ -11,11 +11,11 @@ fn main() { let a = Box::new(Test::Foo(10)); let b = Box::new(Test::Bar(-20)); match (a, b) { - (_, box Test::Foo(_)) => unreachable!(), - (box Test::Foo(x), b) => { + (_, deref!(Test::Foo(_))) => unreachable!(), + (deref!(Test::Foo(x)), b) => { assert_eq!(x, 10); assert_eq!(b, Box::new(Test::Bar(-20))); - }, + } _ => unreachable!(), } } diff --git a/tests/ui/moves/move-out-of-slice-1.rs b/tests/ui/moves/move-out-of-slice-1.rs index 982648f5b237c..6b44c0de1fbc9 100644 --- a/tests/ui/moves/move-out-of-slice-1.rs +++ b/tests/ui/moves/move-out-of-slice-1.rs @@ -1,11 +1,11 @@ -#![feature(box_patterns)] +#![feature(deref_patterns)] struct A; fn main() { let a: Box<[A]> = Box::new([A]); match a { //~ ERROR cannot move out of type `[A]`, a non-copy slice - box [a] => {}, + [a] => {}, _ => {} } } diff --git a/tests/ui/moves/move-out-of-slice-1.stderr b/tests/ui/moves/move-out-of-slice-1.stderr index 4b917554057c3..c664fc34f96aa 100644 --- a/tests/ui/moves/move-out-of-slice-1.stderr +++ b/tests/ui/moves/move-out-of-slice-1.stderr @@ -3,13 +3,13 @@ error[E0508]: cannot move out of type `[A]`, a non-copy slice | LL | match a { | ^ cannot move out of here -LL | box [a] => {}, - | - data moved here because `a` has type `A`, which does not implement the `Copy` trait +LL | [a] => {}, + | - data moved here because `a` has type `A`, which does not implement the `Copy` trait | help: consider borrowing the pattern binding | -LL | box [ref a] => {}, - | +++ +LL | [ref a] => {}, + | +++ error: aborting due to 1 previous error diff --git a/tests/ui/moves/moves-based-on-type-block-bad.fixed b/tests/ui/moves/moves-based-on-type-block-bad.fixed index c272203c7f0bf..60a07e3e0870e 100644 --- a/tests/ui/moves/moves-based-on-type-block-bad.fixed +++ b/tests/ui/moves/moves-based-on-type-block-bad.fixed @@ -1,5 +1,5 @@ //@ run-rustfix -#![feature(box_patterns)] +#![feature(deref_patterns)] #![allow(dead_code)] @@ -22,9 +22,9 @@ fn main() { loop { f(&s, |hellothere| { match hellothere.x { //~ ERROR cannot move out - box E::Foo(_) => {} - box E::Bar(ref x) => println!("{}", x.to_string()), - box E::Baz => {} + deref!(E::Foo(_)) => {} + deref!(E::Bar(ref x)) => println!("{}", x.to_string()), + E::Baz => {} } }) } diff --git a/tests/ui/moves/moves-based-on-type-block-bad.rs b/tests/ui/moves/moves-based-on-type-block-bad.rs index e036e10fb180a..2fb11097b96fd 100644 --- a/tests/ui/moves/moves-based-on-type-block-bad.rs +++ b/tests/ui/moves/moves-based-on-type-block-bad.rs @@ -1,5 +1,5 @@ //@ run-rustfix -#![feature(box_patterns)] +#![feature(deref_patterns)] #![allow(dead_code)] @@ -22,9 +22,9 @@ fn main() { loop { f(&s, |hellothere| { match hellothere.x { //~ ERROR cannot move out - box E::Foo(_) => {} - box E::Bar(x) => println!("{}", x.to_string()), - box E::Baz => {} + deref!(E::Foo(_)) => {} + deref!(E::Bar(x)) => println!("{}", x.to_string()), + E::Baz => {} } }) } diff --git a/tests/ui/moves/moves-based-on-type-block-bad.stderr b/tests/ui/moves/moves-based-on-type-block-bad.stderr index 8e93b62fa8c65..24432ccad00c3 100644 --- a/tests/ui/moves/moves-based-on-type-block-bad.stderr +++ b/tests/ui/moves/moves-based-on-type-block-bad.stderr @@ -3,14 +3,14 @@ error[E0507]: cannot move out of `hellothere.x` as enum variant `Bar` which is b | LL | match hellothere.x { | ^^^^^^^^^^^^ -LL | box E::Foo(_) => {} -LL | box E::Bar(x) => println!("{}", x.to_string()), - | - data moved here because `x` has type `Box`, which does not implement the `Copy` trait +LL | deref!(E::Foo(_)) => {} +LL | deref!(E::Bar(x)) => println!("{}", x.to_string()), + | - data moved here because `x` has type `Box`, which does not implement the `Copy` trait | help: consider borrowing the pattern binding | -LL | box E::Bar(ref x) => println!("{}", x.to_string()), - | +++ +LL | deref!(E::Bar(ref x)) => println!("{}", x.to_string()), + | +++ error: aborting due to 1 previous error diff --git a/tests/ui/nll/issue-16223.rs b/tests/ui/nll/issue-16223.rs index 7a510c5ad9d8a..8da23728fbb84 100644 --- a/tests/ui/nll/issue-16223.rs +++ b/tests/ui/nll/issue-16223.rs @@ -15,7 +15,7 @@ //@ check-pass -#![feature(box_patterns)] +#![feature(deref_patterns)] struct Root { boxed: Box, @@ -41,7 +41,7 @@ fn main() { rhs: SomeVariant::B(B(String::from("This is B"))), }), }; - if let box SetOfVariants { + if let SetOfVariants { lhs: SomeVariant::A(a), rhs: SomeVariant::B(b), } = root.boxed diff --git a/tests/ui/or-patterns/box-patterns.rs b/tests/ui/or-patterns/deref-patterns.rs similarity index 77% rename from tests/ui/or-patterns/box-patterns.rs rename to tests/ui/or-patterns/deref-patterns.rs index 6a3d048f8a6cc..a4edb22fd80fc 100644 --- a/tests/ui/or-patterns/box-patterns.rs +++ b/tests/ui/or-patterns/deref-patterns.rs @@ -1,8 +1,8 @@ -// Test or-patterns with box-patterns +// Test or-patterns with deref patterns //@ run-pass -#![feature(box_patterns)] +#![feature(deref_patterns)] #[derive(Debug, PartialEq)] enum MatchArm { @@ -20,8 +20,8 @@ enum Test { fn test(x: Option>) -> MatchArm { match x { - Some(box Test::Foo | box Test::Bar) => MatchArm::Arm(0), - Some(box Test::Baz) => MatchArm::Arm(1), + Some(Test::Foo | Test::Bar) => MatchArm::Arm(0), + Some(Test::Baz) => MatchArm::Arm(1), Some(_) => MatchArm::Arm(2), _ => MatchArm::Wild, } diff --git a/tests/ui/or-patterns/or-patterns-syntactic-pass.rs b/tests/ui/or-patterns/or-patterns-syntactic-pass.rs index 6fd5840e801a9..164ef2daee9fa 100644 --- a/tests/ui/or-patterns/or-patterns-syntactic-pass.rs +++ b/tests/ui/or-patterns/or-patterns-syntactic-pass.rs @@ -67,9 +67,6 @@ fn or_patterns() { let [A | B, .. | ..]; // These bind as `(prefix p) | q` as opposed to `prefix (p | q)`: - let (box 0 | 1); // Unstable; we *can* change the precedence if we want. - //~^ WARN box pattern syntax is experimental - //~| WARN unstable syntax let (&0 | 1); let (&mut 0 | 1); let (x @ 0 | 1); diff --git a/tests/ui/or-patterns/or-patterns-syntactic-pass.stderr b/tests/ui/or-patterns/or-patterns-syntactic-pass.stderr deleted file mode 100644 index 828a395218fb6..0000000000000 --- a/tests/ui/or-patterns/or-patterns-syntactic-pass.stderr +++ /dev/null @@ -1,14 +0,0 @@ -warning: box pattern syntax is experimental - --> $DIR/or-patterns-syntactic-pass.rs:70:10 - | -LL | let (box 0 | 1); // Unstable; we *can* change the precedence if we want. - | ^^^^^ - | - = note: see issue #29641 for more information - = help: add `#![feature(box_patterns)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = warning: unstable syntax can change at any point in the future, causing a hard error! - = note: for more information, see issue #154045 - -warning: 1 warning emitted - diff --git a/tests/ui/parser/mut-patterns.rs b/tests/ui/parser/mut-patterns.rs index a2af816074056..d519e4ef2c62e 100644 --- a/tests/ui/parser/mut-patterns.rs +++ b/tests/ui/parser/mut-patterns.rs @@ -3,7 +3,6 @@ //@ edition:2018 //@ dont-require-annotations: HELP -#![feature(box_patterns)] #![allow(warnings)] pub fn main() { @@ -39,7 +38,7 @@ pub fn main() { struct W(T, U); struct B { f: Box } - let mut W(mut a, W(b, W(ref c, W(d, B { box f })))) + let mut W(mut a, W(b, W(ref c, W(d, B { f })))) //~^ ERROR `mut` must be attached to each individual binding = W(0, W(1, W(2, W(3, B { f: Box::new(4u8) })))); diff --git a/tests/ui/parser/mut-patterns.stderr b/tests/ui/parser/mut-patterns.stderr index 70099989c9ff0..4d5b3e77c05db 100644 --- a/tests/ui/parser/mut-patterns.stderr +++ b/tests/ui/parser/mut-patterns.stderr @@ -1,5 +1,5 @@ error: `mut` must be followed by a named binding - --> $DIR/mut-patterns.rs:10:9 + --> $DIR/mut-patterns.rs:9:9 | LL | let mut _ = 0; | ^^^^ @@ -12,7 +12,7 @@ LL + let _ = 0; | error: `mut` must be followed by a named binding - --> $DIR/mut-patterns.rs:11:9 + --> $DIR/mut-patterns.rs:10:9 | LL | let mut (_, _) = (0, 0); | ^^^^ @@ -25,7 +25,7 @@ LL + let (_, _) = (0, 0); | error: `mut` must be attached to each individual binding - --> $DIR/mut-patterns.rs:13:9 + --> $DIR/mut-patterns.rs:12:9 | LL | let mut (x @ y) = 0; | ^^^^^^^^^^^ @@ -38,7 +38,7 @@ LL + let (mut x @ mut y) = 0; | error: `mut` on a binding may not be repeated - --> $DIR/mut-patterns.rs:15:13 + --> $DIR/mut-patterns.rs:14:13 | LL | let mut mut x = 0; | ^^^ @@ -50,7 +50,7 @@ LL + let mut x = 0; | error: `mut` on a binding may not be repeated - --> $DIR/mut-patterns.rs:19:13 + --> $DIR/mut-patterns.rs:18:13 | LL | let mut mut mut mut mut x = 0; | ^^^^^^^^^^^^^^^ @@ -62,7 +62,7 @@ LL + let mut x = 0; | error: `mut` must be attached to each individual binding - --> $DIR/mut-patterns.rs:24:9 + --> $DIR/mut-patterns.rs:23:9 | LL | let mut Foo { x: x } = Foo { x: 3 }; | ^^^^^^^^^^^^^^^^ @@ -75,7 +75,7 @@ LL + let Foo { x: mut x } = Foo { x: 3 }; | error: `mut` must be attached to each individual binding - --> $DIR/mut-patterns.rs:28:9 + --> $DIR/mut-patterns.rs:27:9 | LL | let mut Foo { x } = Foo { x: 3 }; | ^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ LL + let Foo { mut x } = Foo { x: 3 }; | error: `mut` on a binding may not be repeated - --> $DIR/mut-patterns.rs:33:13 + --> $DIR/mut-patterns.rs:32:13 | LL | let mut mut yield(become, await) = r#yield(0, 0); | ^^^ @@ -100,7 +100,7 @@ LL + let mut yield(become, await) = r#yield(0, 0); | error: expected identifier, found reserved keyword `yield` - --> $DIR/mut-patterns.rs:33:17 + --> $DIR/mut-patterns.rs:32:17 | LL | let mut mut yield(become, await) = r#yield(0, 0); | ^^^^^ expected identifier, found reserved keyword @@ -111,7 +111,7 @@ LL | let mut mut r#yield(become, await) = r#yield(0, 0); | ++ error: expected identifier, found reserved keyword `become` - --> $DIR/mut-patterns.rs:33:23 + --> $DIR/mut-patterns.rs:32:23 | LL | let mut mut yield(become, await) = r#yield(0, 0); | ^^^^^^ expected identifier, found reserved keyword @@ -122,7 +122,7 @@ LL | let mut mut yield(r#become, await) = r#yield(0, 0); | ++ error: expected identifier, found keyword `await` - --> $DIR/mut-patterns.rs:33:31 + --> $DIR/mut-patterns.rs:32:31 | LL | let mut mut yield(become, await) = r#yield(0, 0); | ^^^^^ expected identifier, found keyword @@ -133,7 +133,7 @@ LL | let mut mut yield(become, r#await) = r#yield(0, 0); | ++ error: `mut` must be followed by a named binding - --> $DIR/mut-patterns.rs:33:9 + --> $DIR/mut-patterns.rs:32:9 | LL | let mut mut yield(become, await) = r#yield(0, 0); | ^^^^^^^^ @@ -146,20 +146,20 @@ LL + let yield(become, await) = r#yield(0, 0); | error: `mut` must be attached to each individual binding - --> $DIR/mut-patterns.rs:42:9 + --> $DIR/mut-patterns.rs:41:9 | -LL | let mut W(mut a, W(b, W(ref c, W(d, B { box f })))) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | let mut W(mut a, W(b, W(ref c, W(d, B { f })))) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `mut` may be followed by `variable` and `variable @ pattern` help: add `mut` to each binding | -LL - let mut W(mut a, W(b, W(ref c, W(d, B { box f })))) -LL + let W(mut a, W(mut b, W(ref c, W(mut d, B { box mut f })))) +LL - let mut W(mut a, W(b, W(ref c, W(d, B { f })))) +LL + let W(mut a, W(mut b, W(ref c, W(mut d, B { mut f })))) | error: expected identifier, found metavariable - --> $DIR/mut-patterns.rs:49:21 + --> $DIR/mut-patterns.rs:48:21 | LL | let mut $p = 0; | ^^ expected identifier, found metavariable diff --git a/tests/ui/feature-gates/feature-gate-box_patterns.rs b/tests/ui/parser/removed-syntax/removed-syntax-box-patterns.rs similarity index 58% rename from tests/ui/feature-gates/feature-gate-box_patterns.rs rename to tests/ui/parser/removed-syntax/removed-syntax-box-patterns.rs index 9ff6604c95206..872f050a04034 100644 --- a/tests/ui/feature-gates/feature-gate-box_patterns.rs +++ b/tests/ui/parser/removed-syntax/removed-syntax-box-patterns.rs @@ -1,9 +1,9 @@ fn main() { - let box x = Box::new('c'); //~ ERROR box pattern syntax is experimental + let box x = Box::new('c'); //~ ERROR `box_patterns` has been removed let _: char = x; struct Packet { x: Box } - let Packet { box x } = Packet { x: Box::new(0) }; //~ ERROR box pattern syntax is experimental + let Packet { box x } = Packet { x: Box::new(0) }; //~ ERROR `box_patterns` has been removed let _: i32 = x; } diff --git a/tests/ui/parser/removed-syntax/removed-syntax-box-patterns.stderr b/tests/ui/parser/removed-syntax/removed-syntax-box-patterns.stderr new file mode 100644 index 0000000000000..df35336ece5a9 --- /dev/null +++ b/tests/ui/parser/removed-syntax/removed-syntax-box-patterns.stderr @@ -0,0 +1,14 @@ +error: `box_patterns` has been removed + --> $DIR/removed-syntax-box-patterns.rs:2:9 + | +LL | let box x = Box::new('c'); + | ^^^^^ + +error: `box_patterns` has been removed + --> $DIR/removed-syntax-box-patterns.rs:7:18 + | +LL | let Packet { box x } = Packet { x: Box::new(0) }; + | ^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/pattern/bindings-after-at/borrowck-pat-at-and-box-pass.rs b/tests/ui/pattern/bindings-after-at/borrowck-pat-at-and-box-pass.rs index d06733bb34427..fda5620590488 100644 --- a/tests/ui/pattern/bindings-after-at/borrowck-pat-at-and-box-pass.rs +++ b/tests/ui/pattern/bindings-after-at/borrowck-pat-at-and-box-pass.rs @@ -1,11 +1,11 @@ //@ check-pass -// Test `@` patterns combined with `box` patterns. +// Test `@` patterns combined with `deref!` patterns. #![allow(dropping_references)] #![allow(dropping_copy_types)] -#![feature(box_patterns)] +#![feature(deref_patterns)] #[derive(Copy, Clone)] struct C; @@ -17,47 +17,47 @@ struct NC; fn nc() -> NC { NC } fn main() { - let ref a @ box b = Box::new(C); // OK; the type is `Copy`. + let ref a @ deref!(b) = Box::new(C); // OK; the type is `Copy`. drop(b); drop(b); drop(a); - let ref a @ box b = Box::new(c()); // OK; the type is `Copy`. + let ref a @ deref!(b) = Box::new(c()); // OK; the type is `Copy`. drop(b); drop(b); drop(a); - fn f3(ref a @ box b: Box) { // OK; the type is `Copy`. + fn f3(ref a @ deref!(b): Box) { // OK; the type is `Copy`. drop(b); drop(b); drop(a); } match Box::new(c()) { - ref a @ box b => { // OK; the type is `Copy`. + ref a @ deref!(b) => { // OK; the type is `Copy`. drop(b); drop(b); drop(a); } } - let ref a @ box ref b = Box::new(NC); // OK. + let ref a @ deref!(ref b) = Box::new(NC); // OK. drop(a); drop(b); - fn f4(ref a @ box ref b: Box) { // OK. + fn f4(ref a @ deref!(ref b): Box) { // OK. drop(a); drop(b) } match Box::new(nc()) { - ref a @ box ref b => { // OK. + ref a @ deref!(ref b) => { // OK. drop(a); drop(b); } } match Box::new([Ok(c()), Err(nc()), Ok(c())]) { - box [Ok(a), ref xs @ .., Err(ref b)] => { + deref!([Ok(a), ref xs @ .., Err(ref b)]) => { let _: C = a; let _: &[Result; 1] = xs; let _: &NC = b; @@ -66,7 +66,7 @@ fn main() { } match [Ok(Box::new(c())), Err(Box::new(nc())), Ok(Box::new(c())), Ok(Box::new(c()))] { - [Ok(box a), ref xs @ .., Err(box ref b), Err(box ref c)] => { + [Ok(deref!(a)), ref xs @ .., Err(deref!(ref b)), Err(deref!(ref c))] => { let _: C = a; let _: &[Result, Box>; 1] = xs; let _: &NC = b; @@ -76,12 +76,12 @@ fn main() { } match Box::new([Ok(c()), Err(nc()), Ok(c())]) { - box [Ok(a), ref xs @ .., Err(b)] => {} + deref!([Ok(a), ref xs @ .., Err(b)]) => {} _ => {} } match [Ok(Box::new(c())), Err(Box::new(nc())), Ok(Box::new(c())), Ok(Box::new(c()))] { - [Ok(box ref a), ref xs @ .., Err(box b), Err(box ref mut c)] => {} + [Ok(deref!(ref a)), ref xs @ .., Err(deref!(b)), Err(deref!(ref mut c))] => {} _ => {} } } diff --git a/tests/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.rs b/tests/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.rs index 45aa65e67a9fa..b3efd9d7228e6 100644 --- a/tests/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.rs +++ b/tests/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.rs @@ -1,6 +1,6 @@ -// Test `@` patterns combined with `box` patterns. +// Test `@` patterns combined with `deref!` patterns. -#![feature(box_patterns)] +#![feature(deref_patterns)] #[derive(Copy, Clone)] struct C; @@ -16,42 +16,42 @@ fn nc() -> NC { } fn main() { - let a @ box &b = Box::new(&C); + let a @ deref!(&b) = Box::new(&C); - let a @ box b = Box::new(C); + let a @ deref!(b) = Box::new(C); - fn f1(a @ box &b: Box<&C>) {} + fn f1(a @ deref!(&b): Box<&C>) {} - fn f2(a @ box b: Box) {} + fn f2(a @ deref!(b): Box) {} match Box::new(C) { - a @ box b => {} + a @ deref!(b) => {} } - let ref a @ box b = Box::new(NC); //~ ERROR cannot move out of value because it is borrowed + let ref a @ deref!(b) = Box::new(NC); //~ ERROR cannot move out of value because it is borrowed //~| ERROR borrow of moved value - let ref a @ box ref mut b = Box::new(nc()); + let ref a @ deref!(ref mut b) = Box::new(nc()); //~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable - let ref a @ box ref mut b = Box::new(NC); + let ref a @ deref!(ref mut b) = Box::new(NC); //~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable - let ref a @ box ref mut b = Box::new(NC); + let ref a @ deref!(ref mut b) = Box::new(NC); //~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable //~| ERROR cannot borrow value as immutable because it is also borrowed as mutable *b = NC; - let ref a @ box ref mut b = Box::new(NC); + let ref a @ deref!(ref mut b) = Box::new(NC); //~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable //~| ERROR cannot borrow value as immutable because it is also borrowed as mutable *b = NC; drop(a); - let ref mut a @ box ref b = Box::new(NC); + let ref mut a @ deref!(ref b) = Box::new(NC); //~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable //~| ERROR cannot borrow value as mutable because it is also borrowed as immutable *a = Box::new(NC); drop(b); - fn f5(ref mut a @ box ref b: Box) { + fn f5(ref mut a @ deref!(ref b): Box) { //~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable //~| ERROR cannot borrow value as mutable because it is also borrowed as immutable *a = Box::new(NC); @@ -59,7 +59,7 @@ fn main() { } match Box::new(nc()) { - ref mut a @ box ref b => { + ref mut a @ deref!(ref b) => { //~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable //~| ERROR cannot borrow value as mutable because it is also borrowed as immutable *a = Box::new(NC); diff --git a/tests/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.stderr b/tests/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.stderr index 3ce48b1a72fca..91a4b26cff50d 100644 --- a/tests/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.stderr +++ b/tests/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.stderr @@ -1,78 +1,78 @@ error: cannot move out of value because it is borrowed --> $DIR/borrowck-pat-at-and-box.rs:31:9 | -LL | let ref a @ box b = Box::new(NC); - | ^^^^^ - value is moved into `b` here +LL | let ref a @ deref!(b) = Box::new(NC); + | ^^^^^ - value is moved into `b` here | | | value is borrowed by `a` here error: cannot borrow value as mutable because it is also borrowed as immutable --> $DIR/borrowck-pat-at-and-box.rs:34:9 | -LL | let ref a @ box ref mut b = Box::new(nc()); - | ^^^^^ --------- value is mutably borrowed by `b` here +LL | let ref a @ deref!(ref mut b) = Box::new(nc()); + | ^^^^^ --------- value is mutably borrowed by `b` here | | | value is borrowed by `a` here error: cannot borrow value as mutable because it is also borrowed as immutable --> $DIR/borrowck-pat-at-and-box.rs:36:9 | -LL | let ref a @ box ref mut b = Box::new(NC); - | ^^^^^ --------- value is mutably borrowed by `b` here +LL | let ref a @ deref!(ref mut b) = Box::new(NC); + | ^^^^^ --------- value is mutably borrowed by `b` here | | | value is borrowed by `a` here error: cannot borrow value as mutable because it is also borrowed as immutable --> $DIR/borrowck-pat-at-and-box.rs:38:9 | -LL | let ref a @ box ref mut b = Box::new(NC); - | ^^^^^ --------- value is mutably borrowed by `b` here +LL | let ref a @ deref!(ref mut b) = Box::new(NC); + | ^^^^^ --------- value is mutably borrowed by `b` here | | | value is borrowed by `a` here error: cannot borrow value as mutable because it is also borrowed as immutable --> $DIR/borrowck-pat-at-and-box.rs:42:9 | -LL | let ref a @ box ref mut b = Box::new(NC); - | ^^^^^ --------- value is mutably borrowed by `b` here +LL | let ref a @ deref!(ref mut b) = Box::new(NC); + | ^^^^^ --------- value is mutably borrowed by `b` here | | | value is borrowed by `a` here error: cannot borrow value as immutable because it is also borrowed as mutable --> $DIR/borrowck-pat-at-and-box.rs:48:9 | -LL | let ref mut a @ box ref b = Box::new(NC); - | ^^^^^^^^^ ----- value is borrowed by `b` here +LL | let ref mut a @ deref!(ref b) = Box::new(NC); + | ^^^^^^^^^ ----- value is borrowed by `b` here | | | value is mutably borrowed by `a` here error: cannot borrow value as immutable because it is also borrowed as mutable --> $DIR/borrowck-pat-at-and-box.rs:62:9 | -LL | ref mut a @ box ref b => { - | ^^^^^^^^^ ----- value is borrowed by `b` here +LL | ref mut a @ deref!(ref b) => { + | ^^^^^^^^^ ----- value is borrowed by `b` here | | | value is mutably borrowed by `a` here error[E0382]: borrow of moved value --> $DIR/borrowck-pat-at-and-box.rs:31:9 | -LL | let ref a @ box b = Box::new(NC); - | ^^^^^ - value moved here +LL | let ref a @ deref!(b) = Box::new(NC); + | ^^^^^ - value moved here | | | value borrowed here after move | = note: move occurs because value has type `NC`, which does not implement the `Copy` trait help: borrow this binding in the pattern to avoid moving the value | -LL | let ref a @ box ref b = Box::new(NC); - | +++ +LL | let ref a @ deref!(ref b) = Box::new(NC); + | +++ error[E0502]: cannot borrow value as immutable because it is also borrowed as mutable --> $DIR/borrowck-pat-at-and-box.rs:38:9 | -LL | let ref a @ box ref mut b = Box::new(NC); - | ^^^^^ --------- mutable borrow occurs here +LL | let ref a @ deref!(ref mut b) = Box::new(NC); + | ^^^^^ --------- mutable borrow occurs here | | | immutable borrow occurs here ... @@ -82,8 +82,8 @@ LL | *b = NC; error[E0502]: cannot borrow value as immutable because it is also borrowed as mutable --> $DIR/borrowck-pat-at-and-box.rs:42:9 | -LL | let ref a @ box ref mut b = Box::new(NC); - | ^^^^^ --------- mutable borrow occurs here +LL | let ref a @ deref!(ref mut b) = Box::new(NC); + | ^^^^^ --------- mutable borrow occurs here | | | immutable borrow occurs here ... @@ -93,8 +93,8 @@ LL | *b = NC; error[E0502]: cannot borrow value as mutable because it is also borrowed as immutable --> $DIR/borrowck-pat-at-and-box.rs:48:9 | -LL | let ref mut a @ box ref b = Box::new(NC); - | ^^^^^^^^^ ----- immutable borrow occurs here +LL | let ref mut a @ deref!(ref b) = Box::new(NC); + | ^^^^^^^^^ ----- immutable borrow occurs here | | | mutable borrow occurs here ... @@ -104,8 +104,8 @@ LL | drop(b); error[E0502]: cannot borrow value as mutable because it is also borrowed as immutable --> $DIR/borrowck-pat-at-and-box.rs:62:9 | -LL | ref mut a @ box ref b => { - | ^^^^^^^^^ ----- immutable borrow occurs here +LL | ref mut a @ deref!(ref b) => { + | ^^^^^^^^^ ----- immutable borrow occurs here | | | mutable borrow occurs here ... @@ -115,16 +115,16 @@ LL | drop(b); error: cannot borrow value as immutable because it is also borrowed as mutable --> $DIR/borrowck-pat-at-and-box.rs:54:11 | -LL | fn f5(ref mut a @ box ref b: Box) { - | ^^^^^^^^^ ----- value is borrowed by `b` here +LL | fn f5(ref mut a @ deref!(ref b): Box) { + | ^^^^^^^^^ ----- value is borrowed by `b` here | | | value is mutably borrowed by `a` here error[E0502]: cannot borrow value as mutable because it is also borrowed as immutable --> $DIR/borrowck-pat-at-and-box.rs:54:11 | -LL | fn f5(ref mut a @ box ref b: Box) { - | ^^^^^^^^^ ----- immutable borrow occurs here +LL | fn f5(ref mut a @ deref!(ref b): Box) { + | ^^^^^^^^^ ----- immutable borrow occurs here | | | mutable borrow occurs here ... diff --git a/tests/ui/pattern/bindings-after-at/box-patterns.rs b/tests/ui/pattern/bindings-after-at/deref-patterns.rs similarity index 78% rename from tests/ui/pattern/bindings-after-at/box-patterns.rs rename to tests/ui/pattern/bindings-after-at/deref-patterns.rs index 57110b0439a89..d3d486253131a 100644 --- a/tests/ui/pattern/bindings-after-at/box-patterns.rs +++ b/tests/ui/pattern/bindings-after-at/deref-patterns.rs @@ -1,8 +1,8 @@ -// Test bindings-after-at with box-patterns +// Test bindings-after-at with deref patterns //@ run-pass -#![feature(box_patterns)] +#![feature(deref_patterns)] #[derive(Debug, PartialEq)] enum MatchArm { @@ -12,13 +12,13 @@ enum MatchArm { fn test(x: Option>) -> MatchArm { match x { - ref bar @ Some(box n) if n > 0 => { + ref bar @ Some(deref!(n)) if n > 0 => { // bar is a &Option> assert_eq!(bar, &x); MatchArm::Arm(0) }, - Some(ref bar @ box n) if n < 0 => { + Some(ref bar @ deref!(n)) if n < 0 => { // bar is a &Box here assert_eq!(**bar, n); diff --git a/tests/ui/pattern/bindings-after-at/or-patterns-box-patterns.rs b/tests/ui/pattern/bindings-after-at/or-patterns-deref-patterns.rs similarity index 82% rename from tests/ui/pattern/bindings-after-at/or-patterns-box-patterns.rs rename to tests/ui/pattern/bindings-after-at/or-patterns-deref-patterns.rs index f6c285634c07f..77c14036c134f 100644 --- a/tests/ui/pattern/bindings-after-at/or-patterns-box-patterns.rs +++ b/tests/ui/pattern/bindings-after-at/or-patterns-deref-patterns.rs @@ -2,7 +2,7 @@ //@ run-pass -#![feature(box_patterns)] +#![feature(deref_patterns)] #[derive(Debug, PartialEq)] enum MatchArm { @@ -20,12 +20,12 @@ enum Test { fn test(foo: Option>) -> MatchArm { match foo { - ref bar @ Some(box Test::Foo | box Test::Bar) => { + ref bar @ Some(deref!(Test::Foo) | deref!(Test::Bar)) => { assert_eq!(bar, &foo); MatchArm::Arm(0) }, - Some(ref bar @ box Test::Baz | ref bar @ box Test::Qux) => { + Some(ref bar @ deref!(Test::Baz) | ref bar @ deref!(Test::Qux)) => { assert!(**bar == Test::Baz || **bar == Test::Qux); MatchArm::Arm(1) diff --git a/tests/ui/pattern/box-pattern-constructor-mismatch.rs b/tests/ui/pattern/box-pattern-constructor-mismatch.rs deleted file mode 100644 index 8f0a19d740782..0000000000000 --- a/tests/ui/pattern/box-pattern-constructor-mismatch.rs +++ /dev/null @@ -1,11 +0,0 @@ -//! Test that `box _` patterns and `Box { .. }` patterns can't be used to match on the same place. -//! This is required for the current implementation of exhaustiveness analysis for deref patterns. - -#![feature(box_patterns)] - -fn main() { - match Box::new(0) { - box _ => {} //~ ERROR mix of deref patterns and normal constructors - Box { .. } => {} - } -} diff --git a/tests/ui/pattern/deref-pattern-box-constructor-mismatch.rs b/tests/ui/pattern/deref-pattern-box-constructor-mismatch.rs new file mode 100644 index 0000000000000..b8bb6f06f10a1 --- /dev/null +++ b/tests/ui/pattern/deref-pattern-box-constructor-mismatch.rs @@ -0,0 +1,12 @@ +//! Test that `deref!(_)` patterns and `Box { .. }` patterns can't be used +//! to match on the same place. +//! This is required for the current implementation of exhaustiveness analysis for deref patterns. + +#![feature(deref_patterns)] + +fn main() { + match Box::new(0) { + deref!(_) => {} //~ ERROR mix of deref patterns and normal constructors + Box { .. } => {} + } +} diff --git a/tests/ui/pattern/box-pattern-constructor-mismatch.stderr b/tests/ui/pattern/deref-pattern-box-constructor-mismatch.stderr similarity index 53% rename from tests/ui/pattern/box-pattern-constructor-mismatch.stderr rename to tests/ui/pattern/deref-pattern-box-constructor-mismatch.stderr index 489eefe0d21a4..7840b39626338 100644 --- a/tests/ui/pattern/box-pattern-constructor-mismatch.stderr +++ b/tests/ui/pattern/deref-pattern-box-constructor-mismatch.stderr @@ -1,8 +1,8 @@ error: mix of deref patterns and normal constructors - --> $DIR/box-pattern-constructor-mismatch.rs:8:9 + --> $DIR/deref-pattern-box-constructor-mismatch.rs:9:9 | -LL | box _ => {} - | ^^^^^ matches on the result of dereferencing `Box` +LL | deref!(_) => {} + | ^^^^^^^^^ matches on the result of dereferencing `Box` LL | Box { .. } => {} | ^^^^^^^^^^ matches directly on `Box` diff --git a/tests/ui/pattern/box-pattern-nested.rs b/tests/ui/pattern/deref-pattern-nested.rs similarity index 69% rename from tests/ui/pattern/box-pattern-nested.rs rename to tests/ui/pattern/deref-pattern-nested.rs index f686fee8742ce..98172e12a66e4 100644 --- a/tests/ui/pattern/box-pattern-nested.rs +++ b/tests/ui/pattern/deref-pattern-nested.rs @@ -1,7 +1,7 @@ // issue: -// Test nested box pattern matching inside a larger `match` statement. +// Test nested deref pattern matching inside a larger `match` statement. //@ run-pass -#![feature(box_patterns)] +#![feature(deref_patterns)] #[derive(Clone)] enum Noun { @@ -11,7 +11,7 @@ enum Noun { fn fas(n: &Noun) -> Noun { match n { - &Noun::Cell(box Noun::Atom(2), box Noun::Cell(ref a, _)) => (**a).clone(), + &Noun::Cell(Noun::Atom(2), Noun::Cell(ref a, _)) => (**a).clone(), _ => panic!("Invalid fas pattern"), } } diff --git a/tests/ui/pattern/box-pattern-type-mismatch.rs b/tests/ui/pattern/deref-pattern-type-mismatch.rs similarity index 81% rename from tests/ui/pattern/box-pattern-type-mismatch.rs rename to tests/ui/pattern/deref-pattern-type-mismatch.rs index 6c98050325638..3806cab240897 100644 --- a/tests/ui/pattern/box-pattern-type-mismatch.rs +++ b/tests/ui/pattern/deref-pattern-type-mismatch.rs @@ -1,6 +1,6 @@ //! This test used to ICE #124004 -#![feature(box_patterns)] +#![feature(deref_patterns)] use std::ops::{ Deref }; @@ -11,7 +11,7 @@ impl Deref for X { type Target = isize; fn deref(&self) -> &isize { - let &X(box ref x) = self; + let &X(ref x) = self; x } } diff --git a/tests/ui/pattern/box-pattern-type-mismatch.stderr b/tests/ui/pattern/deref-pattern-type-mismatch.stderr similarity index 93% rename from tests/ui/pattern/box-pattern-type-mismatch.stderr rename to tests/ui/pattern/deref-pattern-type-mismatch.stderr index 14f7dbbd839c0..b74003938e055 100644 --- a/tests/ui/pattern/box-pattern-type-mismatch.stderr +++ b/tests/ui/pattern/deref-pattern-type-mismatch.stderr @@ -1,5 +1,5 @@ error[E0261]: use of undeclared lifetime name `'a` - --> $DIR/box-pattern-type-mismatch.rs:7:31 + --> $DIR/deref-pattern-type-mismatch.rs:7:31 | LL | struct X(dyn Iterator); | ^^ undeclared lifetime diff --git a/tests/ui/pattern/match-errors-derived-error-suppression.rs b/tests/ui/pattern/match-errors-derived-error-suppression.rs index 7d817167afcb7..4f95de5d57b42 100644 --- a/tests/ui/pattern/match-errors-derived-error-suppression.rs +++ b/tests/ui/pattern/match-errors-derived-error-suppression.rs @@ -1,8 +1,6 @@ //! Regression test for //@ dont-require-annotations: NOTE -#![feature(box_patterns)] - enum A { B, C } fn main() { @@ -31,13 +29,6 @@ fn main() { //~| NOTE found tuple `(_, _, _)` } - match (true, false) { - box (true, false) => () -//~^ ERROR mismatched types -//~| NOTE expected tuple `(bool, bool)` -//~| NOTE found struct `Box<_>` - } - match (true, false) { &(true, false) => () //~^ ERROR mismatched types diff --git a/tests/ui/pattern/match-errors-derived-error-suppression.stderr b/tests/ui/pattern/match-errors-derived-error-suppression.stderr index 6dc5e0eaca6b4..bd1d06fbadf98 100644 --- a/tests/ui/pattern/match-errors-derived-error-suppression.stderr +++ b/tests/ui/pattern/match-errors-derived-error-suppression.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/match-errors-derived-error-suppression.rs:10:9 + --> $DIR/match-errors-derived-error-suppression.rs:8:9 | LL | match (true, false) { | ------------- this expression has type `(bool, bool)` @@ -10,7 +10,7 @@ LL | A::B => (), found enum `A` error[E0308]: mismatched types - --> $DIR/match-errors-derived-error-suppression.rs:19:9 + --> $DIR/match-errors-derived-error-suppression.rs:17:9 | LL | match (true, false) { | ------------- this expression has type `(bool, bool)` @@ -21,7 +21,7 @@ LL | (true, false, false) => () found tuple `(_, _, _)` error[E0308]: mismatched types - --> $DIR/match-errors-derived-error-suppression.rs:27:9 + --> $DIR/match-errors-derived-error-suppression.rs:25:9 | LL | match (true, false) { | ------------- this expression has type `(bool, bool)` @@ -32,18 +32,7 @@ LL | (true, false, false) => () found tuple `(_, _, _)` error[E0308]: mismatched types - --> $DIR/match-errors-derived-error-suppression.rs:35:9 - | -LL | match (true, false) { - | ------------- this expression has type `(bool, bool)` -LL | box (true, false) => () - | ^^^^^^^^^^^^^^^^^ expected `(bool, bool)`, found `Box<_>` - | - = note: expected tuple `(bool, bool)` - found struct `Box<_>` - -error[E0308]: mismatched types - --> $DIR/match-errors-derived-error-suppression.rs:42:9 + --> $DIR/match-errors-derived-error-suppression.rs:33:9 | LL | match (true, false) { | ------------- this expression has type `(bool, bool)` @@ -54,20 +43,20 @@ LL | &(true, false) => () found reference `&_` error[E0618]: expected function, found `(char, char)` - --> $DIR/match-errors-derived-error-suppression.rs:50:14 + --> $DIR/match-errors-derived-error-suppression.rs:41:14 | LL | let v = [('a', 'b') | ^^^^^^^^^^- help: consider separating array elements with a comma: `,` error[E0308]: mismatched types - --> $DIR/match-errors-derived-error-suppression.rs:57:19 + --> $DIR/match-errors-derived-error-suppression.rs:48:19 | LL | let x: char = true; | ---- ^^^^ expected `char`, found `bool` | | | expected due to this -error: aborting due to 7 previous errors +error: aborting due to 6 previous errors Some errors have detailed explanations: E0308, E0618. For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/pattern/match-struct-var-having-boxed-field.rs b/tests/ui/pattern/match-struct-var-having-boxed-field.rs index 963fab4444ecd..49c0410d7b4e5 100644 --- a/tests/ui/pattern/match-struct-var-having-boxed-field.rs +++ b/tests/ui/pattern/match-struct-var-having-boxed-field.rs @@ -3,7 +3,7 @@ #![allow(unused_mut)] #![allow(unused_variables)] -#![feature(box_patterns)] +#![feature(deref_patterns)] enum E { StructVar { boxed: Box } @@ -13,18 +13,6 @@ fn main() { // Test matching each shorthand notation for field patterns. let mut a = E::StructVar { boxed: Box::new(3) }; - match a { - E::StructVar { box boxed } => { } - } - match a { - E::StructVar { box ref boxed } => { } - } - match a { - E::StructVar { box mut boxed } => { } - } - match a { - E::StructVar { box ref mut boxed } => { } - } match a { E::StructVar { ref boxed } => { } } @@ -38,9 +26,6 @@ fn main() { // Test matching non shorthand notation. Recreate a since last test // moved `boxed` let mut a = E::StructVar { boxed: Box::new(3) }; - match a { - E::StructVar { boxed: box ref mut num } => { } - } match a { E::StructVar { boxed: ref mut num } => { } } diff --git a/tests/ui/pattern/pattern-bad-ref-box-order.fixed b/tests/ui/pattern/pattern-bad-ref-box-order.fixed deleted file mode 100644 index 96b91bca63b15..0000000000000 --- a/tests/ui/pattern/pattern-bad-ref-box-order.fixed +++ /dev/null @@ -1,14 +0,0 @@ -//@ run-rustfix - -#![feature(box_patterns)] -#![allow(dead_code)] - -fn foo(f: Option>) { - match f { - Some(box ref _i) => {}, - //~^ ERROR switch the order of `ref` and `box` - None => {} - } -} - -fn main() { } diff --git a/tests/ui/pattern/pattern-bad-ref-box-order.rs b/tests/ui/pattern/pattern-bad-ref-box-order.rs deleted file mode 100644 index 29bf95d48b085..0000000000000 --- a/tests/ui/pattern/pattern-bad-ref-box-order.rs +++ /dev/null @@ -1,14 +0,0 @@ -//@ run-rustfix - -#![feature(box_patterns)] -#![allow(dead_code)] - -fn foo(f: Option>) { - match f { - Some(ref box _i) => {}, - //~^ ERROR switch the order of `ref` and `box` - None => {} - } -} - -fn main() { } diff --git a/tests/ui/pattern/pattern-bad-ref-box-order.stderr b/tests/ui/pattern/pattern-bad-ref-box-order.stderr deleted file mode 100644 index 6f47f704688ba..0000000000000 --- a/tests/ui/pattern/pattern-bad-ref-box-order.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: switch the order of `ref` and `box` - --> $DIR/pattern-bad-ref-box-order.rs:8:14 - | -LL | Some(ref box _i) => {}, - | ^^^^^^^ - | -help: swap them - | -LL - Some(ref box _i) => {}, -LL + Some(box ref _i) => {}, - | - -error: aborting due to 1 previous error - diff --git a/tests/ui/pattern/rest-pat-semantic-disallowed.rs b/tests/ui/pattern/rest-pat-semantic-disallowed.rs index 156285e0f9fc9..ab2fbc5021e4c 100644 --- a/tests/ui/pattern/rest-pat-semantic-disallowed.rs +++ b/tests/ui/pattern/rest-pat-semantic-disallowed.rs @@ -2,8 +2,6 @@ // outside of slice (+ ident patterns within those), tuple, // and tuple struct patterns and that duplicates are caught in these contexts. -#![feature(box_patterns)] - fn main() {} macro_rules! mk_pat { @@ -17,9 +15,6 @@ fn rest_patterns() { fn foo(..: u8) {} //~ ERROR `..` patterns are not allowed here let ..; //~ ERROR `..` patterns are not allowed here - // Box patterns: - let box ..; //~ ERROR `..` patterns are not allowed here - // In or-patterns: match 1 { 1 | .. => {} //~ ERROR `..` patterns are not allowed here diff --git a/tests/ui/pattern/rest-pat-semantic-disallowed.stderr b/tests/ui/pattern/rest-pat-semantic-disallowed.stderr index beba7def96f52..d3985b830c74a 100644 --- a/tests/ui/pattern/rest-pat-semantic-disallowed.stderr +++ b/tests/ui/pattern/rest-pat-semantic-disallowed.stderr @@ -1,5 +1,5 @@ error: `..` patterns are not allowed here - --> $DIR/rest-pat-semantic-disallowed.rs:10:13 + --> $DIR/rest-pat-semantic-disallowed.rs:8:13 | LL | () => { .. } | ^^ @@ -11,7 +11,7 @@ LL | let mk_pat!(); = note: this error originates in the macro `mk_pat` (in Nightly builds, run with -Z macro-backtrace for more info) error: `..` patterns are not allowed here - --> $DIR/rest-pat-semantic-disallowed.rs:18:9 + --> $DIR/rest-pat-semantic-disallowed.rs:16:9 | LL | let ..; | ^^ @@ -19,15 +19,7 @@ LL | let ..; = note: only allowed in tuple, tuple struct, and slice patterns error: `..` patterns are not allowed here - --> $DIR/rest-pat-semantic-disallowed.rs:21:13 - | -LL | let box ..; - | ^^ - | - = note: only allowed in tuple, tuple struct, and slice patterns - -error: `..` patterns are not allowed here - --> $DIR/rest-pat-semantic-disallowed.rs:25:13 + --> $DIR/rest-pat-semantic-disallowed.rs:20:13 | LL | 1 | .. => {} | ^^ @@ -35,7 +27,7 @@ LL | 1 | .. => {} = note: only allowed in tuple, tuple struct, and slice patterns error: `..` patterns are not allowed here - --> $DIR/rest-pat-semantic-disallowed.rs:29:10 + --> $DIR/rest-pat-semantic-disallowed.rs:24:10 | LL | let &..; | ^^ @@ -43,7 +35,7 @@ LL | let &..; = note: only allowed in tuple, tuple struct, and slice patterns error: `..` patterns are not allowed here - --> $DIR/rest-pat-semantic-disallowed.rs:30:14 + --> $DIR/rest-pat-semantic-disallowed.rs:25:14 | LL | let &mut ..; | ^^ @@ -51,7 +43,7 @@ LL | let &mut ..; = note: only allowed in tuple, tuple struct, and slice patterns error: `..` patterns are not allowed here - --> $DIR/rest-pat-semantic-disallowed.rs:33:13 + --> $DIR/rest-pat-semantic-disallowed.rs:28:13 | LL | let x @ ..; | ^^ @@ -59,7 +51,7 @@ LL | let x @ ..; = note: only allowed in tuple, tuple struct, and slice patterns error: `..` patterns are not allowed here - --> $DIR/rest-pat-semantic-disallowed.rs:35:17 + --> $DIR/rest-pat-semantic-disallowed.rs:30:17 | LL | let ref x @ ..; | ^^ @@ -67,7 +59,7 @@ LL | let ref x @ ..; = note: only allowed in tuple, tuple struct, and slice patterns error: `..` patterns are not allowed here - --> $DIR/rest-pat-semantic-disallowed.rs:36:21 + --> $DIR/rest-pat-semantic-disallowed.rs:31:21 | LL | let ref mut x @ ..; | ^^ @@ -75,7 +67,7 @@ LL | let ref mut x @ ..; = note: only allowed in tuple, tuple struct, and slice patterns error: `..` can only be used once per tuple pattern - --> $DIR/rest-pat-semantic-disallowed.rs:43:9 + --> $DIR/rest-pat-semantic-disallowed.rs:38:9 | LL | .., | -- previously used here @@ -83,7 +75,7 @@ LL | .., | ^^ can only be used once per tuple pattern error: `..` can only be used once per tuple pattern - --> $DIR/rest-pat-semantic-disallowed.rs:44:9 + --> $DIR/rest-pat-semantic-disallowed.rs:39:9 | LL | .., | -- previously used here @@ -92,7 +84,7 @@ LL | .. | ^^ can only be used once per tuple pattern error: `..` can only be used once per tuple pattern - --> $DIR/rest-pat-semantic-disallowed.rs:49:9 + --> $DIR/rest-pat-semantic-disallowed.rs:44:9 | LL | .., | -- previously used here @@ -101,7 +93,7 @@ LL | .. | ^^ can only be used once per tuple pattern error: `..` can only be used once per tuple struct pattern - --> $DIR/rest-pat-semantic-disallowed.rs:59:9 + --> $DIR/rest-pat-semantic-disallowed.rs:54:9 | LL | .., | -- previously used here @@ -109,7 +101,7 @@ LL | .., | ^^ can only be used once per tuple struct pattern error: `..` can only be used once per tuple struct pattern - --> $DIR/rest-pat-semantic-disallowed.rs:60:9 + --> $DIR/rest-pat-semantic-disallowed.rs:55:9 | LL | .., | -- previously used here @@ -118,7 +110,7 @@ LL | .. | ^^ can only be used once per tuple struct pattern error: `..` can only be used once per tuple struct pattern - --> $DIR/rest-pat-semantic-disallowed.rs:65:9 + --> $DIR/rest-pat-semantic-disallowed.rs:60:9 | LL | .., | -- previously used here @@ -127,7 +119,7 @@ LL | .. | ^^ can only be used once per tuple struct pattern error: `..` can only be used once per slice pattern - --> $DIR/rest-pat-semantic-disallowed.rs:73:9 + --> $DIR/rest-pat-semantic-disallowed.rs:68:9 | LL | .., | -- previously used here @@ -135,7 +127,7 @@ LL | .., | ^^ can only be used once per slice pattern error: `..` can only be used once per slice pattern - --> $DIR/rest-pat-semantic-disallowed.rs:74:9 + --> $DIR/rest-pat-semantic-disallowed.rs:69:9 | LL | .., | -- previously used here @@ -144,7 +136,7 @@ LL | .. | ^^ can only be used once per slice pattern error: `..` can only be used once per slice pattern - --> $DIR/rest-pat-semantic-disallowed.rs:78:17 + --> $DIR/rest-pat-semantic-disallowed.rs:73:17 | LL | .., | -- previously used here @@ -152,7 +144,7 @@ LL | ref x @ .., | ^^ can only be used once per slice pattern error: `..` can only be used once per slice pattern - --> $DIR/rest-pat-semantic-disallowed.rs:79:21 + --> $DIR/rest-pat-semantic-disallowed.rs:74:21 | LL | .., | -- previously used here @@ -161,7 +153,7 @@ LL | ref mut y @ .., | ^^ can only be used once per slice pattern error: `..` patterns are not allowed here - --> $DIR/rest-pat-semantic-disallowed.rs:80:18 + --> $DIR/rest-pat-semantic-disallowed.rs:75:18 | LL | (ref z @ ..), | ^^ @@ -169,7 +161,7 @@ LL | (ref z @ ..), = note: only allowed in tuple, tuple struct, and slice patterns error: `..` can only be used once per slice pattern - --> $DIR/rest-pat-semantic-disallowed.rs:81:9 + --> $DIR/rest-pat-semantic-disallowed.rs:76:9 | LL | .., | -- previously used here @@ -178,7 +170,7 @@ LL | .. | ^^ can only be used once per slice pattern error: `..` patterns are not allowed here - --> $DIR/rest-pat-semantic-disallowed.rs:17:12 + --> $DIR/rest-pat-semantic-disallowed.rs:15:12 | LL | fn foo(..: u8) {} | ^^ @@ -186,7 +178,7 @@ LL | fn foo(..: u8) {} = note: only allowed in tuple, tuple struct, and slice patterns error[E0282]: type annotations needed - --> $DIR/rest-pat-semantic-disallowed.rs:33:9 + --> $DIR/rest-pat-semantic-disallowed.rs:28:9 | LL | let x @ ..; | ^^^^^^ @@ -196,6 +188,6 @@ help: consider giving this pattern a type LL | let x @ ..: /* Type */; | ++++++++++++ -error: aborting due to 23 previous errors +error: aborting due to 22 previous errors For more information about this error, try `rustc --explain E0282`. diff --git a/tests/ui/pattern/rest-pat-syntactic.rs b/tests/ui/pattern/rest-pat-syntactic.rs index 59c687bb5a8d8..5c1f93cb48a1e 100644 --- a/tests/ui/pattern/rest-pat-syntactic.rs +++ b/tests/ui/pattern/rest-pat-syntactic.rs @@ -17,11 +17,6 @@ fn rest_patterns() { fn foo(..: u8) {} let ..; - // Box patterns: - let box ..; - //~^ WARN box pattern syntax is experimental - //~| WARN unstable syntax - // In or-patterns: match x { .. | .. => {} @@ -59,7 +54,6 @@ fn rest_patterns() { .. | [ ( - box .., //~ WARN box pattern syntax is experimental &(..), &mut .., x @ .. @@ -69,5 +63,4 @@ fn rest_patterns() { ref mut x @ .. => {} } - //~| WARN unstable syntax } diff --git a/tests/ui/pattern/rest-pat-syntactic.stderr b/tests/ui/pattern/rest-pat-syntactic.stderr deleted file mode 100644 index 41bbfd67dab4c..0000000000000 --- a/tests/ui/pattern/rest-pat-syntactic.stderr +++ /dev/null @@ -1,26 +0,0 @@ -warning: box pattern syntax is experimental - --> $DIR/rest-pat-syntactic.rs:21:9 - | -LL | let box ..; - | ^^^^^^ - | - = note: see issue #29641 for more information - = help: add `#![feature(box_patterns)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = warning: unstable syntax can change at any point in the future, causing a hard error! - = note: for more information, see issue #154045 - -warning: box pattern syntax is experimental - --> $DIR/rest-pat-syntactic.rs:62:17 - | -LL | box .., - | ^^^^^^ - | - = note: see issue #29641 for more information - = help: add `#![feature(box_patterns)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - = warning: unstable syntax can change at any point in the future, causing a hard error! - = note: for more information, see issue #154045 - -warning: 2 warnings emitted - diff --git a/tests/ui/pattern/usefulness/issue-12116.rs b/tests/ui/pattern/usefulness/issue-12116.rs index 3cb92a54029dc..afd79248928d9 100644 --- a/tests/ui/pattern/usefulness/issue-12116.rs +++ b/tests/ui/pattern/usefulness/issue-12116.rs @@ -1,4 +1,4 @@ -#![feature(box_patterns)] +#![feature(deref_patterns)] #![allow(dead_code)] #![allow(unused_variables)] #![deny(unreachable_patterns)] @@ -11,8 +11,8 @@ enum IntList { fn tail(source_list: &IntList) -> IntList { match source_list { - &IntList::Cons(val, box ref next_list) => tail(next_list), - &IntList::Cons(val, box IntList::Nil) => IntList::Cons(val, Box::new(IntList::Nil)), + &IntList::Cons(val, ref next_list) => tail(next_list), + &IntList::Cons(val, IntList::Nil) => IntList::Cons(val, Box::new(IntList::Nil)), //~^ ERROR unreachable pattern _ => panic!(), } diff --git a/tests/ui/pattern/usefulness/issue-12116.stderr b/tests/ui/pattern/usefulness/issue-12116.stderr index 5929b81f6c25e..b721daa460161 100644 --- a/tests/ui/pattern/usefulness/issue-12116.stderr +++ b/tests/ui/pattern/usefulness/issue-12116.stderr @@ -1,10 +1,10 @@ error: unreachable pattern --> $DIR/issue-12116.rs:15:9 | -LL | &IntList::Cons(val, box ref next_list) => tail(next_list), - | -------------------------------------- matches all the relevant values -LL | &IntList::Cons(val, box IntList::Nil) => IntList::Cons(val, Box::new(IntList::Nil)), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no value can reach this +LL | &IntList::Cons(val, ref next_list) => tail(next_list), + | ---------------------------------- matches all the relevant values +LL | &IntList::Cons(val, IntList::Nil) => IntList::Cons(val, Box::new(IntList::Nil)), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no value can reach this | note: the lint level is defined here --> $DIR/issue-12116.rs:4:9 diff --git a/tests/ui/pattern/usefulness/issue-3601.rs b/tests/ui/pattern/usefulness/issue-3601.rs index 868e8c7102724..5501cef8f1b7f 100644 --- a/tests/ui/pattern/usefulness/issue-3601.rs +++ b/tests/ui/pattern/usefulness/issue-3601.rs @@ -1,4 +1,4 @@ -#![feature(box_patterns)] +#![feature(deref_patterns)] struct HTMLImageData { image: Option, @@ -27,13 +27,13 @@ fn main() { // n.b. span could be better match n.kind { - box NodeKind::Element(ed) => match ed.kind { + NodeKind::Element(ed) => match ed.kind { //~^ ERROR non-exhaustive patterns //~| NOTE the matched value is of type //~| NOTE match arms with guards don't count towards exhaustivity - //~| NOTE pattern `box ElementKind::HTMLImageElement(_)` not covered + //~| NOTE pattern `deref!(ElementKind::HTMLImageElement(_))` not covered //~| NOTE `Box` defined here - box ElementKind::HTMLImageElement(ref d) if d.image.is_some() => true, + ElementKind::HTMLImageElement(ref d) if d.image.is_some() => true, }, }; } diff --git a/tests/ui/pattern/usefulness/issue-3601.stderr b/tests/ui/pattern/usefulness/issue-3601.stderr index a3fcaa79b066f..a4c24542b05fc 100644 --- a/tests/ui/pattern/usefulness/issue-3601.stderr +++ b/tests/ui/pattern/usefulness/issue-3601.stderr @@ -1,8 +1,8 @@ -error[E0004]: non-exhaustive patterns: `box ElementKind::HTMLImageElement(_)` not covered - --> $DIR/issue-3601.rs:30:44 +error[E0004]: non-exhaustive patterns: `deref!(ElementKind::HTMLImageElement(_))` not covered + --> $DIR/issue-3601.rs:30:40 | -LL | box NodeKind::Element(ed) => match ed.kind { - | ^^^^^^^ pattern `box ElementKind::HTMLImageElement(_)` not covered +LL | NodeKind::Element(ed) => match ed.kind { + | ^^^^^^^ pattern `deref!(ElementKind::HTMLImageElement(_))` not covered | note: `Box` defined here --> $SRC_DIR/alloc/src/boxed.rs:LL:COL @@ -10,8 +10,8 @@ note: `Box` defined here = note: match arms with guards don't count towards exhaustivity help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | -LL ~ box ElementKind::HTMLImageElement(ref d) if d.image.is_some() => true, -LL ~ box ElementKind::HTMLImageElement(_) => todo!(), +LL ~ ElementKind::HTMLImageElement(ref d) if d.image.is_some() => true, +LL ~ deref!(ElementKind::HTMLImageElement(_)) => todo!(), | error: aborting due to 1 previous error diff --git a/tests/ui/range/range-inclusive-pattern-precedence2.rs b/tests/ui/range/range-inclusive-pattern-precedence2.rs deleted file mode 100644 index 39f026201bf54..0000000000000 --- a/tests/ui/range/range-inclusive-pattern-precedence2.rs +++ /dev/null @@ -1,21 +0,0 @@ -//@ edition:2015 -// We are going to disallow `&a..=b` and `box a..=b` in a pattern. However, the -// older ... syntax is still allowed as a stability guarantee. - -#![feature(box_patterns)] -#![warn(ellipsis_inclusive_range_patterns)] - -fn main() { - match Box::new(12) { - // FIXME: can we add suggestions like `&(0..=9)`? - box 0...9 => {} - //~^ WARN `...` range patterns are deprecated - //~| WARN this is accepted in the current edition - //~| HELP use `..=` for an inclusive range - box 10..=15 => {} - //~^ ERROR the range pattern here has ambiguous interpretation - //~^^ HELP add parentheses to clarify the precedence - box (16..=20) => {} - _ => {} - } -} diff --git a/tests/ui/range/range-inclusive-pattern-precedence2.stderr b/tests/ui/range/range-inclusive-pattern-precedence2.stderr deleted file mode 100644 index 2415ef0572dc1..0000000000000 --- a/tests/ui/range/range-inclusive-pattern-precedence2.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error: the range pattern here has ambiguous interpretation - --> $DIR/range-inclusive-pattern-precedence2.rs:15:13 - | -LL | box 10..=15 => {} - | ^^^^^^^ - | -help: add parentheses to clarify the precedence - | -LL | box (10..=15) => {} - | + + - -warning: `...` range patterns are deprecated - --> $DIR/range-inclusive-pattern-precedence2.rs:11:14 - | -LL | box 0...9 => {} - | ^^^ help: use `..=` for an inclusive range - | - = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! - = note: for more information, see -note: the lint level is defined here - --> $DIR/range-inclusive-pattern-precedence2.rs:6:9 - | -LL | #![warn(ellipsis_inclusive_range_patterns)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 1 previous error; 1 warning emitted - diff --git a/tests/ui/reachable/unreachable-arm.rs b/tests/ui/reachable/unreachable-arm.rs index 3277bf0d52b20..ddc9ae9622ed0 100644 --- a/tests/ui/reachable/unreachable-arm.rs +++ b/tests/ui/reachable/unreachable-arm.rs @@ -1,5 +1,3 @@ -#![feature(box_patterns)] - #![allow(dead_code)] #![deny(unreachable_patterns)] @@ -7,7 +5,7 @@ enum Foo { A(Box, isize), B(usize), } fn main() { match Foo::B(1) { - Foo::B(_) | Foo::A(box _, 1) => { } + Foo::B(_) | Foo::A(Box { .. }, 1) => { } Foo::A(_, 1) => { } //~ ERROR unreachable pattern _ => { } } diff --git a/tests/ui/reachable/unreachable-arm.stderr b/tests/ui/reachable/unreachable-arm.stderr index 50c29b30c69cb..db05a1176a5a8 100644 --- a/tests/ui/reachable/unreachable-arm.stderr +++ b/tests/ui/reachable/unreachable-arm.stderr @@ -1,13 +1,13 @@ error: unreachable pattern - --> $DIR/unreachable-arm.rs:11:9 + --> $DIR/unreachable-arm.rs:9:9 | -LL | Foo::B(_) | Foo::A(box _, 1) => { } - | ---------------------------- matches all the relevant values +LL | Foo::B(_) | Foo::A(Box { .. }, 1) => { } + | --------------------------------- matches all the relevant values LL | Foo::A(_, 1) => { } | ^^^^^^^^^^^^ no value can reach this | note: the lint level is defined here - --> $DIR/unreachable-arm.rs:4:9 + --> $DIR/unreachable-arm.rs:2:9 | LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/regions/regions-dependent-addr-of.rs b/tests/ui/regions/regions-dependent-addr-of.rs index 12fc38a02f72d..9fc837d5c60d1 100644 --- a/tests/ui/regions/regions-dependent-addr-of.rs +++ b/tests/ui/regions/regions-dependent-addr-of.rs @@ -1,8 +1,7 @@ //@ run-pass // Test lifetimes are linked properly when we create dependent region pointers. // Issue #3148. - -#![feature(box_patterns)] +#![feature(deref_patterns)] struct A { value: B @@ -71,7 +70,7 @@ fn get_v6_c(a: &A, _i: usize) -> &isize { fn get_v5_ref(a: &A, _i: usize) -> &isize { match &a.value { - &B {v5: box C {f: ref v}, ..} => v + &B {v5: C {f: ref v}, ..} => v } } diff --git a/tests/ui/regions/regions-ref-in-fn-arg.rs b/tests/ui/regions/regions-ref-in-fn-arg.rs index 3df529c9f0dae..04968ee709042 100644 --- a/tests/ui/regions/regions-ref-in-fn-arg.rs +++ b/tests/ui/regions/regions-ref-in-fn-arg.rs @@ -1,14 +1,11 @@ -#![feature(box_patterns)] - - -fn arg_item(box ref x: Box) -> &'static isize { +fn arg_item(ref x: Box) -> &'static isize { x //~ ERROR cannot return value referencing function parameter } fn with(f: F) -> R where F: FnOnce(Box) -> R { f(Box::new(3)) } fn arg_closure() -> &'static isize { - with(|box ref x| x) //~ ERROR cannot return value referencing function parameter + with(|ref x| x) //~ ERROR cannot return value referencing function parameter } fn main() {} diff --git a/tests/ui/regions/regions-ref-in-fn-arg.stderr b/tests/ui/regions/regions-ref-in-fn-arg.stderr index ccba6c59b616e..2c879632d2c93 100644 --- a/tests/ui/regions/regions-ref-in-fn-arg.stderr +++ b/tests/ui/regions/regions-ref-in-fn-arg.stderr @@ -1,16 +1,16 @@ error[E0515]: cannot return value referencing function parameter - --> $DIR/regions-ref-in-fn-arg.rs:5:5 + --> $DIR/regions-ref-in-fn-arg.rs:2:5 | -LL | fn arg_item(box ref x: Box) -> &'static isize { - | --------- function parameter borrowed here +LL | fn arg_item(ref x: Box) -> &'static isize { + | ----- function parameter borrowed here LL | x | ^ returns a value referencing data owned by the current function error[E0515]: cannot return value referencing function parameter - --> $DIR/regions-ref-in-fn-arg.rs:11:22 + --> $DIR/regions-ref-in-fn-arg.rs:8:18 | -LL | with(|box ref x| x) - | --------- ^ returns a value referencing data owned by the current function +LL | with(|ref x| x) + | ----- ^ returns a value referencing data owned by the current function | | | function parameter borrowed here diff --git a/tests/ui/rfcs/rfc-2005-default-binding-mode/box.rs b/tests/ui/rfcs/rfc-2005-default-binding-mode/box.rs deleted file mode 100644 index de8afd95a84a9..0000000000000 --- a/tests/ui/rfcs/rfc-2005-default-binding-mode/box.rs +++ /dev/null @@ -1,18 +0,0 @@ -//@ run-pass -#![allow(unreachable_patterns)] -#![feature(box_patterns)] - -struct Foo{} - -pub fn main() { - let b = Box::new(Foo{}); - let box f = &b; - let _: &Foo = f; - - match &&&b { - box f => { - let _: &Foo = f; - }, - _ => panic!(), - } -} diff --git a/tests/ui/traits/trait-object-destructure.rs b/tests/ui/traits/trait-object-destructure.rs index 6c091677c8ce6..029a14102a501 100644 --- a/tests/ui/traits/trait-object-destructure.rs +++ b/tests/ui/traits/trait-object-destructure.rs @@ -1,10 +1,8 @@ -//! Regression test for destructuring trait references (`&dyn T`/`Box`). -//! Checks cases where number of `&`/`Box` patterns (n) matches/doesn't match references (m). +//! Regression test for destructuring trait references (`&dyn T`). +//! Checks cases where number of `&` patterns (n) matches/doesn't match references (m). //! //! Issue: https://github.com/rust-lang/rust/issues/15031 -#![feature(box_patterns)] - trait T { fn foo(&self) {} } @@ -20,10 +18,8 @@ fn main() { // Error cases: n == m (cannot dereference trait object) let &x = &1isize as &dyn T; //~ ERROR type `&dyn T` cannot be dereferenced let &&x = &(&1isize as &dyn T); //~ ERROR type `&dyn T` cannot be dereferenced - let box x = Box::new(1isize) as Box; //~ ERROR type `Box` cannot be dereferenced // Error cases: n > m (type mismatch) let &&x = &1isize as &dyn T; //~ ERROR mismatched types let &&&x = &(&1isize as &dyn T); //~ ERROR mismatched types - let box box x = Box::new(1isize) as Box; //~ ERROR mismatched types } diff --git a/tests/ui/traits/trait-object-destructure.stderr b/tests/ui/traits/trait-object-destructure.stderr index c7c832dc40aff..297e0c889fd56 100644 --- a/tests/ui/traits/trait-object-destructure.stderr +++ b/tests/ui/traits/trait-object-destructure.stderr @@ -1,23 +1,17 @@ error[E0033]: type `&dyn T` cannot be dereferenced - --> $DIR/trait-object-destructure.rs:21:9 + --> $DIR/trait-object-destructure.rs:19:9 | LL | let &x = &1isize as &dyn T; | ^^ type `&dyn T` cannot be dereferenced error[E0033]: type `&dyn T` cannot be dereferenced - --> $DIR/trait-object-destructure.rs:22:10 + --> $DIR/trait-object-destructure.rs:20:10 | LL | let &&x = &(&1isize as &dyn T); | ^^ type `&dyn T` cannot be dereferenced -error[E0033]: type `Box` cannot be dereferenced - --> $DIR/trait-object-destructure.rs:23:9 - | -LL | let box x = Box::new(1isize) as Box; - | ^^^^^ type `Box` cannot be dereferenced - error[E0308]: mismatched types - --> $DIR/trait-object-destructure.rs:26:10 + --> $DIR/trait-object-destructure.rs:23:10 | LL | let &&x = &1isize as &dyn T; | ^^ ----------------- this expression has type `&dyn T` @@ -33,7 +27,7 @@ LL + let &x = &1isize as &dyn T; | error[E0308]: mismatched types - --> $DIR/trait-object-destructure.rs:27:11 + --> $DIR/trait-object-destructure.rs:24:11 | LL | let &&&x = &(&1isize as &dyn T); | ^^ -------------------- this expression has type `&&dyn T` @@ -48,18 +42,7 @@ LL - let &&&x = &(&1isize as &dyn T); LL + let &&x = &(&1isize as &dyn T); | -error[E0308]: mismatched types - --> $DIR/trait-object-destructure.rs:28:13 - | -LL | let box box x = Box::new(1isize) as Box; - | ^^^^^ ------------------------------ this expression has type `Box` - | | - | expected `dyn T`, found `Box<_>` - | - = note: expected trait object `dyn T` - found struct `Box<_>` - -error: aborting due to 6 previous errors +error: aborting due to 4 previous errors Some errors have detailed explanations: E0033, E0308. For more information about an error, try `rustc --explain E0033`. diff --git a/tests/ui/uninhabited/uninhabited-patterns.rs b/tests/ui/uninhabited/uninhabited-patterns.rs index 1f30af2acc697..e82de48d88983 100644 --- a/tests/ui/uninhabited/uninhabited-patterns.rs +++ b/tests/ui/uninhabited/uninhabited-patterns.rs @@ -1,5 +1,4 @@ #![feature(exhaustive_patterns)] -#![feature(box_patterns)] #![feature(never_type)] #![deny(unreachable_patterns)] @@ -27,7 +26,7 @@ fn main() { let x: Result, &[Result]> = Err(&[]); match x { - Ok(box _) => (), // We'd get a non-exhaustiveness error if this arm was removed; don't lint. + Ok(_) => (), // We'd get a non-exhaustiveness error if this arm was removed; don't lint. Err(&[]) => (), Err(&[..]) => (), } diff --git a/tests/ui/uninhabited/uninhabited-patterns.stderr b/tests/ui/uninhabited/uninhabited-patterns.stderr index 62113c82a3648..d2964694c2ebf 100644 --- a/tests/ui/uninhabited/uninhabited-patterns.stderr +++ b/tests/ui/uninhabited/uninhabited-patterns.stderr @@ -1,5 +1,5 @@ error[E0004]: non-exhaustive patterns: `Ok(_)` not covered - --> $DIR/uninhabited-patterns.rs:34:11 + --> $DIR/uninhabited-patterns.rs:33:11 | LL | match x { | ^ pattern `Ok(_)` not covered @@ -17,7 +17,7 @@ LL ~ Ok(_) => todo!(), | error: unreachable pattern - --> $DIR/uninhabited-patterns.rs:43:9 + --> $DIR/uninhabited-patterns.rs:42:9 | LL | Err(Ok(_y)) => (), | ^^^^^^^^^^^------- @@ -27,13 +27,13 @@ LL | Err(Ok(_y)) => (), | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types note: the lint level is defined here - --> $DIR/uninhabited-patterns.rs:4:9 + --> $DIR/uninhabited-patterns.rs:3:9 | LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/uninhabited-patterns.rs:46:15 + --> $DIR/uninhabited-patterns.rs:45:15 | LL | while let Some(_y) = foo() { | ^^^^^^^^ matches no values because `NotSoSecretlyEmpty` is uninhabited diff --git a/tests/ui/unpretty/exhaustive.expanded.stdout b/tests/ui/unpretty/exhaustive.expanded.stdout index 17995cabc75a7..258203b7a89cf 100644 --- a/tests/ui/unpretty/exhaustive.expanded.stdout +++ b/tests/ui/unpretty/exhaustive.expanded.stdout @@ -10,7 +10,6 @@ // errors that only occur once we get past the AST. #![feature(auto_traits)] -#![feature(box_patterns)] #![feature(builtin_syntax)] #![feature(const_trait_impl)] #![feature(coroutines)] @@ -514,8 +513,6 @@ mod patterns { } /// PatKind::Tuple fn pat_tuple() { let (); let (true,); let (true, false); } - /// PatKind::Box - fn pat_box() { let box pat; } /// PatKind::Deref fn pat_deref() { let deref!(pat); } /// PatKind::Ref diff --git a/tests/ui/unpretty/exhaustive.hir.stderr b/tests/ui/unpretty/exhaustive.hir.stderr index f6800fc9c1e6f..276bc5b5d2573 100644 --- a/tests/ui/unpretty/exhaustive.hir.stderr +++ b/tests/ui/unpretty/exhaustive.hir.stderr @@ -1,17 +1,17 @@ error[E0697]: closures cannot be static - --> $DIR/exhaustive.rs:211:9 + --> $DIR/exhaustive.rs:210:9 | LL | static || value; | ^^^^^^^^^ error[E0697]: closures cannot be static - --> $DIR/exhaustive.rs:212:9 + --> $DIR/exhaustive.rs:211:9 | LL | static move || value; | ^^^^^^^^^^^^^^ error[E0728]: `await` is only allowed inside `async` functions and blocks - --> $DIR/exhaustive.rs:241:13 + --> $DIR/exhaustive.rs:240:13 | LL | fn expr_await() { | --------------- this is not `async` @@ -20,19 +20,19 @@ LL | fut.await; | ^^^^^ only allowed inside `async` functions and blocks error: in expressions, `_` can only be used on the left-hand side of an assignment - --> $DIR/exhaustive.rs:292:9 + --> $DIR/exhaustive.rs:291:9 | LL | _; | ^ `_` not allowed here error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:302:9 + --> $DIR/exhaustive.rs:301:9 | LL | x::(); | ^^^^^ only `Fn` traits may use parentheses error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:303:9 + --> $DIR/exhaustive.rs:302:9 | LL | x::(T, T) -> T; | ^^^^^^^^^^^^^^ only `Fn` traits may use parentheses @@ -44,31 +44,31 @@ LL + x:: -> T; | error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:304:9 + --> $DIR/exhaustive.rs:303:9 | LL | crate::() -> ()::expressions::() -> ()::expr_path; | ^^^^^^^^^^^^^^^ only `Fn` traits may use parentheses error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:304:26 + --> $DIR/exhaustive.rs:303:26 | LL | crate::() -> ()::expressions::() -> ()::expr_path; | ^^^^^^^^^^^^^^^^^^^^^ only `Fn` traits may use parentheses error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:307:9 + --> $DIR/exhaustive.rs:306:9 | LL | core::()::marker::()::PhantomData; | ^^^^^^^^ only `Fn` traits may use parentheses error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:307:19 + --> $DIR/exhaustive.rs:306:19 | LL | core::()::marker::()::PhantomData; | ^^^^^^^^^^ only `Fn` traits may use parentheses error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks - --> $DIR/exhaustive.rs:394:9 + --> $DIR/exhaustive.rs:393:9 | LL | yield; | ^^^^^ @@ -79,7 +79,7 @@ LL | #[coroutine] fn expr_yield() { | ++++++++++++ error[E0703]: invalid ABI: found `C++` - --> $DIR/exhaustive.rs:474:23 + --> $DIR/exhaustive.rs:473:23 | LL | unsafe extern "C++" {} | ^^^^^ invalid ABI @@ -87,7 +87,7 @@ LL | unsafe extern "C++" {} = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions error: `..` patterns are not allowed here - --> $DIR/exhaustive.rs:681:13 + --> $DIR/exhaustive.rs:675:13 | LL | let ..; | ^^ @@ -95,13 +95,13 @@ LL | let ..; = note: only allowed in tuple, tuple struct, and slice patterns error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:796:16 + --> $DIR/exhaustive.rs:790:16 | LL | let _: T() -> !; | ^^^^^^^^ only `Fn` traits may use parentheses error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/exhaustive.rs:810:16 + --> $DIR/exhaustive.rs:804:16 | LL | let _: impl Send; | ^^^^^^^^^ @@ -112,7 +112,7 @@ LL | let _: impl Send; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/exhaustive.rs:811:16 + --> $DIR/exhaustive.rs:805:16 | LL | let _: impl Send + 'static; | ^^^^^^^^^^^^^^^^^^^ @@ -123,7 +123,7 @@ LL | let _: impl Send + 'static; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/exhaustive.rs:812:16 + --> $DIR/exhaustive.rs:806:16 | LL | let _: impl 'static + Send; | ^^^^^^^^^^^^^^^^^^^ @@ -134,7 +134,7 @@ LL | let _: impl 'static + Send; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/exhaustive.rs:813:16 + --> $DIR/exhaustive.rs:807:16 | LL | let _: impl ?Sized; | ^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL | let _: impl ?Sized; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/exhaustive.rs:814:16 + --> $DIR/exhaustive.rs:808:16 | LL | let _: impl [const] Clone; | ^^^^^^^^^^^^^^^^^^ @@ -156,7 +156,7 @@ LL | let _: impl [const] Clone; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/exhaustive.rs:815:16 + --> $DIR/exhaustive.rs:809:16 | LL | let _: impl for<'a> Send; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unpretty/exhaustive.hir.stdout b/tests/ui/unpretty/exhaustive.hir.stdout index 78403e1704dca..b54785c0675c0 100644 --- a/tests/ui/unpretty/exhaustive.hir.stdout +++ b/tests/ui/unpretty/exhaustive.hir.stdout @@ -9,12 +9,12 @@ // errors that only occur once we get past the AST. #![allow(incomplete_features)] -#![attr = Feature([auto_traits#0, box_patterns#0, builtin_syntax#0, -const_trait_impl#0, coroutines#0, decl_macro#0, deref_patterns#0, -explicit_tail_calls#0, gen_blocks#0, more_qualified_paths#0, never_patterns#0, -never_type#0, pattern_types#0, pattern_type_macro#0, prelude_import#0, -specialization#0, trace_macros#0, trait_alias#0, try_blocks#0, -try_blocks_heterogeneous#0, yeet_expr#0])] +#![attr = Feature([auto_traits#0, builtin_syntax#0, const_trait_impl#0, +coroutines#0, decl_macro#0, deref_patterns#0, explicit_tail_calls#0, +gen_blocks#0, more_qualified_paths#0, never_patterns#0, never_type#0, +pattern_types#0, pattern_type_macro#0, prelude_import#0, specialization#0, +trace_macros#0, trait_alias#0, try_blocks#0, try_blocks_heterogeneous#0, +yeet_expr#0])] extern crate std; #[attr = PreludeImport] use std::prelude::rust_2024::*; @@ -565,8 +565,6 @@ mod patterns { } /// PatKind::Tuple fn pat_tuple() { let (); let (true,); let (true, false); } - /// PatKind::Box - fn pat_box() { let box pat; } /// PatKind::Deref fn pat_deref() { let deref!(pat); } /// PatKind::Ref diff --git a/tests/ui/unpretty/exhaustive.rs b/tests/ui/unpretty/exhaustive.rs index 462429ea8e27e..72dcbcd57e2c1 100644 --- a/tests/ui/unpretty/exhaustive.rs +++ b/tests/ui/unpretty/exhaustive.rs @@ -9,7 +9,6 @@ // errors that only occur once we get past the AST. #![feature(auto_traits)] -#![feature(box_patterns)] #![feature(builtin_syntax)] #![feature(const_trait_impl)] #![feature(coroutines)] @@ -637,11 +636,6 @@ mod patterns { let (true, false); } - /// PatKind::Box - fn pat_box() { - let box pat; - } - /// PatKind::Deref fn pat_deref() { let deref!(pat); diff --git a/tests/ui/unsized-locals/unsized-locals-using-unsized-fn-params.rs b/tests/ui/unsized-locals/unsized-locals-using-unsized-fn-params.rs index 15263954ced77..8c502563f3fbd 100644 --- a/tests/ui/unsized-locals/unsized-locals-using-unsized-fn-params.rs +++ b/tests/ui/unsized-locals/unsized-locals-using-unsized-fn-params.rs @@ -1,10 +1,5 @@ -#![feature(box_patterns)] #![feature(unsized_fn_params)] -#[allow(dead_code)] -fn f1(box box _b: Box>) {} -//~^ ERROR: the size for values of type `[u8]` cannot be known at compilation time [E0277] - fn f2((_x, _y): (i32, [i32])) {} //~^ ERROR: the size for values of type `[i32]` cannot be known at compilation time [E0277] diff --git a/tests/ui/unsized-locals/unsized-locals-using-unsized-fn-params.stderr b/tests/ui/unsized-locals/unsized-locals-using-unsized-fn-params.stderr index fe6780c438c96..902dd287212f7 100644 --- a/tests/ui/unsized-locals/unsized-locals-using-unsized-fn-params.stderr +++ b/tests/ui/unsized-locals/unsized-locals-using-unsized-fn-params.stderr @@ -1,14 +1,5 @@ -error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/unsized-locals-using-unsized-fn-params.rs:5:15 - | -LL | fn f1(box box _b: Box>) {} - | ^^ doesn't have a size known at compile-time - | - = help: the trait `Sized` is not implemented for `[u8]` - = note: all local variables must have a statically known size - error[E0277]: the size for values of type `[i32]` cannot be known at compilation time - --> $DIR/unsized-locals-using-unsized-fn-params.rs:8:12 + --> $DIR/unsized-locals-using-unsized-fn-params.rs:3:12 | LL | fn f2((_x, _y): (i32, [i32])) {} | ^^ doesn't have a size known at compile-time @@ -17,7 +8,7 @@ LL | fn f2((_x, _y): (i32, [i32])) {} = note: all local variables must have a statically known size error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/unsized-locals-using-unsized-fn-params.rs:13:9 + --> $DIR/unsized-locals-using-unsized-fn-params.rs:8:9 | LL | let _foo: [u8] = *foo; | ^^^^ doesn't have a size known at compile-time @@ -29,6 +20,6 @@ help: consider borrowing here LL | let _foo: &[u8] = *foo; | + -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`.