From 299213ffae4d994943719d3ced29421b247dd66b Mon Sep 17 00:00:00 2001 From: Augie Fackler Date: Fri, 14 Aug 2026 10:43:40 -0400 Subject: [PATCH 01/23] PassWrapper: handle LLVM 24 change in function types LLVM 24 stopped using llvm::Any here to avoid heap allocations in PassInstrumentation. --- .../rustc_llvm/llvm-wrapper/PassWrapper.cpp | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 3ad59c53a5bf3..50cdcbc29874f 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -523,6 +523,17 @@ extern "C" typedef void (*LLVMRustSelfProfileBeforePassCallback)( extern "C" typedef void (*LLVMRustSelfProfileAfterPassCallback)( void *); // LlvmSelfProfiler +#if LLVM_VERSION_GE(24, 0) +std::string LLVMRustwrappedIrGetName(const llvm::IRUnitRef &WrappedIr) { + if (const auto *Cast = dyn_cast(WrappedIr)) + return Cast->getName().str(); + if (const auto *Cast = dyn_cast(WrappedIr)) + return Cast->getName().str(); + if (const auto *Cast = dyn_cast(WrappedIr)) + return Cast->getName().str(); + if (const auto *Cast = dyn_cast(WrappedIr)) + return Cast->getName(); +#else std::string LLVMRustwrappedIrGetName(const llvm::Any &WrappedIr) { if (const auto *Cast = any_cast(&WrappedIr)) return (*Cast)->getName().str(); @@ -532,6 +543,7 @@ std::string LLVMRustwrappedIrGetName(const llvm::Any &WrappedIr) { return (*Cast)->getName().str(); if (const auto *Cast = any_cast(&WrappedIr)) return (*Cast)->getName(); +#endif return ""; } @@ -540,15 +552,24 @@ void LLVMSelfProfileInitializeCallbacks( LLVMRustSelfProfileBeforePassCallback BeforePassCallback, LLVMRustSelfProfileAfterPassCallback AfterPassCallback) { PIC.registerBeforeNonSkippedPassCallback( +#if LLVM_VERSION_GE(24, 0) + [LlvmSelfProfiler, BeforePassCallback](StringRef Pass, llvm::IRUnitRef Ir) { +#else [LlvmSelfProfiler, BeforePassCallback](StringRef Pass, llvm::Any Ir) { +#endif std::string PassName = Pass.str(); std::string IrName = LLVMRustwrappedIrGetName(Ir); BeforePassCallback(LlvmSelfProfiler, PassName.c_str(), IrName.c_str()); }); PIC.registerAfterPassCallback( +#if LLVM_VERSION_GE(24, 0) + [LlvmSelfProfiler, AfterPassCallback]( + StringRef Pass, llvm::IRUnitRef IR, const PreservedAnalyses &Preserved) { +#else [LlvmSelfProfiler, AfterPassCallback]( StringRef Pass, llvm::Any IR, const PreservedAnalyses &Preserved) { +#endif AfterPassCallback(LlvmSelfProfiler); }); @@ -557,16 +578,25 @@ void LLVMSelfProfileInitializeCallbacks( AfterPassCallback](StringRef Pass, const PreservedAnalyses &Preserved) { AfterPassCallback(LlvmSelfProfiler); }); - +#if LLVM_VERSION_GE(24, 0) + PIC.registerBeforeAnalysisCallback( + [LlvmSelfProfiler, BeforePassCallback](StringRef Pass, llvm::IRUnitRef Ir) { +#else PIC.registerBeforeAnalysisCallback( [LlvmSelfProfiler, BeforePassCallback](StringRef Pass, llvm::Any Ir) { +#endif std::string PassName = Pass.str(); std::string IrName = LLVMRustwrappedIrGetName(Ir); BeforePassCallback(LlvmSelfProfiler, PassName.c_str(), IrName.c_str()); }); +#if LLVM_VERSION_GE(24, 0) + PIC.registerAfterAnalysisCallback( + [LlvmSelfProfiler, AfterPassCallback](StringRef Pass, llvm::IRUnitRef Ir) { +#else PIC.registerAfterAnalysisCallback( [LlvmSelfProfiler, AfterPassCallback](StringRef Pass, llvm::Any Ir) { +#endif AfterPassCallback(LlvmSelfProfiler); }); } From 50b867f932c2dd7239571fbcc540d8f8f9ecd057 Mon Sep 17 00:00:00 2001 From: Augie Fackler Date: Fri, 14 Aug 2026 11:23:43 -0400 Subject: [PATCH 02/23] PassWrapper: clang-format --- .../rustc_llvm/llvm-wrapper/PassWrapper.cpp | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 50cdcbc29874f..06526e718b791 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -553,7 +553,8 @@ void LLVMSelfProfileInitializeCallbacks( LLVMRustSelfProfileAfterPassCallback AfterPassCallback) { PIC.registerBeforeNonSkippedPassCallback( #if LLVM_VERSION_GE(24, 0) - [LlvmSelfProfiler, BeforePassCallback](StringRef Pass, llvm::IRUnitRef Ir) { + [LlvmSelfProfiler, BeforePassCallback](StringRef Pass, + llvm::IRUnitRef Ir) { #else [LlvmSelfProfiler, BeforePassCallback](StringRef Pass, llvm::Any Ir) { #endif @@ -564,8 +565,9 @@ void LLVMSelfProfileInitializeCallbacks( PIC.registerAfterPassCallback( #if LLVM_VERSION_GE(24, 0) - [LlvmSelfProfiler, AfterPassCallback]( - StringRef Pass, llvm::IRUnitRef IR, const PreservedAnalyses &Preserved) { + [LlvmSelfProfiler, + AfterPassCallback](StringRef Pass, llvm::IRUnitRef IR, + const PreservedAnalyses &Preserved) { #else [LlvmSelfProfiler, AfterPassCallback]( StringRef Pass, llvm::Any IR, const PreservedAnalyses &Preserved) { @@ -579,26 +581,26 @@ void LLVMSelfProfileInitializeCallbacks( AfterPassCallback(LlvmSelfProfiler); }); #if LLVM_VERSION_GE(24, 0) - PIC.registerBeforeAnalysisCallback( - [LlvmSelfProfiler, BeforePassCallback](StringRef Pass, llvm::IRUnitRef Ir) { + PIC.registerBeforeAnalysisCallback([LlvmSelfProfiler, BeforePassCallback]( + StringRef Pass, llvm::IRUnitRef Ir) { #else PIC.registerBeforeAnalysisCallback( [LlvmSelfProfiler, BeforePassCallback](StringRef Pass, llvm::Any Ir) { #endif - std::string PassName = Pass.str(); - std::string IrName = LLVMRustwrappedIrGetName(Ir); - BeforePassCallback(LlvmSelfProfiler, PassName.c_str(), IrName.c_str()); - }); + std::string PassName = Pass.str(); + std::string IrName = LLVMRustwrappedIrGetName(Ir); + BeforePassCallback(LlvmSelfProfiler, PassName.c_str(), IrName.c_str()); + }); #if LLVM_VERSION_GE(24, 0) - PIC.registerAfterAnalysisCallback( - [LlvmSelfProfiler, AfterPassCallback](StringRef Pass, llvm::IRUnitRef Ir) { + PIC.registerAfterAnalysisCallback([LlvmSelfProfiler, AfterPassCallback]( + StringRef Pass, llvm::IRUnitRef Ir) { #else PIC.registerAfterAnalysisCallback( [LlvmSelfProfiler, AfterPassCallback](StringRef Pass, llvm::Any Ir) { #endif - AfterPassCallback(LlvmSelfProfiler); - }); + AfterPassCallback(LlvmSelfProfiler); + }); } enum class LLVMRustOptStage { From 226b17508f45632d1c962b228718e072d03a4037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Mon, 24 Aug 2026 08:04:10 +0200 Subject: [PATCH 03/23] Check for missing rustfmt in the stdarch intrinsic test step sooner --- src/bootstrap/src/core/build_steps/test.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index e308801b2548f..31b31ecb89c46 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -1102,6 +1102,14 @@ impl CommandLineStep for IntrinsicTest { builder.info(&format!("Skipping intrinsic-test, as it is not available for {host}")); return; } + // intrinsic-test shells out to `cargo` and `rustfmt` make bootstrap's + // managed binaries findable by prepending their dirs to PATH. + let Some(rustfmt_path) = builder.ensure(InternalRustfmt) else { + eprintln!( + "WARNING: intrinsic-test skipped because rustfmt is required but not available on this channel" + ); + return; + }; let (input_file, skip_file, cflags, sde_runner) = if host.contains("x86_64-unknown-linux") { let Some(sde) = &builder.config.sde else { @@ -1172,14 +1180,6 @@ impl CommandLineStep for IntrinsicTest { cmd.arg("--cc-arg-style").arg("gcc"); cmd.env("CC", builder.cc(host)); cmd.env("CFLAGS", cflags); - // intrinsic-test shells out to `cargo` and `rustfmt` make bootstrap's - // managed binaries findable by prepending their dirs to PATH. - let Some(rustfmt_path) = builder.ensure(InternalRustfmt) else { - eprintln!( - "WARNING: intrinsic-test skipped because rustfmt is required but not available on this channel" - ); - return; - }; let mut path_dirs: Vec = Vec::new(); if let Some(cargo_dir) = builder.initial_cargo.parent() { From 77f2a347fb2e723e0da871a64bf3da2ad6a9a240 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Tue, 19 May 2026 09:03:37 +0000 Subject: [PATCH 04/23] remove `box_patterns` feature --- compiler/rustc_ast/src/ast.rs | 6 +--- compiler/rustc_ast_lowering/src/pat.rs | 3 -- compiler/rustc_ast_passes/src/feature_gate.rs | 4 --- compiler/rustc_ast_pretty/src/pprust/state.rs | 4 --- compiler/rustc_feature/src/removed.rs | 2 ++ compiler/rustc_feature/src/unstable.rs | 2 -- compiler/rustc_lint/src/internal.rs | 3 -- compiler/rustc_lint/src/unused.rs | 4 +-- compiler/rustc_middle/src/thir.rs | 2 -- compiler/rustc_parse/src/diagnostics.rs | 7 ++++ compiler/rustc_parse/src/parser/pat.rs | 21 ++++++++---- compiler/rustc_passes/src/input_stats.rs | 1 - compiler/rustc_pattern_analysis/src/rustc.rs | 8 ----- .../src/language-features/box-patterns.md | 34 ------------------- .../src/language-features/deref-patterns.md | 5 ++- .../clippy_lints/src/unnested_or_patterns.rs | 11 ++---- .../clippy/clippy_utils/src/ast_utils/mod.rs | 1 - src/tools/rustfmt/src/patterns.rs | 10 +++--- tests/ui/README.md | 3 +- .../{box-patterns.rs => deref-patterns.rs} | 0 .../removed-syntax-box-patterns.rs | 9 +++++ .../removed-syntax-box-patterns.stderr | 14 ++++++++ 22 files changed, 58 insertions(+), 96 deletions(-) delete mode 100644 src/doc/unstable-book/src/language-features/box-patterns.md rename tests/ui/or-patterns/{box-patterns.rs => deref-patterns.rs} (100%) create mode 100644 tests/ui/parser/removed-syntax/removed-syntax-box-patterns.rs create mode 100644 tests/ui/parser/removed-syntax/removed-syntax-box-patterns.stderr 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_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index fb9fda0e94989..7089b08e77388 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); } 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_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..a09a8f833536e 100644 --- a/compiler/rustc_passes/src/input_stats.rs +++ b/compiler/rustc_passes/src/input_stats.rs @@ -635,7 +635,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/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_utils/src/ast_utils/mod.rs b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs index 03af2609d250a..e3660fa171968 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), 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/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/or-patterns/box-patterns.rs b/tests/ui/or-patterns/deref-patterns.rs similarity index 100% rename from tests/ui/or-patterns/box-patterns.rs rename to tests/ui/or-patterns/deref-patterns.rs diff --git a/tests/ui/parser/removed-syntax/removed-syntax-box-patterns.rs b/tests/ui/parser/removed-syntax/removed-syntax-box-patterns.rs new file mode 100644 index 0000000000000..273df70c140a6 --- /dev/null +++ b/tests/ui/parser/removed-syntax/removed-syntax-box-patterns.rs @@ -0,0 +1,9 @@ +fn main() { + 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_patterns` have 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..251ffc25795d7 --- /dev/null +++ b/tests/ui/parser/removed-syntax/removed-syntax-box-patterns.stderr @@ -0,0 +1,14 @@ +error: `box_patterns` have been removed + --> $DIR/removed-syntax-box-patterns.rs:2:9 + | +LL | let box x = Box::new('c'); + | ^^^^^ + +error: `box_patterns` have 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 + From 405d95bad4c4e394f92cae44df70e924171a71fc Mon Sep 17 00:00:00 2001 From: cyrgani Date: Mon, 18 May 2026 20:02:16 +0000 Subject: [PATCH 05/23] remove `box_patterns` from remaining tests --- tests/debuginfo/destructured-fn-argument.rs | 4 +- .../destructured-for-loop-variable.rs | 4 +- tests/debuginfo/destructured-local.rs | 4 +- tests/pretty/or-pattern-paren.pp | 4 +- tests/pretty/or-pattern-paren.rs | 4 +- tests/ui/binding/func-arg-ref-pattern.rs | 6 +- .../range-inclusive-pattern-precedence.rs | 9 --- ...patterns-slice-patterns-deref-patterns.rs} | 32 +++++----- ...erns-slice-patterns-deref-patterns.stderr} | 48 +++++++-------- .../borrowck-loan-in-overloaded-op.rs | 9 +-- .../borrowck-loan-in-overloaded-op.stderr | 2 +- .../borrowck-macro-interaction-issue-6304.rs | 4 +- .../borrowck/borrowck-vec-pattern-nesting.rs | 4 +- .../borrowck-vec-pattern-nesting.stderr | 4 +- ...T-struct-pattern-box-pattern-ice-121463.rs | 3 +- ...ruct-pattern-box-pattern-ice-121463.stderr | 8 +-- .../ui/box/box-patterns-feature-usage-6557.rs | 9 --- tests/ui/box/unit/unique-pat.rs | 14 ----- tests/ui/cfg/cfg-false-feature.rs | 7 ++- tests/ui/cfg/cfg-false-feature.stderr | 24 ++++---- .../box-pattern-trait-object-cannot-deref.rs | 19 ------ ...x-pattern-trait-object-cannot-deref.stderr | 9 --- .../ui/deref/deref-mut-closure-drop-order.rs | 6 +- .../feature-gate-box_patterns.rs | 9 --- .../feature-gate-box_patterns.stderr | 23 ------- .../feature-gate-deref_patterns.rs | 12 ++-- .../feature-gate-deref_patterns.stderr | 21 ++++--- .../soft-feature-gate-box_patterns.rs | 17 ------ .../soft-feature-gate-box_patterns.stderr | 26 -------- .../lifetimes/rvalue-lifetime-drop-timing.rs | 4 -- ...47390-unused-variable-in-struct-pattern.rs | 7 --- ...0-unused-variable-in-struct-pattern.stderr | 40 ++++++------- .../issue-54538-unused-parens-lint.fixed | 7 +-- .../unused/issue-54538-unused-parens-lint.rs | 7 +-- .../issue-54538-unused-parens-lint.stderr | 36 +++++------ tests/ui/macros/stringify.rs | 4 -- tests/ui/match/issue-42679.rs | 8 +-- tests/ui/moves/move-out-of-slice-1.rs | 4 +- tests/ui/moves/move-out-of-slice-1.stderr | 8 +-- .../moves/moves-based-on-type-block-bad.fixed | 8 +-- .../ui/moves/moves-based-on-type-block-bad.rs | 8 +-- .../moves-based-on-type-block-bad.stderr | 10 ++-- tests/ui/nll/issue-16223.rs | 4 +- tests/ui/or-patterns/deref-patterns.rs | 8 +-- .../or-patterns/or-patterns-syntactic-pass.rs | 3 - .../or-patterns-syntactic-pass.stderr | 14 ----- tests/ui/parser/mut-patterns.rs | 3 +- tests/ui/parser/mut-patterns.stderr | 36 +++++------ .../removed-syntax-box-patterns.rs | 2 +- .../removed-syntax-box-patterns.stderr | 4 +- .../borrowck-pat-at-and-box-pass.rs | 26 ++++---- .../borrowck-pat-at-and-box.rs | 30 +++++----- .../borrowck-pat-at-and-box.stderr | 60 +++++++++---------- .../{box-patterns.rs => deref-patterns.rs} | 8 +-- ...terns.rs => or-patterns-deref-patterns.rs} | 6 +- .../box-pattern-constructor-mismatch.rs | 11 ---- .../deref-pattern-box-constructor-mismatch.rs | 12 ++++ ...f-pattern-box-constructor-mismatch.stderr} | 6 +- ...tern-nested.rs => deref-pattern-nested.rs} | 6 +- ...atch.rs => deref-pattern-type-mismatch.rs} | 4 +- ...err => deref-pattern-type-mismatch.stderr} | 2 +- .../match-errors-derived-error-suppression.rs | 9 --- ...ch-errors-derived-error-suppression.stderr | 25 +++----- .../match-struct-var-having-boxed-field.rs | 17 +----- .../pattern/pattern-bad-ref-box-order.fixed | 14 ----- tests/ui/pattern/pattern-bad-ref-box-order.rs | 14 ----- .../pattern/pattern-bad-ref-box-order.stderr | 14 ----- .../pattern/rest-pat-semantic-disallowed.rs | 5 -- .../rest-pat-semantic-disallowed.stderr | 54 +++++++---------- tests/ui/pattern/rest-pat-syntactic.rs | 7 --- tests/ui/pattern/rest-pat-syntactic.stderr | 26 -------- tests/ui/pattern/usefulness/issue-12116.rs | 6 +- .../ui/pattern/usefulness/issue-12116.stderr | 8 +-- tests/ui/pattern/usefulness/issue-3601.rs | 8 +-- tests/ui/pattern/usefulness/issue-3601.stderr | 12 ++-- .../range-inclusive-pattern-precedence2.rs | 21 ------- ...range-inclusive-pattern-precedence2.stderr | 27 --------- tests/ui/reachable/unreachable-arm.rs | 4 +- tests/ui/reachable/unreachable-arm.stderr | 8 +-- tests/ui/regions/regions-dependent-addr-of.rs | 5 +- tests/ui/regions/regions-ref-in-fn-arg.rs | 7 +-- tests/ui/regions/regions-ref-in-fn-arg.stderr | 12 ++-- .../rfcs/rfc-2005-default-binding-mode/box.rs | 18 ------ tests/ui/traits/trait-object-destructure.rs | 8 +-- .../ui/traits/trait-object-destructure.stderr | 27 ++------- tests/ui/uninhabited/uninhabited-patterns.rs | 3 +- .../uninhabited/uninhabited-patterns.stderr | 8 +-- tests/ui/unpretty/exhaustive.expanded.stdout | 3 - tests/ui/unpretty/exhaustive.hir.stderr | 40 ++++++------- tests/ui/unpretty/exhaustive.hir.stdout | 14 ++--- tests/ui/unpretty/exhaustive.rs | 6 -- .../unsized-locals-using-unsized-fn-params.rs | 5 -- ...ized-locals-using-unsized-fn-params.stderr | 15 +---- 93 files changed, 383 insertions(+), 808 deletions(-) rename tests/ui/borrowck/{bindings-after-at-or-patterns-slice-patterns-box-patterns.rs => bindings-after-at-or-patterns-slice-patterns-deref-patterns.rs} (76%) rename tests/ui/borrowck/{bindings-after-at-or-patterns-slice-patterns-box-patterns.stderr => bindings-after-at-or-patterns-slice-patterns-deref-patterns.stderr} (76%) delete mode 100644 tests/ui/box/box-patterns-feature-usage-6557.rs delete mode 100644 tests/ui/box/unit/unique-pat.rs delete mode 100644 tests/ui/deref/box-pattern-trait-object-cannot-deref.rs delete mode 100644 tests/ui/deref/box-pattern-trait-object-cannot-deref.stderr delete mode 100644 tests/ui/feature-gates/feature-gate-box_patterns.rs delete mode 100644 tests/ui/feature-gates/feature-gate-box_patterns.stderr delete mode 100644 tests/ui/feature-gates/soft-feature-gate-box_patterns.rs delete mode 100644 tests/ui/feature-gates/soft-feature-gate-box_patterns.stderr delete mode 100644 tests/ui/or-patterns/or-patterns-syntactic-pass.stderr rename tests/ui/pattern/bindings-after-at/{box-patterns.rs => deref-patterns.rs} (78%) rename tests/ui/pattern/bindings-after-at/{or-patterns-box-patterns.rs => or-patterns-deref-patterns.rs} (82%) delete mode 100644 tests/ui/pattern/box-pattern-constructor-mismatch.rs create mode 100644 tests/ui/pattern/deref-pattern-box-constructor-mismatch.rs rename tests/ui/pattern/{box-pattern-constructor-mismatch.stderr => deref-pattern-box-constructor-mismatch.stderr} (53%) rename tests/ui/pattern/{box-pattern-nested.rs => deref-pattern-nested.rs} (69%) rename tests/ui/pattern/{box-pattern-type-mismatch.rs => deref-pattern-type-mismatch.rs} (81%) rename tests/ui/pattern/{box-pattern-type-mismatch.stderr => deref-pattern-type-mismatch.stderr} (93%) delete mode 100644 tests/ui/pattern/pattern-bad-ref-box-order.fixed delete mode 100644 tests/ui/pattern/pattern-bad-ref-box-order.rs delete mode 100644 tests/ui/pattern/pattern-bad-ref-box-order.stderr delete mode 100644 tests/ui/pattern/rest-pat-syntactic.stderr delete mode 100644 tests/ui/range/range-inclusive-pattern-precedence2.rs delete mode 100644 tests/ui/range/range-inclusive-pattern-precedence2.stderr delete mode 100644 tests/ui/rfcs/rfc-2005-default-binding-mode/box.rs 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/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.rs b/tests/ui/feature-gates/feature-gate-box_patterns.rs deleted file mode 100644 index 9ff6604c95206..0000000000000 --- a/tests/ui/feature-gates/feature-gate-box_patterns.rs +++ /dev/null @@ -1,9 +0,0 @@ -fn main() { - let box x = Box::new('c'); //~ ERROR box pattern syntax is experimental - let _: char = x; - - struct Packet { x: Box } - - let Packet { box x } = Packet { x: Box::new(0) }; //~ ERROR box pattern syntax is experimental - let _: i32 = 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/deref-patterns.rs b/tests/ui/or-patterns/deref-patterns.rs index 6a3d048f8a6cc..a4edb22fd80fc 100644 --- a/tests/ui/or-patterns/deref-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/parser/removed-syntax/removed-syntax-box-patterns.rs b/tests/ui/parser/removed-syntax/removed-syntax-box-patterns.rs index 273df70c140a6..872f050a04034 100644 --- a/tests/ui/parser/removed-syntax/removed-syntax-box-patterns.rs +++ b/tests/ui/parser/removed-syntax/removed-syntax-box-patterns.rs @@ -4,6 +4,6 @@ fn main() { struct Packet { x: Box } - let Packet { box x } = Packet { x: Box::new(0) }; //~ ERROR `box_patterns` have been removed + 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 index 251ffc25795d7..df35336ece5a9 100644 --- a/tests/ui/parser/removed-syntax/removed-syntax-box-patterns.stderr +++ b/tests/ui/parser/removed-syntax/removed-syntax-box-patterns.stderr @@ -1,10 +1,10 @@ -error: `box_patterns` have been removed +error: `box_patterns` has been removed --> $DIR/removed-syntax-box-patterns.rs:2:9 | LL | let box x = Box::new('c'); | ^^^^^ -error: `box_patterns` have been removed +error: `box_patterns` has been removed --> $DIR/removed-syntax-box-patterns.rs:7:18 | LL | let Packet { box x } = Packet { x: Box::new(0) }; 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`. From ca0cb94e9d58555738609d799a6af2cfbdcd0189 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Mon, 24 Aug 2026 09:21:24 +0000 Subject: [PATCH 06/23] clippy: replace `box_patterns` usage with `deref_patterns` --- .../clippy/clippy_utils/src/ast_utils/mod.rs | 56 +++++++++---------- src/tools/clippy/clippy_utils/src/lib.rs | 1 - .../clippy_utils/src/qualify_min_const_fn.rs | 10 ++-- 3 files changed, 33 insertions(+), 34 deletions(-) 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 e3660fa171968..944dedb775729 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs @@ -158,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, @@ -205,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, @@ -214,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, @@ -311,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, @@ -320,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, @@ -331,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, @@ -340,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, @@ -359,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, @@ -369,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, @@ -403,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, @@ -430,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, @@ -440,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, @@ -461,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, @@ -518,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, @@ -527,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, @@ -538,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, @@ -548,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, @@ -567,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, @@ -575,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, @@ -600,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, @@ -609,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, @@ -627,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, @@ -637,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, @@ -656,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, @@ -664,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/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 8b47c79aa6da2..8ee677866ee2b 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)] 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)?; From 0a78bac9928cdc20b1ecb2cace6e27b3c6e4e443 Mon Sep 17 00:00:00 2001 From: cyrgani Date: Mon, 24 Aug 2026 09:41:15 +0000 Subject: [PATCH 07/23] also remove `hir::PatKind::Box` --- compiler/rustc_hir/src/hir.rs | 10 ++---- compiler/rustc_hir/src/intravisit.rs | 4 +-- .../rustc_hir_analysis/src/check/region.rs | 4 +-- compiler/rustc_hir_pretty/src/lib.rs | 11 ------- .../rustc_hir_typeck/src/expr_use_visitor.rs | 5 ++- compiler/rustc_hir_typeck/src/pat.rs | 32 +------------------ compiler/rustc_lint/src/internal.rs | 1 - .../rustc_mir_build/src/thir/pattern/mod.rs | 7 +--- compiler/rustc_passes/src/input_stats.rs | 1 - src/librustdoc/clean/utils.rs | 2 +- .../clippy_lints/src/equatable_if_let.rs | 2 +- .../src/matches/match_same_arms.rs | 1 - .../clippy_lints/src/matches/single_match.rs | 1 - .../clippy/clippy_lints/src/utils/author.rs | 5 --- .../clippy_utils/src/check_proc_macro.rs | 4 --- .../clippy/clippy_utils/src/hir_utils.rs | 3 +- src/tools/clippy/clippy_utils/src/lib.rs | 2 +- 17 files changed, 12 insertions(+), 83 deletions(-) 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 7089b08e77388..9746b52dda41e 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -760,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_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_passes/src/input_stats.rs b/compiler/rustc_passes/src/input_stats.rs index a09a8f833536e..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, 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/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/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 8ee677866ee2b..464b5fcfeb04e 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -1489,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, From afcb367812e059f45c77196f039c96f03f684727 Mon Sep 17 00:00:00 2001 From: Max Dexheimer Date: Mon, 24 Aug 2026 12:21:01 +0200 Subject: [PATCH 08/23] Don't treat slashes as path seps after drive letters in verbatim paths --- library/std/src/sys/path/windows/tests.rs | 23 +++++++++++++++++++--- library/std/src/sys/path/windows_prefix.rs | 2 +- library/std/tests/path.rs | 10 +++++----- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/library/std/src/sys/path/windows/tests.rs b/library/std/src/sys/path/windows/tests.rs index 830f48d7bfc94..4ca47fc10c2e1 100644 --- a/library/std/src/sys/path/windows/tests.rs +++ b/library/std/src/sys/path/windows/tests.rs @@ -83,6 +83,9 @@ fn verbatim() { // Make sure opening a drive will work. check("Z:", "Z:"); + // Verbatim drive paths begin with `LETTER:\`. `/` is just a regular character here + check(r"\\?\C:/path\somewhere", r"\\?\C:/path\somewhere"); + // A path that contains null is not a valid path. assert!(maybe_verbatim(Path::new("\0")).is_err()); } @@ -93,9 +96,23 @@ fn parse_prefix(path: &str) -> Option> { #[test] fn test_parse_prefix_verbatim() { - let prefix = Some(Prefix::VerbatimDisk(b'C')); - assert_eq!(prefix, parse_prefix(r"\\?\C:/windows/system32/notepad.exe")); - assert_eq!(prefix, parse_prefix(r"\\?\C:\windows\system32\notepad.exe")); + assert_eq!( + parse_prefix(r"\\?\C:\windows\system32\notepad.exe"), + Some(Prefix::VerbatimDisk(b'C')), + ); +} + +#[test] +fn test_verbatim_disk_issue_161651() { + use crate::path::Path; + + // This is not a `VerbatimDisk` path, because `/` is not a separator in verbatim paths! + assert_eq!( + parse_prefix(r"\\?\C:/windows\system32"), + Some(Prefix::Verbatim(OsStr::new("C:/windows"))), + ); + + assert_ne!(Path::new(r"\\?\C:/foo"), Path::new(r"\\?\C:\foo")); } #[test] diff --git a/library/std/src/sys/path/windows_prefix.rs b/library/std/src/sys/path/windows_prefix.rs index b9dfe754485ab..5413269e9edee 100644 --- a/library/std/src/sys/path/windows_prefix.rs +++ b/library/std/src/sys/path/windows_prefix.rs @@ -142,7 +142,7 @@ fn parse_drive(path: &OsStr) -> Option { // Parses a drive prefix exactly, e.g. "C:" fn parse_drive_exact(path: &OsStr) -> Option { // only parse two bytes: the drive letter and the drive separator - if path.as_encoded_bytes().get(2).map(|&x| is_sep_byte(x)).unwrap_or(true) { + if path.as_encoded_bytes().get(2).map(|&x| is_verbatim_sep(x)).unwrap_or(true) { parse_drive(path) } else { None diff --git a/library/std/tests/path.rs b/library/std/tests/path.rs index 8997b8ad192dc..4d42437fbd871 100644 --- a/library/std/tests/path.rs +++ b/library/std/tests/path.rs @@ -989,14 +989,14 @@ pub fn test_decompositions_windows() { ); t!("\\\\?\\C:/foo/bar", - iter: ["\\\\?\\C:", "\\", "foo/bar"], + iter: ["\\\\?\\C:/foo/bar"], has_root: true, is_absolute: true, - parent: Some("\\\\?\\C:/"), - file_name: Some("foo/bar"), - file_stem: Some("foo/bar"), + parent: None, + file_name: None, + file_stem: None, extension: None, - file_prefix: Some("foo/bar") + file_prefix: None ); t!("\\\\.\\foo\\bar", From 7eaf48cc1fe89a38ab83ad2d427f25e9833dcd24 Mon Sep 17 00:00:00 2001 From: Jakob Koschel Date: Fri, 21 Aug 2026 14:29:22 +0000 Subject: [PATCH 09/23] Pass LargeDataThreshold to LLVM module IR Before, LargeDataThreshold was only set via `LLVMRustCreateTargetMachine`. When LTO is enabled, this information is required to be passed into the generated LLVM module IR files since the LTO linker spins up its own TargetMachine and otherwise has no knowledge of the LargeDataThreshold. Currently, `-Z large-data-threshold` has no affect at all when compiling with LTO. This commit makes sure that if `-Z large-data-threshold` is passed and not 0, it is preserved and stored into the generated LLVM IR. --- compiler/rustc_codegen_llvm/src/context.rs | 7 +++++++ compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 1 + compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp | 5 +++++ tests/codegen-llvm/large_data_threshold.rs | 9 +++++++++ 4 files changed, 22 insertions(+) create mode 100644 tests/codegen-llvm/large_data_threshold.rs diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 668072ff082ec..aabb4ce110d81 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -282,6 +282,13 @@ pub(crate) unsafe fn create_module<'ll>( llvm::LLVMRustSetModuleCodeModel(llmod, to_llvm_code_model(sess.code_model())); } + let large_data_threshold = sess.opts.unstable_opts.large_data_threshold.unwrap_or(0); + if large_data_threshold != 0 { + unsafe { + llvm::LLVMRustSetModuleLargeDataThreshold(llmod, large_data_threshold); + } + } + // If skipping the PLT is enabled, we need to add some module metadata // to ensure intrinsic calls don't use it. if !sess.needs_plt() { diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 1a60b59a93525..8c9bf55b14e45 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -2508,6 +2508,7 @@ unsafe extern "C" { pub(crate) fn LLVMRustSetModulePICLevel(M: &Module); pub(crate) fn LLVMRustSetModulePIELevel(M: &Module); pub(crate) fn LLVMRustSetModuleCodeModel(M: &Module, Model: CodeModel); + pub(crate) fn LLVMRustSetModuleLargeDataThreshold(M: &Module, Threshold: u64); pub(crate) fn LLVMRustBufferPtr(p: &Buffer) -> *const u8; pub(crate) fn LLVMRustBufferLen(p: &Buffer) -> usize; pub(crate) fn LLVMRustBufferFree(p: &'static mut Buffer); diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 3ad59c53a5bf3..b2e02a0889f12 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -1179,6 +1179,11 @@ extern "C" void LLVMRustSetModuleCodeModel(LLVMModuleRef M, unwrap(M)->setCodeModel(*CM); } +extern "C" void LLVMRustSetModuleLargeDataThreshold(LLVMModuleRef M, + uint64_t Threshold) { + unwrap(M)->setLargeDataThreshold(Threshold); +} + // Here you'll find an implementation of ThinLTO as used by the Rust compiler // right now. This ThinLTO support is only enabled on "recent ish" versions of // LLVM, and otherwise it's just blanket rejected from other compilers. diff --git a/tests/codegen-llvm/large_data_threshold.rs b/tests/codegen-llvm/large_data_threshold.rs new file mode 100644 index 0000000000000..a63a333985cca --- /dev/null +++ b/tests/codegen-llvm/large_data_threshold.rs @@ -0,0 +1,9 @@ +//@ only-x86_64 +//@ revisions: DEFAULT EXPLICIT +//@[DEFAULT] compile-flags: -C code-model=medium +//@[EXPLICIT] compile-flags: -C code-model=medium -Z large-data-threshold=1024 + +#![crate_type = "lib"] + +// DEFAULT-NOT: !"Large Data Threshold" +// EXPLICIT: !{{[0-9]+}} = !{i32 1, !"Large Data Threshold", i64 1024} From 97967dee57e5f5d09263bdfb816dca03dae0b10c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 20 Jul 2026 00:34:00 +0200 Subject: [PATCH 10/23] Add new `unescaped_pipe_in_table_cell` rustdoc lint --- src/librustdoc/lint.rs | 12 +++ src/librustdoc/passes/lint.rs | 5 + .../passes/lint/table_pipe_escape.rs | 99 +++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 src/librustdoc/passes/lint/table_pipe_escape.rs diff --git a/src/librustdoc/lint.rs b/src/librustdoc/lint.rs index 1c3d1c421b545..b0dd2108c5660 100644 --- a/src/librustdoc/lint.rs +++ b/src/librustdoc/lint.rs @@ -209,6 +209,17 @@ declare_rustdoc_lint! { "detects unused footnote definitions" } +declare_rustdoc_lint! { + /// This lint is **warn-by-default**. It detects unescaped pipes in table rows which + /// lead to some row cells being ignored. This is a `rustdoc` only lint, see the + /// documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#unescaped_pipe_in_table_cell + UNESCAPED_PIPE_IN_TABLE_CELL, + Warn, + "detects unescaped pipe in table rows in doc comments" +} + pub(crate) static RUSTDOC_LINTS: Lazy> = Lazy::new(|| { vec![ BROKEN_INTRA_DOC_LINKS, @@ -224,6 +235,7 @@ pub(crate) static RUSTDOC_LINTS: Lazy> = Lazy::new(|| { REDUNDANT_EXPLICIT_LINKS, BROKEN_FOOTNOTE, UNUSED_FOOTNOTE_DEFINITION, + UNESCAPED_PIPE_IN_TABLE_CELL, ] }); diff --git a/src/librustdoc/passes/lint.rs b/src/librustdoc/passes/lint.rs index bb952b32393cf..2093ff328413d 100644 --- a/src/librustdoc/passes/lint.rs +++ b/src/librustdoc/passes/lint.rs @@ -6,6 +6,7 @@ mod check_code_block_syntax; mod footnotes; mod html_tags; mod redundant_explicit_links; +mod table_pipe_escape; mod unescaped_backticks; use super::Pass; @@ -35,6 +36,7 @@ impl DocVisitor<'_> for Linter<'_, '_> { if !dox.is_empty() { let may_have_link = dox.contains(&[':', '['][..]); let may_have_block_comment_or_html = dox.contains(['<', '>']); + let may_have_table = dox.contains(&['|'][..]); // ~~~rust // // This is a real, supported commonmark syntax for block code // ~~~ @@ -51,6 +53,9 @@ impl DocVisitor<'_> for Linter<'_, '_> { if may_have_block_comment_or_html { html_tags::visit_item(self.cx, item, hir_id, &dox); } + if may_have_table { + table_pipe_escape::visit_item(self.cx, item, hir_id, &dox); + } } self.visit_item_recur(item) diff --git a/src/librustdoc/passes/lint/table_pipe_escape.rs b/src/librustdoc/passes/lint/table_pipe_escape.rs new file mode 100644 index 0000000000000..1ba19eabab1ac --- /dev/null +++ b/src/librustdoc/passes/lint/table_pipe_escape.rs @@ -0,0 +1,99 @@ +//! Detects table rows where some content seems to have been discarded because there are too many +//! pipe characters. + +use std::ops::Range; + +use rustc_hir::HirId; +use rustc_macros::Diagnostic; +use rustc_resolve::rustdoc::pulldown_cmark::{Event, Parser, Tag, TagEnd}; +use rustc_resolve::rustdoc::source_span_for_markdown_range; + +use crate::clean::*; +use crate::core::DocContext; +use crate::html::markdown::main_body_opts; + +#[derive(Diagnostic)] +#[diag("table row has too many columns")] +#[help("to escape `|` characters in tables, add a `\\` before them like `\\|`")] +struct UnescapedPipeInTableCell { + #[primary_span] + #[label("any content after this column divider is discarded")] + span: rustc_span::Span, +} + +pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item, hir_id: HirId, dox: &str) { + let mut p = Parser::new_ext(dox, main_body_opts()).into_offset_iter(); + + while let Some((event, _range)) = p.next() { + if let Event::Start(Tag::Table(_)) = event + && let Some((Event::Start(Tag::TableHead), _)) = p.next() + { + let mut expected_cells = 0; + while let Some((event, _)) = p.next() { + match event { + Event::End(TagEnd::TableCell) => expected_cells += 1, + Event::End(TagEnd::TableHead) => break, + _ => {} + } + } + let mut prev_range = None; + while let Some((event, range)) = p.next() { + match event { + Event::End(TagEnd::TableCell) => { + prev_range = Some(range); + } + Event::End(TagEnd::TableRow) => { + if let Some(prev_range) = &prev_range + // So here what is happening: when `pulldown-cmark` is parsing a table + // and a table row has too many cells, it doesn't emit events for the + // extra cells. So the only way for us to know these extra cells exist + // is to compare the row's span with the last emitted cell event's span. + // If the span ends don't match, then there are extra cells. + && prev_range.end + 1 != range.end + { + // Something seems wrong, the range diff doesn't match, some content + // was left out. We now check the number of unescaped `|`. + let row = &dox[range.clone()]; + let mut iter = row.chars(); + let mut divider_count = 0; + while let Some(c) = iter.next() { + if c == '\\' { + iter.next(); + } else if c == '|' { + divider_count += 1; + } + } + // + 1 is to handle the `|` at the end of the table row. + if divider_count <= expected_cells + 1 + || dox[Range { start: prev_range.end + 1, end: range.end }] + .trim() + .is_empty() + { + // Seems all good so let's ignore it and continue;. + continue; + } + let last_cell_separator = + Range { start: prev_range.end, end: prev_range.end + 1 }; + + if let Some((span, _)) = source_span_for_markdown_range( + cx.tcx, + dox, + &last_cell_separator, + &item.attrs.doc_strings, + ) { + cx.tcx.emit_node_span_lint( + crate::lint::UNESCAPED_PIPE_IN_TABLE_CELL, + hir_id, + span, + UnescapedPipeInTableCell { span }, + ); + } + } + } + Event::End(TagEnd::Table) => break, + _ => {} + } + } + } + } +} From dbe2c8ec57a3114974729ca4f98799c1aa85067b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 20 Jul 2026 00:34:41 +0200 Subject: [PATCH 11/23] Add ui regression test for new rustdoc `unescaped_pipe_in_table_cell` lint --- .../lints/unescaped_pipe_in_table_cell.rs | 38 +++++++++++++++++++ .../lints/unescaped_pipe_in_table_cell.stderr | 31 +++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 tests/rustdoc-ui/lints/unescaped_pipe_in_table_cell.rs create mode 100644 tests/rustdoc-ui/lints/unescaped_pipe_in_table_cell.stderr diff --git a/tests/rustdoc-ui/lints/unescaped_pipe_in_table_cell.rs b/tests/rustdoc-ui/lints/unescaped_pipe_in_table_cell.rs new file mode 100644 index 0000000000000..1a0918340c646 --- /dev/null +++ b/tests/rustdoc-ui/lints/unescaped_pipe_in_table_cell.rs @@ -0,0 +1,38 @@ +#![deny(rustdoc::unescaped_pipe_in_table_cell)] + +//! | col1 | +//! | ---- | +//! | `code_with(|arg| arg)` | +//~^ ERROR unescaped_pipe_in_table_cell +//! | one `|` b | +//~^ ERROR unescaped_pipe_in_table_cell +//! +// Testing another lint emission on the same doc comment. +//! +//! | col1 | +//! | ---- | +//! | `code_with(|arg| arg)` | +//~^ ERROR unescaped_pipe_in_table_cell + +// We check that the extra whitespace characters at the end of the line won't trigger +// the lint. +mod b { + //! | col | + //! | ---- | + #![doc = "| code_with | "] +} + +// We check that the `\|` is correctly handled as well (ie not emitting the lint). +mod c { + //! | col | + //! | ---- | + //! | a \| still same cell | +} + +// We check that content after a table row is ignored. +mod d { + //! | col | + //! | ---- | + //! | code_with | aaaaa + //^ the "aaaaa" part will be ignored. +} diff --git a/tests/rustdoc-ui/lints/unescaped_pipe_in_table_cell.stderr b/tests/rustdoc-ui/lints/unescaped_pipe_in_table_cell.stderr new file mode 100644 index 0000000000000..03a10c078cded --- /dev/null +++ b/tests/rustdoc-ui/lints/unescaped_pipe_in_table_cell.stderr @@ -0,0 +1,31 @@ +error: table row has too many columns + --> $DIR/unescaped_pipe_in_table_cell.rs:5:18 + | +LL | //! | `code_with(|arg| arg)` | + | ^ any content after this column divider is discarded + | + = help: to escape `|` characters in tables, add a `\` before them like `\|` +note: the lint level is defined here + --> $DIR/unescaped_pipe_in_table_cell.rs:1:9 + | +LL | #![deny(rustdoc::unescaped_pipe_in_table_cell)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: table row has too many columns + --> $DIR/unescaped_pipe_in_table_cell.rs:7:12 + | +LL | //! | one `|` b | + | ^ any content after this column divider is discarded + | + = help: to escape `|` characters in tables, add a `\` before them like `\|` + +error: table row has too many columns + --> $DIR/unescaped_pipe_in_table_cell.rs:14:18 + | +LL | //! | `code_with(|arg| arg)` | + | ^ any content after this column divider is discarded + | + = help: to escape `|` characters in tables, add a `\` before them like `\|` + +error: aborting due to 3 previous errors + From f74d66c50cb0aa55cf353c50071f83914038a599 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 20 Jul 2026 00:38:02 +0200 Subject: [PATCH 12/23] Add documentation for rustdoc `unescaped_pipe_in_table_cell` lint --- src/doc/rustdoc/src/lints.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/doc/rustdoc/src/lints.md b/src/doc/rustdoc/src/lints.md index 9dee33ef6eb85..8c284a339d210 100644 --- a/src/doc/rustdoc/src/lints.md +++ b/src/doc/rustdoc/src/lints.md @@ -456,3 +456,31 @@ note: the lint level is defined here | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: Remove explicit link instead ``` + +## `unescaped_pipe_in_table_cell` + +This lint is **warn-by-default**. It detects unescaped pipes (`|`) in table rows which +lead to some row cells being ignored. For example: + +```rust +//! | col1 | +//! | ---- | +//! | `code_with(|arg| arg)` | +``` + +Which will give: + +```text +error: table row has too many columns + --> $DIR/unescaped_pipe_in_table_cell.rs:5:18 + | +5 | //! | `code_with(|arg| arg)` | + | ^ help: any content after this column divider is discarded + | + = help: to escape `|` characters in tables, add a `\` before them like `\|` +note: the lint level is defined here + --> $DIR/unescaped_pipe_in_table_cell.rs:1:9 + | +1 | #![deny(rustdoc::unescaped_pipe_in_table_cell)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +``` From fe90bb22b85c7aadf332edf5cb46090750c855ea Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 24 Jul 2026 16:26:28 +0200 Subject: [PATCH 13/23] Rename lint `unescaped_pipe_in_table_cell` into `invalid_markdown_table` --- src/doc/rustdoc/src/lints.md | 8 ++++---- src/librustdoc/lint.rs | 6 +++--- src/librustdoc/passes/lint.rs | 4 ++-- ...able_pipe_escape.rs => invalid_markdown_table.rs} | 2 +- ...pe_in_table_cell.rs => invalid_markdown_table.rs} | 8 ++++---- ...ble_cell.stderr => invalid_markdown_table.stderr} | 12 ++++++------ 6 files changed, 20 insertions(+), 20 deletions(-) rename src/librustdoc/passes/lint/{table_pipe_escape.rs => invalid_markdown_table.rs} (98%) rename tests/rustdoc-ui/lints/{unescaped_pipe_in_table_cell.rs => invalid_markdown_table.rs} (80%) rename tests/rustdoc-ui/lints/{unescaped_pipe_in_table_cell.stderr => invalid_markdown_table.stderr} (72%) diff --git a/src/doc/rustdoc/src/lints.md b/src/doc/rustdoc/src/lints.md index 8c284a339d210..abd436bb5561c 100644 --- a/src/doc/rustdoc/src/lints.md +++ b/src/doc/rustdoc/src/lints.md @@ -457,7 +457,7 @@ note: the lint level is defined here = help: Remove explicit link instead ``` -## `unescaped_pipe_in_table_cell` +## `invalid_markdown_table` This lint is **warn-by-default**. It detects unescaped pipes (`|`) in table rows which lead to some row cells being ignored. For example: @@ -472,15 +472,15 @@ Which will give: ```text error: table row has too many columns - --> $DIR/unescaped_pipe_in_table_cell.rs:5:18 + --> $DIR/foo.rs:5:18 | 5 | //! | `code_with(|arg| arg)` | | ^ help: any content after this column divider is discarded | = help: to escape `|` characters in tables, add a `\` before them like `\|` note: the lint level is defined here - --> $DIR/unescaped_pipe_in_table_cell.rs:1:9 + --> $DIR/foo.rs:1:9 | -1 | #![deny(rustdoc::unescaped_pipe_in_table_cell)] +1 | #![deny(rustdoc::invalid_markdown_table)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` diff --git a/src/librustdoc/lint.rs b/src/librustdoc/lint.rs index b0dd2108c5660..5d8675aecb86a 100644 --- a/src/librustdoc/lint.rs +++ b/src/librustdoc/lint.rs @@ -214,8 +214,8 @@ declare_rustdoc_lint! { /// lead to some row cells being ignored. This is a `rustdoc` only lint, see the /// documentation in the [rustdoc book]. /// - /// [rustdoc book]: ../../../rustdoc/lints.html#unescaped_pipe_in_table_cell - UNESCAPED_PIPE_IN_TABLE_CELL, + /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_markdown_table + INVALID_MARKDOWN_TABLE, Warn, "detects unescaped pipe in table rows in doc comments" } @@ -235,7 +235,7 @@ pub(crate) static RUSTDOC_LINTS: Lazy> = Lazy::new(|| { REDUNDANT_EXPLICIT_LINKS, BROKEN_FOOTNOTE, UNUSED_FOOTNOTE_DEFINITION, - UNESCAPED_PIPE_IN_TABLE_CELL, + INVALID_MARKDOWN_TABLE, ] }); diff --git a/src/librustdoc/passes/lint.rs b/src/librustdoc/passes/lint.rs index 2093ff328413d..a417bbaab4ed5 100644 --- a/src/librustdoc/passes/lint.rs +++ b/src/librustdoc/passes/lint.rs @@ -5,8 +5,8 @@ mod bare_urls; mod check_code_block_syntax; mod footnotes; mod html_tags; +mod invalid_markdown_table; mod redundant_explicit_links; -mod table_pipe_escape; mod unescaped_backticks; use super::Pass; @@ -54,7 +54,7 @@ impl DocVisitor<'_> for Linter<'_, '_> { html_tags::visit_item(self.cx, item, hir_id, &dox); } if may_have_table { - table_pipe_escape::visit_item(self.cx, item, hir_id, &dox); + invalid_markdown_table::visit_item(self.cx, item, hir_id, &dox); } } diff --git a/src/librustdoc/passes/lint/table_pipe_escape.rs b/src/librustdoc/passes/lint/invalid_markdown_table.rs similarity index 98% rename from src/librustdoc/passes/lint/table_pipe_escape.rs rename to src/librustdoc/passes/lint/invalid_markdown_table.rs index 1ba19eabab1ac..929ff9b5f4ff2 100644 --- a/src/librustdoc/passes/lint/table_pipe_escape.rs +++ b/src/librustdoc/passes/lint/invalid_markdown_table.rs @@ -82,7 +82,7 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item, hir_id: HirId, dox: & &item.attrs.doc_strings, ) { cx.tcx.emit_node_span_lint( - crate::lint::UNESCAPED_PIPE_IN_TABLE_CELL, + crate::lint::INVALID_MARKDOWN_TABLE, hir_id, span, UnescapedPipeInTableCell { span }, diff --git a/tests/rustdoc-ui/lints/unescaped_pipe_in_table_cell.rs b/tests/rustdoc-ui/lints/invalid_markdown_table.rs similarity index 80% rename from tests/rustdoc-ui/lints/unescaped_pipe_in_table_cell.rs rename to tests/rustdoc-ui/lints/invalid_markdown_table.rs index 1a0918340c646..fe47213da3f31 100644 --- a/tests/rustdoc-ui/lints/unescaped_pipe_in_table_cell.rs +++ b/tests/rustdoc-ui/lints/invalid_markdown_table.rs @@ -1,18 +1,18 @@ -#![deny(rustdoc::unescaped_pipe_in_table_cell)] +#![deny(rustdoc::invalid_markdown_table)] //! | col1 | //! | ---- | //! | `code_with(|arg| arg)` | -//~^ ERROR unescaped_pipe_in_table_cell +//~^ ERROR invalid_markdown_table //! | one `|` b | -//~^ ERROR unescaped_pipe_in_table_cell +//~^ ERROR invalid_markdown_table //! // Testing another lint emission on the same doc comment. //! //! | col1 | //! | ---- | //! | `code_with(|arg| arg)` | -//~^ ERROR unescaped_pipe_in_table_cell +//~^ ERROR invalid_markdown_table // We check that the extra whitespace characters at the end of the line won't trigger // the lint. diff --git a/tests/rustdoc-ui/lints/unescaped_pipe_in_table_cell.stderr b/tests/rustdoc-ui/lints/invalid_markdown_table.stderr similarity index 72% rename from tests/rustdoc-ui/lints/unescaped_pipe_in_table_cell.stderr rename to tests/rustdoc-ui/lints/invalid_markdown_table.stderr index 03a10c078cded..b0974dfa51b5a 100644 --- a/tests/rustdoc-ui/lints/unescaped_pipe_in_table_cell.stderr +++ b/tests/rustdoc-ui/lints/invalid_markdown_table.stderr @@ -1,18 +1,18 @@ error: table row has too many columns - --> $DIR/unescaped_pipe_in_table_cell.rs:5:18 + --> $DIR/invalid_markdown_table.rs:5:18 | LL | //! | `code_with(|arg| arg)` | | ^ any content after this column divider is discarded | = help: to escape `|` characters in tables, add a `\` before them like `\|` note: the lint level is defined here - --> $DIR/unescaped_pipe_in_table_cell.rs:1:9 + --> $DIR/invalid_markdown_table.rs:1:9 | -LL | #![deny(rustdoc::unescaped_pipe_in_table_cell)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::invalid_markdown_table)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: table row has too many columns - --> $DIR/unescaped_pipe_in_table_cell.rs:7:12 + --> $DIR/invalid_markdown_table.rs:7:12 | LL | //! | one `|` b | | ^ any content after this column divider is discarded @@ -20,7 +20,7 @@ LL | //! | one `|` b | = help: to escape `|` characters in tables, add a `\` before them like `\|` error: table row has too many columns - --> $DIR/unescaped_pipe_in_table_cell.rs:14:18 + --> $DIR/invalid_markdown_table.rs:14:18 | LL | //! | `code_with(|arg| arg)` | | ^ any content after this column divider is discarded From 67bfe3ad49f017d6cdc9cc5522eefafe550a87de Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 24 Jul 2026 17:17:27 +0200 Subject: [PATCH 14/23] Also warn in case there is content after the last table cell --- .../passes/lint/invalid_markdown_table.rs | 82 +++++++++++++------ .../lints/invalid_markdown_table.rs | 19 ++++- .../lints/invalid_markdown_table.stderr | 14 +++- 3 files changed, 87 insertions(+), 28 deletions(-) diff --git a/src/librustdoc/passes/lint/invalid_markdown_table.rs b/src/librustdoc/passes/lint/invalid_markdown_table.rs index 929ff9b5f4ff2..cf04fbf82d723 100644 --- a/src/librustdoc/passes/lint/invalid_markdown_table.rs +++ b/src/librustdoc/passes/lint/invalid_markdown_table.rs @@ -14,13 +14,21 @@ use crate::html::markdown::main_body_opts; #[derive(Diagnostic)] #[diag("table row has too many columns")] -#[help("to escape `|` characters in tables, add a `\\` before them like `\\|`")] +#[help(r"to escape `|` characters in tables, add a `\` before them like `\|`")] struct UnescapedPipeInTableCell { #[primary_span] #[label("any content after this column divider is discarded")] span: rustc_span::Span, } +#[derive(Diagnostic)] +#[diag("unused content after last table cell")] +struct ContentAfterLastPipe { + #[primary_span] + #[label("this content is discarded")] + span: rustc_span::Span, +} + pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item, hir_id: HirId, dox: &str) { let mut p = Parser::new_ext(dox, main_body_opts()).into_offset_iter(); @@ -49,10 +57,17 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item, hir_id: HirId, dox: & // extra cells. So the only way for us to know these extra cells exist // is to compare the row's span with the last emitted cell event's span. // If the span ends don't match, then there are extra cells. - && prev_range.end + 1 != range.end + && prev_range.end + 1 < range.end { // Something seems wrong, the range diff doesn't match, some content - // was left out. We now check the number of unescaped `|`. + // was left out. + let mut after_last_cell_range = + Range { start: prev_range.end + 1, end: range.end }; + if dox[after_last_cell_range.clone()].trim().is_empty() { + // Seems all good so let's ignore it and continue;. + continue; + } + // We now check the number of unescaped `|`. let row = &dox[range.clone()]; let mut iter = row.chars(); let mut divider_count = 0; @@ -64,29 +79,46 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item, hir_id: HirId, dox: & } } // + 1 is to handle the `|` at the end of the table row. - if divider_count <= expected_cells + 1 - || dox[Range { start: prev_range.end + 1, end: range.end }] - .trim() - .is_empty() - { - // Seems all good so let's ignore it and continue;. - continue; - } - let last_cell_separator = - Range { start: prev_range.end, end: prev_range.end + 1 }; + let too_many_pipes = divider_count > expected_cells + 1; + + if too_many_pipes { + // Seems like a pipe was not escaped as it should have been. + let last_cell_separator = + Range { start: prev_range.end, end: prev_range.end + 1 }; - if let Some((span, _)) = source_span_for_markdown_range( - cx.tcx, - dox, - &last_cell_separator, - &item.attrs.doc_strings, - ) { - cx.tcx.emit_node_span_lint( - crate::lint::INVALID_MARKDOWN_TABLE, - hir_id, - span, - UnescapedPipeInTableCell { span }, - ); + if let Some((span, _)) = source_span_for_markdown_range( + cx.tcx, + dox, + &last_cell_separator, + &item.attrs.doc_strings, + ) { + cx.tcx.emit_node_span_lint( + crate::lint::INVALID_MARKDOWN_TABLE, + hir_id, + span, + UnescapedPipeInTableCell { span }, + ); + } + } else { + // An unclosed cell maybe? There is content after the last cell so + // let's lint about it. + let content = &dox[after_last_cell_range.clone()]; + after_last_cell_range.end -= + content.len() - content.trim_end().len(); + + if let Some((span, _)) = source_span_for_markdown_range( + cx.tcx, + dox, + &after_last_cell_range, + &item.attrs.doc_strings, + ) { + cx.tcx.emit_node_span_lint( + crate::lint::INVALID_MARKDOWN_TABLE, + hir_id, + span, + ContentAfterLastPipe { span }, + ); + } } } } diff --git a/tests/rustdoc-ui/lints/invalid_markdown_table.rs b/tests/rustdoc-ui/lints/invalid_markdown_table.rs index fe47213da3f31..8ba4da3b970a6 100644 --- a/tests/rustdoc-ui/lints/invalid_markdown_table.rs +++ b/tests/rustdoc-ui/lints/invalid_markdown_table.rs @@ -29,10 +29,25 @@ mod c { //! | a \| still same cell | } -// We check that content after a table row is ignored. +// We check that content after a table row also emits. mod d { //! | col | //! | ---- | //! | code_with | aaaaa - //^ the "aaaaa" part will be ignored. + //~^ ERROR invalid_markdown_table + //! blob + //! + //! one | two + //! -|- + //! a | b | c + //~^ ERROR invalid_markdown_table + //! a | +} + +// More cases that are ignored. +mod e { + //! | one | two | + //! |-|-| + //! | a | + //! | b } diff --git a/tests/rustdoc-ui/lints/invalid_markdown_table.stderr b/tests/rustdoc-ui/lints/invalid_markdown_table.stderr index b0974dfa51b5a..5f0b4e2416521 100644 --- a/tests/rustdoc-ui/lints/invalid_markdown_table.stderr +++ b/tests/rustdoc-ui/lints/invalid_markdown_table.stderr @@ -27,5 +27,17 @@ LL | //! | `code_with(|arg| arg)` | | = help: to escape `|` characters in tables, add a `\` before them like `\|` -error: aborting due to 3 previous errors +error: unused content after last table cell + --> $DIR/invalid_markdown_table.rs:36:22 + | +LL | //! | code_with | aaaaa + | ^^^^^^ this content is discarded + +error: unused content after last table cell + --> $DIR/invalid_markdown_table.rs:42:16 + | +LL | //! a | b | c + | ^^ this content is discarded + +error: aborting due to 5 previous errors From df734af6ae8a7fdc287c5da23fe610573bf2a761 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 24 Jul 2026 14:06:31 -0700 Subject: [PATCH 15/23] rustdoc: clean up some unneeded table lint code The essential problem is that, with this table: ```text one | ----| a | b | c a | b | a | b a | ``` And this logic: ```rust let too_many_pipes = divider_count > expected_cells + 1; ``` `expected_cells + 1` winds up as 2, so you get this warning: ```text error: unused content after last table cell --> $DIR/invalid_markdown_table.rs:81:14 | LL | //! a | b | c | ^^^^^^ this content is discarded error: unused content after last table cell --> $DIR/invalid_markdown_table.rs:83:14 | LL | //! a | b | | ^^^^ this content is discarded error: unused content after last table cell --> $DIR/invalid_markdown_table.rs:85:14 | LL | //! a | b | ^^ this content is discarded ``` We really want our warning to give the suggest-escaping flow, like this: ```text error: table row has too many columns --> $DIR/invalid_markdown_table.rs:81:13 | LL | //! a | b | c | ^ any content after this column divider is discarded | = help: to escape `|` characters in tables, add a `\` before them like `\|` error: table row has too many columns --> $DIR/invalid_markdown_table.rs:83:13 | LL | //! a | b | | ^ any content after this column divider is discarded | = help: to escape `|` characters in tables, add a `\` before them like `\|` error: unused content after last table cell --> $DIR/invalid_markdown_table.rs:85:14 | LL | //! a | b | ^^ this content is discarded ``` By only scanning the text between the end of the last cell and the row, instead of doing the entire row, we don't have to re-implement as much of pulldown-cmark's logic. --- .../passes/lint/invalid_markdown_table.rs | 33 ++++------ .../lints/invalid_markdown_table.rs | 50 +++++++++++++++ .../lints/invalid_markdown_table.stderr | 62 ++++++++++++++++++- 3 files changed, 120 insertions(+), 25 deletions(-) diff --git a/src/librustdoc/passes/lint/invalid_markdown_table.rs b/src/librustdoc/passes/lint/invalid_markdown_table.rs index cf04fbf82d723..dd44f2ec92445 100644 --- a/src/librustdoc/passes/lint/invalid_markdown_table.rs +++ b/src/librustdoc/passes/lint/invalid_markdown_table.rs @@ -33,17 +33,7 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item, hir_id: HirId, dox: & let mut p = Parser::new_ext(dox, main_body_opts()).into_offset_iter(); while let Some((event, _range)) = p.next() { - if let Event::Start(Tag::Table(_)) = event - && let Some((Event::Start(Tag::TableHead), _)) = p.next() - { - let mut expected_cells = 0; - while let Some((event, _)) = p.next() { - match event { - Event::End(TagEnd::TableCell) => expected_cells += 1, - Event::End(TagEnd::TableHead) => break, - _ => {} - } - } + if Event::Start(Tag::TableRow) == event { let mut prev_range = None; while let Some((event, range)) = p.next() { match event { @@ -67,21 +57,20 @@ pub(crate) fn visit_item(cx: &DocContext<'_>, item: &Item, hir_id: HirId, dox: & // Seems all good so let's ignore it and continue;. continue; } - // We now check the number of unescaped `|`. - let row = &dox[range.clone()]; - let mut iter = row.chars(); - let mut divider_count = 0; + // Check if any pipes appear after the end of the row. + let mut iter = dox[after_last_cell_range.clone()].bytes().peekable(); + let mut found_divider = false; while let Some(c) = iter.next() { - if c == '\\' { + // the sequence `\\|` still escapes the pipe because GFM + // processes block structures like tables in its own pass + if c == b'\\' && iter.peek() == Some(&b'|') { iter.next(); - } else if c == '|' { - divider_count += 1; + } else if c == b'|' { + found_divider = true; + break; } } - // + 1 is to handle the `|` at the end of the table row. - let too_many_pipes = divider_count > expected_cells + 1; - - if too_many_pipes { + if found_divider { // Seems like a pipe was not escaped as it should have been. let last_cell_separator = Range { start: prev_range.end, end: prev_range.end + 1 }; diff --git a/tests/rustdoc-ui/lints/invalid_markdown_table.rs b/tests/rustdoc-ui/lints/invalid_markdown_table.rs index 8ba4da3b970a6..d910af1266c19 100644 --- a/tests/rustdoc-ui/lints/invalid_markdown_table.rs +++ b/tests/rustdoc-ui/lints/invalid_markdown_table.rs @@ -27,6 +27,15 @@ mod c { //! | col | //! | ---- | //! | a \| still same cell | + //! + //! now with double-backslashes; + //! yes, it really does work this way, + //! but it's *weird* compared to what + //! you would naively expect + //! + //! | col | + //! | ---- | + //! | a \\| still same cell | } // We check that content after a table row also emits. @@ -37,6 +46,18 @@ mod d { //~^ ERROR invalid_markdown_table //! blob //! + //! | col | + //! | ---- | + //! | code_with | \| + //~^ ERROR invalid_markdown_table + //! blob + //! + //! | col | + //! | ---- | + //! | code_with | \\| + //~^ ERROR invalid_markdown_table + //! blob + //! //! one | two //! -|- //! a | b | c @@ -51,3 +72,32 @@ mod e { //! | a | //! | b } + +// Weird corner case where the table ends with a pipe, +// but doesn't start with it +mod f { + //! one | + //! ----| + //! a | b | c + //~^ ERROR invalid_markdown_table + //! a | b | + //~^ ERROR invalid_markdown_table + //! a | b + //~^ ERROR invalid_markdown_table + //! a | +} + +// Weird corner case where the table ends with a pipe, +// but doesn't start with it +mod g { + //! | one + //! |---- + //! | a | b | c + //~^ ERROR invalid_markdown_table + //! | a | b | + //~^ ERROR invalid_markdown_table + //! | a | b + //~^ ERROR invalid_markdown_table + //! | a | + //! | a +} diff --git a/tests/rustdoc-ui/lints/invalid_markdown_table.stderr b/tests/rustdoc-ui/lints/invalid_markdown_table.stderr index 5f0b4e2416521..87321c77dfdfc 100644 --- a/tests/rustdoc-ui/lints/invalid_markdown_table.stderr +++ b/tests/rustdoc-ui/lints/invalid_markdown_table.stderr @@ -28,16 +28,72 @@ LL | //! | `code_with(|arg| arg)` | = help: to escape `|` characters in tables, add a `\` before them like `\|` error: unused content after last table cell - --> $DIR/invalid_markdown_table.rs:36:22 + --> $DIR/invalid_markdown_table.rs:45:22 | LL | //! | code_with | aaaaa | ^^^^^^ this content is discarded error: unused content after last table cell - --> $DIR/invalid_markdown_table.rs:42:16 + --> $DIR/invalid_markdown_table.rs:51:22 + | +LL | //! | code_with | \| + | ^^^ this content is discarded + +error: unused content after last table cell + --> $DIR/invalid_markdown_table.rs:57:22 + | +LL | //! | code_with | \| + | ^^^^ this content is discarded + +error: unused content after last table cell + --> $DIR/invalid_markdown_table.rs:63:16 | LL | //! a | b | c | ^^ this content is discarded -error: aborting due to 5 previous errors +error: table row has too many columns + --> $DIR/invalid_markdown_table.rs:81:13 + | +LL | //! a | b | c + | ^ any content after this column divider is discarded + | + = help: to escape `|` characters in tables, add a `\` before them like `\|` + +error: table row has too many columns + --> $DIR/invalid_markdown_table.rs:83:13 + | +LL | //! a | b | + | ^ any content after this column divider is discarded + | + = help: to escape `|` characters in tables, add a `\` before them like `\|` + +error: unused content after last table cell + --> $DIR/invalid_markdown_table.rs:85:14 + | +LL | //! a | b + | ^^ this content is discarded + +error: table row has too many columns + --> $DIR/invalid_markdown_table.rs:95:14 + | +LL | //! | a | b | c + | ^ any content after this column divider is discarded + | + = help: to escape `|` characters in tables, add a `\` before them like `\|` + +error: table row has too many columns + --> $DIR/invalid_markdown_table.rs:97:14 + | +LL | //! | a | b | + | ^ any content after this column divider is discarded + | + = help: to escape `|` characters in tables, add a `\` before them like `\|` + +error: unused content after last table cell + --> $DIR/invalid_markdown_table.rs:99:15 + | +LL | //! | a | b + | ^^ this content is discarded + +error: aborting due to 13 previous errors From aeb0d4a35aba47b1645a89265a08871e50aeb0cd Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 24 Aug 2026 16:19:21 +0200 Subject: [PATCH 16/23] Update lint to new rustdoc table lint --- tests/rustdoc-ui/lints/invalid-html-tags.rs | 1 + .../rustdoc-ui/lints/invalid-html-tags.stderr | 62 +++++++++---------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/tests/rustdoc-ui/lints/invalid-html-tags.rs b/tests/rustdoc-ui/lints/invalid-html-tags.rs index d0aa97c9e4074..7a244e6cc58f5 100644 --- a/tests/rustdoc-ui/lints/invalid-html-tags.rs +++ b/tests/rustdoc-ui/lints/invalid-html-tags.rs @@ -1,5 +1,6 @@ #![deny(rustdoc::invalid_html_tags)] //~^ NOTE the lint level is defined here +#![allow(rustdoc::invalid_markdown_table)] //!

💩

//~^ ERROR unclosed HTML tag `p` diff --git a/tests/rustdoc-ui/lints/invalid-html-tags.stderr b/tests/rustdoc-ui/lints/invalid-html-tags.stderr index 15b88496b7557..d0830321536dd 100644 --- a/tests/rustdoc-ui/lints/invalid-html-tags.stderr +++ b/tests/rustdoc-ui/lints/invalid-html-tags.stderr @@ -1,5 +1,5 @@ error: unclosed HTML tag `p` - --> $DIR/invalid-html-tags.rs:4:5 + --> $DIR/invalid-html-tags.rs:5:5 | LL | //!

💩

| ^^^ @@ -11,115 +11,115 @@ LL | #![deny(rustdoc::invalid_html_tags)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unclosed HTML tag `p` - --> $DIR/invalid-html-tags.rs:4:9 + --> $DIR/invalid-html-tags.rs:5:9 | LL | //!

💩

| ^^^ error: unclosed HTML tag `unknown` - --> $DIR/invalid-html-tags.rs:12:5 + --> $DIR/invalid-html-tags.rs:13:5 | LL | /// | ^^^^^^^^^ error: unclosed HTML tag `script` - --> $DIR/invalid-html-tags.rs:15:5 + --> $DIR/invalid-html-tags.rs:16:5 | LL | ///