From 6859a17f0ee021fe6615df7fff2147a78421da0c Mon Sep 17 00:00:00 2001
From: Lukas Bergdoll <lukas.bergdoll@gmail.com>
Date: Sun, 23 Feb 2025 16:28:39 +0100
Subject: [PATCH 1/4] Stabilize assert_matches and move it to core::macros

Closes https://github.com/rust-lang/rust/issues/82775

This is a revive of https://github.com/rust-lang/rust/pull/120234, with the
suggested move from the public assert_matches module to macros. This
necessitates the rename of the internal macros modules to core_macros and
std_macros respectively.
---
 compiler/rustc_abi/src/extern_abi/tests.rs    |   2 +-
 compiler/rustc_abi/src/lib.rs                 |   1 -
 compiler/rustc_ast_lowering/src/expr.rs       |   2 +-
 compiler/rustc_ast_lowering/src/lib.rs        |   1 -
 .../src/diagnostics/explain_borrow.rs         |   2 +-
 compiler/rustc_borrowck/src/lib.rs            |   1 -
 .../src/type_check/input_output.rs            |   2 +-
 compiler/rustc_builtin_macros/src/lib.rs      |   1 -
 compiler/rustc_builtin_macros/src/test.rs     |   2 +-
 compiler/rustc_codegen_llvm/src/asm.rs        |   2 +-
 compiler/rustc_codegen_llvm/src/intrinsic.rs  |   2 +-
 compiler/rustc_codegen_llvm/src/lib.rs        |   1 -
 compiler/rustc_codegen_ssa/src/back/write.rs  |   2 +-
 compiler/rustc_codegen_ssa/src/lib.rs         |   1 -
 compiler/rustc_codegen_ssa/src/mir/rvalue.rs  |   2 +-
 .../rustc_codegen_ssa/src/traits/builder.rs   |   2 +-
 .../src/check_consts/check.rs                 |   2 +-
 .../rustc_const_eval/src/interpret/call.rs    |   2 +-
 .../rustc_const_eval/src/interpret/cast.rs    |   2 +-
 .../src/interpret/eval_context.rs             |   2 +-
 .../src/interpret/intrinsics.rs               |   2 +-
 .../rustc_const_eval/src/interpret/memory.rs  |   2 +-
 .../rustc_const_eval/src/interpret/operand.rs |   2 +-
 .../rustc_const_eval/src/interpret/place.rs   |   2 +-
 compiler/rustc_const_eval/src/lib.rs          |   1 -
 .../src/graph/scc/mod.rs                      |   2 +-
 compiler/rustc_data_structures/src/lib.rs     |   1 -
 compiler/rustc_errors/src/lib.rs              |   3 +-
 .../src/check/intrinsicck.rs                  |   2 +-
 .../src/coherence/builtin.rs                  |   2 +-
 .../src/collect/generics_of.rs                |   2 +-
 .../src/collect/predicates_of.rs              |   2 +-
 compiler/rustc_hir_analysis/src/delegation.rs |   2 +-
 .../src/hir_ty_lowering/mod.rs                |   2 +-
 .../rustc_hir_analysis/src/impl_wf_check.rs   |   2 +-
 compiler/rustc_hir_analysis/src/lib.rs        |   1 -
 .../rustc_infer/src/infer/outlives/verify.rs  |   2 +-
 compiler/rustc_infer/src/lib.rs               |   1 -
 .../rustc_lint/src/impl_trait_overcaptures.rs |   2 +-
 compiler/rustc_lint/src/lib.rs                |   1 -
 compiler/rustc_middle/src/lib.rs              |   1 -
 compiler/rustc_middle/src/ty/consts/kind.rs   |   2 +-
 compiler/rustc_middle/src/ty/context.rs       |   2 +-
 compiler/rustc_middle/src/ty/instance.rs      |   2 +-
 compiler/rustc_middle/src/ty/mod.rs           |   2 +-
 compiler/rustc_middle/src/ty/sty.rs           |   2 +-
 .../src/builder/coverageinfo.rs               |   2 +-
 .../src/builder/expr/as_place.rs              |   2 +-
 .../src/builder/matches/mod.rs                |   2 +-
 compiler/rustc_mir_build/src/lib.rs           |   1 -
 .../src/impls/initialized.rs                  |   2 +-
 compiler/rustc_mir_dataflow/src/lib.rs        |   1 -
 .../src/dataflow_const_prop.rs                |   2 +-
 compiler/rustc_mir_transform/src/lib.rs       |   1 -
 .../rustc_mir_transform/src/promote_consts.rs |   2 +-
 compiler/rustc_mir_transform/src/shim.rs      |   2 +-
 compiler/rustc_parse/src/lib.rs               |   1 -
 compiler/rustc_parse/src/parser/mod.rs        |   2 +-
 compiler/rustc_parse/src/parser/tests.rs      |   2 +-
 .../rustc_query_system/src/dep_graph/graph.rs |   2 +-
 compiler/rustc_query_system/src/lib.rs        |   1 -
 compiler/rustc_resolve/src/late.rs            |   2 +-
 compiler/rustc_resolve/src/lib.rs             |   1 -
 compiler/rustc_target/src/lib.rs              |   1 -
 .../src/error_reporting/traits/suggestions.rs |   2 +-
 compiler/rustc_trait_selection/src/lib.rs     |   1 -
 .../src/solve/inspect/analyse.rs              |   2 +-
 .../src/solve/normalize.rs                    |   2 +-
 .../rustc_trait_selection/src/traits/misc.rs  |   2 +-
 .../src/traits/select/mod.rs                  |   2 +-
 .../rustc_ty_utils/src/layout/invariant.rs    |   2 +-
 compiler/rustc_ty_utils/src/lib.rs            |   1 -
 .../alloc/src/collections/btree/map/tests.rs  |   2 +-
 library/alloc/src/lib.rs                      |   1 -
 library/alloc/tests/c_str2.rs                 |   2 +-
 library/alloc/tests/lib.rs                    |   1 -
 library/alloc/tests/str.rs                    |   2 +-
 library/alloc/tests/string.rs                 |   2 +-
 library/alloc/tests/vec.rs                    |   2 +-
 library/alloc/tests/vec_deque.rs              |   2 +-
 library/core/src/contracts.rs                 |   4 +-
 .../core/src/{macros => core_macros}/mod.rs   | 108 +++++++++---------
 .../core/src/{macros => core_macros}/panic.md |   0
 library/core/src/lib.rs                       |  16 +--
 library/core/src/prelude/v1.rs                |  12 +-
 library/std/src/collections/hash/map/tests.rs |   2 +-
 library/std/src/io/error/tests.rs             |   2 +-
 library/std/src/lib.rs                        |   7 +-
 library/std/src/{macros.rs => std_macros.rs}  |   2 +-
 .../std/src/sys/pal/unix/linux/pidfd/tests.rs |   2 +-
 .../src/sys/pal/unix/process/process_unix.rs  |   2 +-
 src/librustdoc/clean/utils.rs                 |   2 +-
 src/librustdoc/lib.rs                         |   1 -
 src/tools/clippy/clippy_utils/src/lib.rs      |   1 -
 src/tools/clippy/clippy_utils/src/ty/mod.rs   |   2 +-
 tests/ui-fulldeps/stable-mir/check_abi.rs     |   3 +-
 .../stable-mir/check_allocation.rs            |   3 +-
 .../stable-mir/check_crate_defs.rs            |   1 -
 tests/ui-fulldeps/stable-mir/check_def_ty.rs  |   1 -
 tests/ui-fulldeps/stable-mir/check_defs.rs    |   3 +-
 tests/ui-fulldeps/stable-mir/check_foreign.rs |   3 +-
 .../ui-fulldeps/stable-mir/check_instance.rs  |   1 -
 .../stable-mir/check_intrinsics.rs            |   3 +-
 .../ui-fulldeps/stable-mir/check_item_kind.rs |   1 -
 .../stable-mir/check_trait_queries.rs         |   1 -
 .../ui-fulldeps/stable-mir/check_transform.rs |   1 -
 tests/ui-fulldeps/stable-mir/check_ty_fold.rs |   1 -
 .../stable-mir/compilation-result.rs          |   1 -
 tests/ui-fulldeps/stable-mir/crate-info.rs    |   3 +-
 tests/ui-fulldeps/stable-mir/projections.rs   |   3 +-
 tests/ui-fulldeps/stable-mir/smir_internal.rs |   1 -
 tests/ui-fulldeps/stable-mir/smir_serde.rs    |   1 -
 tests/ui-fulldeps/stable-mir/smir_visitor.rs  |   1 -
 tests/ui-fulldeps/try-from-u32/values.rs      |   3 +-
 tests/ui/coroutine/uninhabited-field.rs       |   3 +-
 tests/ui/macros/assert-matches-macro-msg.rs   |   4 +-
 tests/ui/stdlib-unit-tests/matches2021.rs     |   4 +-
 117 files changed, 147 insertions(+), 200 deletions(-)
 rename library/core/src/{macros => core_macros}/mod.rs (99%)
 rename library/core/src/{macros => core_macros}/panic.md (100%)
 rename library/std/src/{macros.rs => std_macros.rs} (99%)

diff --git a/compiler/rustc_abi/src/extern_abi/tests.rs b/compiler/rustc_abi/src/extern_abi/tests.rs
index fc546a6570f0a..fcc56c0c8d7eb 100644
--- a/compiler/rustc_abi/src/extern_abi/tests.rs
+++ b/compiler/rustc_abi/src/extern_abi/tests.rs
@@ -1,4 +1,4 @@
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 use std::str::FromStr;
 
 use super::*;
diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs
index 81e4e255f3799..cb533e3c577b3 100644
--- a/compiler/rustc_abi/src/lib.rs
+++ b/compiler/rustc_abi/src/lib.rs
@@ -1,7 +1,6 @@
 // tidy-alphabetical-start
 #![cfg_attr(feature = "nightly", allow(internal_features))]
 #![cfg_attr(feature = "nightly", doc(rust_logo))]
-#![cfg_attr(feature = "nightly", feature(assert_matches))]
 #![cfg_attr(feature = "nightly", feature(rustc_attrs))]
 #![cfg_attr(feature = "nightly", feature(rustdoc_internals))]
 #![cfg_attr(feature = "nightly", feature(step_trait))]
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs
index af53c7ec21572..6ebef07ee8285 100644
--- a/compiler/rustc_ast_lowering/src/expr.rs
+++ b/compiler/rustc_ast_lowering/src/expr.rs
@@ -1,4 +1,4 @@
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 use std::ops::ControlFlow;
 use std::sync::Arc;
 
diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs
index b865cbedbbb78..323005154a6b1 100644
--- a/compiler/rustc_ast_lowering/src/lib.rs
+++ b/compiler/rustc_ast_lowering/src/lib.rs
@@ -33,7 +33,6 @@
 // tidy-alphabetical-start
 #![allow(internal_features)]
 #![doc(rust_logo)]
-#![feature(assert_matches)]
 #![feature(box_patterns)]
 #![feature(if_let_guard)]
 #![feature(let_chains)]
diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
index f77dda0d386aa..02bdaadccbdec 100644
--- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
@@ -3,7 +3,7 @@
 #![allow(rustc::diagnostic_outside_of_impl)]
 #![allow(rustc::untranslatable_diagnostic)]
 
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 
 use rustc_errors::{Applicability, Diag, EmissionGuarantee};
 use rustc_hir as hir;
diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs
index a98984a4b4c7a..00d142c1f46dc 100644
--- a/compiler/rustc_borrowck/src/lib.rs
+++ b/compiler/rustc_borrowck/src/lib.rs
@@ -3,7 +3,6 @@
 // tidy-alphabetical-start
 #![allow(internal_features)]
 #![doc(rust_logo)]
-#![feature(assert_matches)]
 #![feature(box_patterns)]
 #![feature(file_buffered)]
 #![feature(if_let_guard)]
diff --git a/compiler/rustc_borrowck/src/type_check/input_output.rs b/compiler/rustc_borrowck/src/type_check/input_output.rs
index f70b17e33624b..a6b99e4bba18d 100644
--- a/compiler/rustc_borrowck/src/type_check/input_output.rs
+++ b/compiler/rustc_borrowck/src/type_check/input_output.rs
@@ -7,7 +7,7 @@
 //! `RETURN_PLACE` the MIR arguments) are always fully normalized (and
 //! contain revealed `impl Trait` values).
 
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 
 use itertools::Itertools;
 use rustc_hir as hir;
diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs
index ca16583a45de7..101bcba519d41 100644
--- a/compiler/rustc_builtin_macros/src/lib.rs
+++ b/compiler/rustc_builtin_macros/src/lib.rs
@@ -7,7 +7,6 @@
 #![allow(rustc::untranslatable_diagnostic)]
 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
 #![doc(rust_logo)]
-#![feature(assert_matches)]
 #![feature(autodiff)]
 #![feature(box_patterns)]
 #![feature(decl_macro)]
diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs
index a05fff2dcd1c1..2bc0785d6aa32 100644
--- a/compiler/rustc_builtin_macros/src/test.rs
+++ b/compiler/rustc_builtin_macros/src/test.rs
@@ -1,8 +1,8 @@
 //! The expansion from a test function to the appropriate test struct for libtest
 //! Ideally, this code would be in libtest but for efficiency and error messages it lives here.
 
-use std::assert_matches::assert_matches;
 use std::iter;
+use std::macros::assert_matches;
 
 use rustc_ast::ptr::P;
 use rustc_ast::{self as ast, GenericParamKind, attr};
diff --git a/compiler/rustc_codegen_llvm/src/asm.rs b/compiler/rustc_codegen_llvm/src/asm.rs
index be5673eddf93e..16f082f9e12c4 100644
--- a/compiler/rustc_codegen_llvm/src/asm.rs
+++ b/compiler/rustc_codegen_llvm/src/asm.rs
@@ -1,4 +1,4 @@
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 
 use libc::{c_char, c_uint};
 use rustc_abi::{BackendRepr, Float, Integer, Primitive, Scalar};
diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs
index f68365f6c69bc..3d326b111df60 100644
--- a/compiler/rustc_codegen_llvm/src/intrinsic.rs
+++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs
@@ -1,5 +1,5 @@
-use std::assert_matches::assert_matches;
 use std::cmp::Ordering;
+use std::macros::assert_matches;
 
 use rustc_abi::{Align, BackendRepr, ExternAbi, Float, HasDataLayout, Primitive, Size};
 use rustc_codegen_ssa::base::{compare_simd_types, wants_msvc_seh, wants_wasm_eh};
diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs
index e9e1b644f183e..56934a84ca4c0 100644
--- a/compiler/rustc_codegen_llvm/src/lib.rs
+++ b/compiler/rustc_codegen_llvm/src/lib.rs
@@ -8,7 +8,6 @@
 #![allow(internal_features)]
 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
 #![doc(rust_logo)]
-#![feature(assert_matches)]
 #![feature(exact_size_is_empty)]
 #![feature(extern_types)]
 #![feature(file_buffered)]
diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs
index d2548deb8c7a4..433cf16700c8e 100644
--- a/compiler/rustc_codegen_ssa/src/back/write.rs
+++ b/compiler/rustc_codegen_ssa/src/back/write.rs
@@ -1,5 +1,5 @@
 use std::any::Any;
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 use std::marker::PhantomData;
 use std::path::{Path, PathBuf};
 use std::sync::Arc;
diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs
index 9d2ac219d592c..ec7afa1e6be5e 100644
--- a/compiler/rustc_codegen_ssa/src/lib.rs
+++ b/compiler/rustc_codegen_ssa/src/lib.rs
@@ -4,7 +4,6 @@
 #![allow(rustc::untranslatable_diagnostic)]
 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
 #![doc(rust_logo)]
-#![feature(assert_matches)]
 #![feature(box_patterns)]
 #![feature(debug_closure_helpers)]
 #![feature(file_buffered)]
diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs
index daa4fa90ed704..b726f8b3f84d0 100644
--- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs
@@ -1,4 +1,4 @@
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 
 use arrayvec::ArrayVec;
 use rustc_abi::{self as abi, FIRST_VARIANT, FieldIdx};
diff --git a/compiler/rustc_codegen_ssa/src/traits/builder.rs b/compiler/rustc_codegen_ssa/src/traits/builder.rs
index 2b00ba01946e5..3bc97c36c5bb9 100644
--- a/compiler/rustc_codegen_ssa/src/traits/builder.rs
+++ b/compiler/rustc_codegen_ssa/src/traits/builder.rs
@@ -1,4 +1,4 @@
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 use std::ops::Deref;
 
 use rustc_abi::{Align, Scalar, Size, WrappingRange};
diff --git a/compiler/rustc_const_eval/src/check_consts/check.rs b/compiler/rustc_const_eval/src/check_consts/check.rs
index 90002d3f10905..1be8f38d92350 100644
--- a/compiler/rustc_const_eval/src/check_consts/check.rs
+++ b/compiler/rustc_const_eval/src/check_consts/check.rs
@@ -1,7 +1,7 @@
 //! The `Visitor` responsible for actually checking a `mir::Body` for invalid operations.
 
-use std::assert_matches::assert_matches;
 use std::borrow::Cow;
+use std::macros::assert_matches;
 use std::mem;
 use std::num::NonZero;
 use std::ops::Deref;
diff --git a/compiler/rustc_const_eval/src/interpret/call.rs b/compiler/rustc_const_eval/src/interpret/call.rs
index 29f819cca1fb6..93e6ea4b593eb 100644
--- a/compiler/rustc_const_eval/src/interpret/call.rs
+++ b/compiler/rustc_const_eval/src/interpret/call.rs
@@ -1,7 +1,7 @@
 //! Manages calling a concrete function (with known MIR body) with argument passing,
 //! and returning the return value to the caller.
-use std::assert_matches::assert_matches;
 use std::borrow::Cow;
+use std::macros::assert_matches;
 
 use either::{Left, Right};
 use rustc_abi::{self as abi, ExternAbi, FieldIdx, Integer, VariantIdx};
diff --git a/compiler/rustc_const_eval/src/interpret/cast.rs b/compiler/rustc_const_eval/src/interpret/cast.rs
index 7b706334ed85e..e30710f657493 100644
--- a/compiler/rustc_const_eval/src/interpret/cast.rs
+++ b/compiler/rustc_const_eval/src/interpret/cast.rs
@@ -1,4 +1,4 @@
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 
 use rustc_abi::Integer;
 use rustc_apfloat::ieee::{Double, Half, Quad, Single};
diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs
index c1948e9f31f10..e76506325347e 100644
--- a/compiler/rustc_const_eval/src/interpret/eval_context.rs
+++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs
@@ -1,4 +1,4 @@
-use std::assert_matches::debug_assert_matches;
+use std::macros::debug_assert_matches;
 
 use either::{Left, Right};
 use rustc_abi::{Align, HasDataLayout, Size, TargetDataLayout};
diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs
index 4ca317e3a1e53..647abb1db4cb8 100644
--- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs
+++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs
@@ -2,7 +2,7 @@
 //! looking at their MIR. Intrinsics/functions supported here are shared by CTFE
 //! and miri.
 
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 
 use rustc_abi::Size;
 use rustc_apfloat::ieee::{Double, Half, Quad, Single};
diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs
index 4f4b6785844dc..3ea68c2484dea 100644
--- a/compiler/rustc_const_eval/src/interpret/memory.rs
+++ b/compiler/rustc_const_eval/src/interpret/memory.rs
@@ -6,9 +6,9 @@
 //! integer. It is crucial that these operations call `check_align` *before*
 //! short-circuiting the empty case!
 
-use std::assert_matches::assert_matches;
 use std::borrow::{Borrow, Cow};
 use std::collections::VecDeque;
+use std::macros::assert_matches;
 use std::{fmt, mem, ptr};
 
 use rustc_abi::{Align, HasDataLayout, Size};
diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs
index 36da9037e43d9..003798cb921d8 100644
--- a/compiler/rustc_const_eval/src/interpret/operand.rs
+++ b/compiler/rustc_const_eval/src/interpret/operand.rs
@@ -1,7 +1,7 @@
 //! Functions concerning immediate values and operands, and reading from operands.
 //! All high-level functions to read from memory work on operands as sources.
 
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 
 use either::{Either, Left, Right};
 use rustc_abi as abi;
diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs
index f5d3de7b1b270..dabc236539c55 100644
--- a/compiler/rustc_const_eval/src/interpret/place.rs
+++ b/compiler/rustc_const_eval/src/interpret/place.rs
@@ -2,7 +2,7 @@
 //! into a place.
 //! All high-level functions to write to memory work on places as destinations.
 
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 
 use either::{Either, Left, Right};
 use rustc_abi::{BackendRepr, HasDataLayout, Size};
diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs
index ed5489652fba6..ae0eca33e0df8 100644
--- a/compiler/rustc_const_eval/src/lib.rs
+++ b/compiler/rustc_const_eval/src/lib.rs
@@ -2,7 +2,6 @@
 #![allow(internal_features)]
 #![allow(rustc::diagnostic_outside_of_impl)]
 #![doc(rust_logo)]
-#![feature(assert_matches)]
 #![feature(box_patterns)]
 #![feature(decl_macro)]
 #![feature(if_let_guard)]
diff --git a/compiler/rustc_data_structures/src/graph/scc/mod.rs b/compiler/rustc_data_structures/src/graph/scc/mod.rs
index e7c4ea3daae45..8ae757c239a69 100644
--- a/compiler/rustc_data_structures/src/graph/scc/mod.rs
+++ b/compiler/rustc_data_structures/src/graph/scc/mod.rs
@@ -8,8 +8,8 @@
 //! Typical examples would include: minimum element in SCC, maximum element
 //! reachable from it, etc.
 
-use std::assert_matches::debug_assert_matches;
 use std::fmt::Debug;
+use std::macros::debug_assert_matches;
 use std::ops::Range;
 
 use rustc_index::{Idx, IndexSlice, IndexVec};
diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs
index 66d3834d85784..771f9a317163b 100644
--- a/compiler/rustc_data_structures/src/lib.rs
+++ b/compiler/rustc_data_structures/src/lib.rs
@@ -17,7 +17,6 @@
 #![feature(array_windows)]
 #![feature(ascii_char)]
 #![feature(ascii_char_variants)]
-#![feature(assert_matches)]
 #![feature(auto_traits)]
 #![feature(cfg_match)]
 #![feature(core_intrinsics)]
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs
index ceed0cd94fc91..42c2bf917b2e8 100644
--- a/compiler/rustc_errors/src/lib.rs
+++ b/compiler/rustc_errors/src/lib.rs
@@ -10,7 +10,6 @@
 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
 #![doc(rust_logo)]
 #![feature(array_windows)]
-#![feature(assert_matches)]
 #![feature(associated_type_defaults)]
 #![feature(box_into_inner)]
 #![feature(box_patterns)]
@@ -30,7 +29,6 @@
 
 extern crate self as rustc_errors;
 
-use std::assert_matches::assert_matches;
 use std::backtrace::{Backtrace, BacktraceStatus};
 use std::borrow::Cow;
 use std::cell::Cell;
@@ -38,6 +36,7 @@ use std::error::Report;
 use std::ffi::OsStr;
 use std::hash::Hash;
 use std::io::Write;
+use std::macros::assert_matches;
 use std::num::NonZero;
 use std::ops::DerefMut;
 use std::path::{Path, PathBuf};
diff --git a/compiler/rustc_hir_analysis/src/check/intrinsicck.rs b/compiler/rustc_hir_analysis/src/check/intrinsicck.rs
index e1727fc48a833..7fa1e1b6da2b8 100644
--- a/compiler/rustc_hir_analysis/src/check/intrinsicck.rs
+++ b/compiler/rustc_hir_analysis/src/check/intrinsicck.rs
@@ -1,4 +1,4 @@
-use std::assert_matches::debug_assert_matches;
+use std::macros::debug_assert_matches;
 
 use rustc_abi::FieldIdx;
 use rustc_ast::InlineAsmTemplatePiece;
diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs
index b46b805f0a9d2..1550f362d3c37 100644
--- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs
+++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs
@@ -1,8 +1,8 @@
 //! Check properties that are required by built-in traits and set
 //! up data structures required by type-checking/codegen.
 
-use std::assert_matches::assert_matches;
 use std::collections::BTreeMap;
+use std::macros::assert_matches;
 
 use rustc_data_structures::fx::FxHashSet;
 use rustc_errors::{ErrorGuaranteed, MultiSpan};
diff --git a/compiler/rustc_hir_analysis/src/collect/generics_of.rs b/compiler/rustc_hir_analysis/src/collect/generics_of.rs
index 2cdd9a3a9348a..7db7ef6bcb9ec 100644
--- a/compiler/rustc_hir_analysis/src/collect/generics_of.rs
+++ b/compiler/rustc_hir_analysis/src/collect/generics_of.rs
@@ -1,4 +1,4 @@
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 use std::ops::ControlFlow;
 
 use hir::intravisit::{self, Visitor};
diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs
index 5b511d270743b..5068c574959ba 100644
--- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs
+++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs
@@ -1,4 +1,4 @@
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 
 use hir::Node;
 use rustc_data_structures::fx::FxIndexSet;
diff --git a/compiler/rustc_hir_analysis/src/delegation.rs b/compiler/rustc_hir_analysis/src/delegation.rs
index 4dbdfa3d85a9b..2e7c316d275c2 100644
--- a/compiler/rustc_hir_analysis/src/delegation.rs
+++ b/compiler/rustc_hir_analysis/src/delegation.rs
@@ -2,7 +2,7 @@
 //!
 //! For more information about delegation design, see the tracking issue #118212.
 
-use std::assert_matches::debug_assert_matches;
+use std::macros::debug_assert_matches;
 
 use rustc_data_structures::fx::FxHashMap;
 use rustc_hir::def::DefKind;
diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
index 750770178eef9..a85e6f104fdff 100644
--- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
+++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
@@ -20,7 +20,7 @@ pub mod errors;
 pub mod generics;
 mod lint;
 
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 use std::slice;
 
 use rustc_ast::TraitObjectSyntax;
diff --git a/compiler/rustc_hir_analysis/src/impl_wf_check.rs b/compiler/rustc_hir_analysis/src/impl_wf_check.rs
index c30b39dfe7656..724c095fc6f8e 100644
--- a/compiler/rustc_hir_analysis/src/impl_wf_check.rs
+++ b/compiler/rustc_hir_analysis/src/impl_wf_check.rs
@@ -8,7 +8,7 @@
 //! specialization errors. These things can (and probably should) be
 //! fixed, but for the moment it's easier to do these checks early.
 
-use std::assert_matches::debug_assert_matches;
+use std::macros::debug_assert_matches;
 
 use min_specialization::check_min_specialization;
 use rustc_data_structures::fx::FxHashSet;
diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs
index bdfbd540e40a3..81dffc461ae54 100644
--- a/compiler/rustc_hir_analysis/src/lib.rs
+++ b/compiler/rustc_hir_analysis/src/lib.rs
@@ -61,7 +61,6 @@ This API is completely unstable and subject to change.
 #![allow(rustc::untranslatable_diagnostic)]
 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
 #![doc(rust_logo)]
-#![feature(assert_matches)]
 #![feature(coroutines)]
 #![feature(debug_closure_helpers)]
 #![feature(if_let_guard)]
diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs
index c14c288c6e4e6..9acd0ab56fa5b 100644
--- a/compiler/rustc_infer/src/infer/outlives/verify.rs
+++ b/compiler/rustc_infer/src/infer/outlives/verify.rs
@@ -1,4 +1,4 @@
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 
 use rustc_middle::ty::{self, OutlivesPredicate, Ty, TyCtxt};
 use rustc_type_ir::outlives::{Component, compute_alias_components_recursive};
diff --git a/compiler/rustc_infer/src/lib.rs b/compiler/rustc_infer/src/lib.rs
index a04b2bb2b08b5..7b84493cc833c 100644
--- a/compiler/rustc_infer/src/lib.rs
+++ b/compiler/rustc_infer/src/lib.rs
@@ -18,7 +18,6 @@
 #![allow(rustc::untranslatable_diagnostic)]
 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
 #![doc(rust_logo)]
-#![feature(assert_matches)]
 #![feature(extend_one)]
 #![feature(iterator_try_collect)]
 #![feature(let_chains)]
diff --git a/compiler/rustc_lint/src/impl_trait_overcaptures.rs b/compiler/rustc_lint/src/impl_trait_overcaptures.rs
index 0b3af7d6aba98..c12db976ff23e 100644
--- a/compiler/rustc_lint/src/impl_trait_overcaptures.rs
+++ b/compiler/rustc_lint/src/impl_trait_overcaptures.rs
@@ -1,5 +1,5 @@
-use std::assert_matches::debug_assert_matches;
 use std::cell::LazyCell;
+use std::macros::debug_assert_matches;
 
 use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
 use rustc_data_structures::unord::UnordSet;
diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs
index ded50d98db5e3..442efc94cb884 100644
--- a/compiler/rustc_lint/src/lib.rs
+++ b/compiler/rustc_lint/src/lib.rs
@@ -24,7 +24,6 @@
 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
 #![doc(rust_logo)]
 #![feature(array_windows)]
-#![feature(assert_matches)]
 #![feature(box_patterns)]
 #![feature(extract_if)]
 #![feature(if_let_guard)]
diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs
index 93a7227d65ee3..87403a1542bbc 100644
--- a/compiler/rustc_middle/src/lib.rs
+++ b/compiler/rustc_middle/src/lib.rs
@@ -33,7 +33,6 @@
 #![doc(rust_logo)]
 #![feature(allocator_api)]
 #![feature(array_windows)]
-#![feature(assert_matches)]
 #![feature(associated_type_defaults)]
 #![feature(box_as_ptr)]
 #![feature(box_patterns)]
diff --git a/compiler/rustc_middle/src/ty/consts/kind.rs b/compiler/rustc_middle/src/ty/consts/kind.rs
index b3436550e8e07..3ef5b5ca5ebf5 100644
--- a/compiler/rustc_middle/src/ty/consts/kind.rs
+++ b/compiler/rustc_middle/src/ty/consts/kind.rs
@@ -1,4 +1,4 @@
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 
 use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
 
diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs
index 238ba127e2ecf..56ba2e532f260 100644
--- a/compiler/rustc_middle/src/ty/context.rs
+++ b/compiler/rustc_middle/src/ty/context.rs
@@ -4,10 +4,10 @@
 
 pub mod tls;
 
-use std::assert_matches::{assert_matches, debug_assert_matches};
 use std::borrow::Borrow;
 use std::cmp::Ordering;
 use std::hash::{Hash, Hasher};
+use std::macros::{assert_matches, debug_assert_matches};
 use std::marker::PhantomData;
 use std::ops::{Bound, Deref};
 use std::sync::{Arc, OnceLock};
diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs
index e9c19331e4a0b..d582569708844 100644
--- a/compiler/rustc_middle/src/ty/instance.rs
+++ b/compiler/rustc_middle/src/ty/instance.rs
@@ -1,5 +1,5 @@
-use std::assert_matches::assert_matches;
 use std::fmt;
+use std::macros::assert_matches;
 use std::path::PathBuf;
 
 use rustc_data_structures::fx::FxHashMap;
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs
index 8ed5a118093f3..02b3d178538c4 100644
--- a/compiler/rustc_middle/src/ty/mod.rs
+++ b/compiler/rustc_middle/src/ty/mod.rs
@@ -11,9 +11,9 @@
 
 #![allow(rustc::usage_of_ty_tykind)]
 
-use std::assert_matches::assert_matches;
 use std::fmt::Debug;
 use std::hash::{Hash, Hasher};
+use std::macros::assert_matches;
 use std::marker::PhantomData;
 use std::num::NonZero;
 use std::ptr::NonNull;
diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs
index d5617adf26b40..095d6dccabe21 100644
--- a/compiler/rustc_middle/src/ty/sty.rs
+++ b/compiler/rustc_middle/src/ty/sty.rs
@@ -2,9 +2,9 @@
 
 #![allow(rustc::usage_of_ty_tykind)]
 
-use std::assert_matches::debug_assert_matches;
 use std::borrow::Cow;
 use std::iter;
+use std::macros::debug_assert_matches;
 use std::ops::{ControlFlow, Range};
 
 use hir::def::{CtorKind, DefKind};
diff --git a/compiler/rustc_mir_build/src/builder/coverageinfo.rs b/compiler/rustc_mir_build/src/builder/coverageinfo.rs
index a80bd4f3c8009..122e8af81db7b 100644
--- a/compiler/rustc_mir_build/src/builder/coverageinfo.rs
+++ b/compiler/rustc_mir_build/src/builder/coverageinfo.rs
@@ -1,5 +1,5 @@
-use std::assert_matches::assert_matches;
 use std::collections::hash_map::Entry;
+use std::macros::assert_matches;
 
 use rustc_data_structures::fx::FxHashMap;
 use rustc_middle::mir::coverage::{BlockMarkerId, BranchSpan, CoverageInfoHi, CoverageKind};
diff --git a/compiler/rustc_mir_build/src/builder/expr/as_place.rs b/compiler/rustc_mir_build/src/builder/expr/as_place.rs
index 581f45db6c483..c02fd42d41851 100644
--- a/compiler/rustc_mir_build/src/builder/expr/as_place.rs
+++ b/compiler/rustc_mir_build/src/builder/expr/as_place.rs
@@ -1,7 +1,7 @@
 //! See docs in build/expr/mod.rs
 
-use std::assert_matches::assert_matches;
 use std::iter;
+use std::macros::assert_matches;
 
 use rustc_abi::{FIRST_VARIANT, FieldIdx, VariantIdx};
 use rustc_hir::def_id::LocalDefId;
diff --git a/compiler/rustc_mir_build/src/builder/matches/mod.rs b/compiler/rustc_mir_build/src/builder/matches/mod.rs
index d05d5b151ff48..9c1b00d2de82b 100644
--- a/compiler/rustc_mir_build/src/builder/matches/mod.rs
+++ b/compiler/rustc_mir_build/src/builder/matches/mod.rs
@@ -30,8 +30,8 @@ mod simplify;
 mod test;
 mod util;
 
-use std::assert_matches::assert_matches;
 use std::borrow::Borrow;
+use std::macros::assert_matches;
 use std::mem;
 use std::sync::Arc;
 
diff --git a/compiler/rustc_mir_build/src/lib.rs b/compiler/rustc_mir_build/src/lib.rs
index fa5db32d9134c..4e104c770920d 100644
--- a/compiler/rustc_mir_build/src/lib.rs
+++ b/compiler/rustc_mir_build/src/lib.rs
@@ -3,7 +3,6 @@
 // tidy-alphabetical-start
 #![allow(rustc::diagnostic_outside_of_impl)]
 #![allow(rustc::untranslatable_diagnostic)]
-#![feature(assert_matches)]
 #![feature(box_patterns)]
 #![feature(if_let_guard)]
 #![feature(let_chains)]
diff --git a/compiler/rustc_mir_dataflow/src/impls/initialized.rs b/compiler/rustc_mir_dataflow/src/impls/initialized.rs
index f5ffc42d52ab0..b58bed15b34c2 100644
--- a/compiler/rustc_mir_dataflow/src/impls/initialized.rs
+++ b/compiler/rustc_mir_dataflow/src/impls/initialized.rs
@@ -1,4 +1,4 @@
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 
 use rustc_abi::VariantIdx;
 use rustc_index::Idx;
diff --git a/compiler/rustc_mir_dataflow/src/lib.rs b/compiler/rustc_mir_dataflow/src/lib.rs
index a8a56baa1ffc0..0f4626bebc22a 100644
--- a/compiler/rustc_mir_dataflow/src/lib.rs
+++ b/compiler/rustc_mir_dataflow/src/lib.rs
@@ -1,5 +1,4 @@
 // tidy-alphabetical-start
-#![feature(assert_matches)]
 #![feature(associated_type_defaults)]
 #![feature(box_patterns)]
 #![feature(exact_size_is_empty)]
diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs
index 90173da17f0fc..448d27cfa696a 100644
--- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs
+++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs
@@ -2,8 +2,8 @@
 //!
 //! Currently, this pass only propagates scalar values.
 
-use std::assert_matches::assert_matches;
 use std::fmt::Formatter;
+use std::macros::assert_matches;
 
 use rustc_abi::{BackendRepr, FIRST_VARIANT, FieldIdx, Size, VariantIdx};
 use rustc_const_eval::const_eval::{DummyMachine, throw_machine_stop_str};
diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs
index 04c9375b83176..1f80eb2ae83d3 100644
--- a/compiler/rustc_mir_transform/src/lib.rs
+++ b/compiler/rustc_mir_transform/src/lib.rs
@@ -1,6 +1,5 @@
 // tidy-alphabetical-start
 #![feature(array_windows)]
-#![feature(assert_matches)]
 #![feature(box_patterns)]
 #![feature(const_type_name)]
 #![feature(cow_is_borrowed)]
diff --git a/compiler/rustc_mir_transform/src/promote_consts.rs b/compiler/rustc_mir_transform/src/promote_consts.rs
index c8d8dc147e94f..2129869e3adab 100644
--- a/compiler/rustc_mir_transform/src/promote_consts.rs
+++ b/compiler/rustc_mir_transform/src/promote_consts.rs
@@ -10,8 +10,8 @@
 //! otherwise silence errors, if move analysis runs after promotion on broken
 //! MIR.
 
-use std::assert_matches::assert_matches;
 use std::cell::Cell;
+use std::macros::assert_matches;
 use std::{cmp, iter, mem};
 
 use either::{Left, Right};
diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs
index 34074a84e28b6..4e55ad16929d5 100644
--- a/compiler/rustc_mir_transform/src/shim.rs
+++ b/compiler/rustc_mir_transform/src/shim.rs
@@ -1,4 +1,4 @@
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 use std::{fmt, iter};
 
 use rustc_abi::{ExternAbi, FIRST_VARIANT, FieldIdx, VariantIdx};
diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs
index 1a104ff5e3375..6f1c35d495f2b 100644
--- a/compiler/rustc_parse/src/lib.rs
+++ b/compiler/rustc_parse/src/lib.rs
@@ -5,7 +5,6 @@
 #![allow(rustc::diagnostic_outside_of_impl)]
 #![allow(rustc::untranslatable_diagnostic)]
 #![feature(array_windows)]
-#![feature(assert_matches)]
 #![feature(box_patterns)]
 #![feature(debug_closure_helpers)]
 #![feature(if_let_guard)]
diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs
index 80a33a7600599..eded1314ab423 100644
--- a/compiler/rustc_parse/src/parser/mod.rs
+++ b/compiler/rustc_parse/src/parser/mod.rs
@@ -11,7 +11,7 @@ mod stmt;
 pub mod token_type;
 mod ty;
 
-use std::assert_matches::debug_assert_matches;
+use std::macros::debug_assert_matches;
 use std::ops::Range;
 use std::sync::Arc;
 use std::{fmt, mem, slice};
diff --git a/compiler/rustc_parse/src/parser/tests.rs b/compiler/rustc_parse/src/parser/tests.rs
index 8b8c81a77a01a..4818cdb9d2c34 100644
--- a/compiler/rustc_parse/src/parser/tests.rs
+++ b/compiler/rustc_parse/src/parser/tests.rs
@@ -1,8 +1,8 @@
 #![allow(rustc::symbol_intern_string_literal)]
 
-use std::assert_matches::assert_matches;
 use std::io::prelude::*;
 use std::iter::Peekable;
+use std::macros::assert_matches;
 use std::path::{Path, PathBuf};
 use std::sync::{Arc, Mutex};
 use std::{io, str};
diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs
index 5e6bee1dbd5a1..c23005d833d54 100644
--- a/compiler/rustc_query_system/src/dep_graph/graph.rs
+++ b/compiler/rustc_query_system/src/dep_graph/graph.rs
@@ -1,7 +1,7 @@
-use std::assert_matches::assert_matches;
 use std::collections::hash_map::Entry;
 use std::fmt::Debug;
 use std::hash::Hash;
+use std::macros::assert_matches;
 use std::marker::PhantomData;
 use std::sync::Arc;
 use std::sync::atomic::{AtomicU32, Ordering};
diff --git a/compiler/rustc_query_system/src/lib.rs b/compiler/rustc_query_system/src/lib.rs
index ee984095ad84b..3c93a421b0dc1 100644
--- a/compiler/rustc_query_system/src/lib.rs
+++ b/compiler/rustc_query_system/src/lib.rs
@@ -1,6 +1,5 @@
 // tidy-alphabetical-start
 #![allow(rustc::potential_query_instability, internal_features)]
-#![feature(assert_matches)]
 #![feature(core_intrinsics)]
 #![feature(dropck_eyepatch)]
 #![feature(hash_raw_entry)]
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs
index ad9c3465f0cc6..19543e94c2bfc 100644
--- a/compiler/rustc_resolve/src/late.rs
+++ b/compiler/rustc_resolve/src/late.rs
@@ -6,10 +6,10 @@
 //! If you wonder why there's no `early.rs`, that's because it's split into three files -
 //! `build_reduced_graph.rs`, `macros.rs` and `imports.rs`.
 
-use std::assert_matches::debug_assert_matches;
 use std::borrow::Cow;
 use std::collections::BTreeSet;
 use std::collections::hash_map::Entry;
+use std::macros::debug_assert_matches;
 use std::mem::{replace, swap, take};
 
 use rustc_ast::ptr::P;
diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs
index eb4ac6ce77c9c..4a39d17a4614a 100644
--- a/compiler/rustc_resolve/src/lib.rs
+++ b/compiler/rustc_resolve/src/lib.rs
@@ -13,7 +13,6 @@
 #![allow(rustc::untranslatable_diagnostic)]
 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
 #![doc(rust_logo)]
-#![feature(assert_matches)]
 #![feature(box_patterns)]
 #![feature(extract_if)]
 #![feature(if_let_guard)]
diff --git a/compiler/rustc_target/src/lib.rs b/compiler/rustc_target/src/lib.rs
index 7ebe96960ed0f..2b0a3276bb237 100644
--- a/compiler/rustc_target/src/lib.rs
+++ b/compiler/rustc_target/src/lib.rs
@@ -11,7 +11,6 @@
 #![allow(internal_features)]
 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
 #![doc(rust_logo)]
-#![feature(assert_matches)]
 #![feature(iter_intersperse)]
 #![feature(let_chains)]
 #![feature(rustc_attrs)]
diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
index c7e71a626dc51..8101cd545c3b3 100644
--- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
+++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
@@ -1,8 +1,8 @@
 // ignore-tidy-filelength
 
-use std::assert_matches::debug_assert_matches;
 use std::borrow::Cow;
 use std::iter;
+use std::macros::debug_assert_matches;
 
 use itertools::{EitherOrBoth, Itertools};
 use rustc_abi::ExternAbi;
diff --git a/compiler/rustc_trait_selection/src/lib.rs b/compiler/rustc_trait_selection/src/lib.rs
index 1af383e9200d0..4bda58f276f34 100644
--- a/compiler/rustc_trait_selection/src/lib.rs
+++ b/compiler/rustc_trait_selection/src/lib.rs
@@ -16,7 +16,6 @@
 #![allow(rustc::untranslatable_diagnostic)]
 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
 #![doc(rust_logo)]
-#![feature(assert_matches)]
 #![feature(associated_type_defaults)]
 #![feature(box_patterns)]
 #![feature(cfg_version)]
diff --git a/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs b/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs
index 4b1bc316d5f1d..ff5473e4a2247 100644
--- a/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs
+++ b/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs
@@ -9,7 +9,7 @@
 //! coherence right now and was annoying to implement, so I am leaving it
 //! as is until we start using it for something else.
 
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 
 use rustc_infer::infer::{DefineOpaqueTypes, InferCtxt, InferOk};
 use rustc_macros::extension;
diff --git a/compiler/rustc_trait_selection/src/solve/normalize.rs b/compiler/rustc_trait_selection/src/solve/normalize.rs
index 232357dc71a0d..78938a6295244 100644
--- a/compiler/rustc_trait_selection/src/solve/normalize.rs
+++ b/compiler/rustc_trait_selection/src/solve/normalize.rs
@@ -1,5 +1,5 @@
-use std::assert_matches::assert_matches;
 use std::fmt::Debug;
+use std::macros::assert_matches;
 use std::marker::PhantomData;
 
 use rustc_data_structures::stack::ensure_sufficient_stack;
diff --git a/compiler/rustc_trait_selection/src/traits/misc.rs b/compiler/rustc_trait_selection/src/traits/misc.rs
index a4b6f330b9d78..278758b3b7599 100644
--- a/compiler/rustc_trait_selection/src/traits/misc.rs
+++ b/compiler/rustc_trait_selection/src/traits/misc.rs
@@ -1,6 +1,6 @@
 //! Miscellaneous type-system utilities that are too small to deserve their own modules.
 
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 
 use hir::LangItem;
 use rustc_ast::Mutability;
diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs
index 436ce3dddd9f0..86fbf2d5ab303 100644
--- a/compiler/rustc_trait_selection/src/traits/select/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs
@@ -2,9 +2,9 @@
 //!
 //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/resolution.html#selection
 
-use std::assert_matches::assert_matches;
 use std::cell::{Cell, RefCell};
 use std::fmt::{self, Display};
+use std::macros::assert_matches;
 use std::ops::ControlFlow;
 use std::{cmp, iter};
 
diff --git a/compiler/rustc_ty_utils/src/layout/invariant.rs b/compiler/rustc_ty_utils/src/layout/invariant.rs
index c695e2887fd6f..8f53544520004 100644
--- a/compiler/rustc_ty_utils/src/layout/invariant.rs
+++ b/compiler/rustc_ty_utils/src/layout/invariant.rs
@@ -1,4 +1,4 @@
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 
 use rustc_abi::{BackendRepr, FieldsShape, Scalar, Size, TagEncoding, Variants};
 use rustc_middle::bug;
diff --git a/compiler/rustc_ty_utils/src/lib.rs b/compiler/rustc_ty_utils/src/lib.rs
index 8be1611bb9ac2..b352179a44562 100644
--- a/compiler/rustc_ty_utils/src/lib.rs
+++ b/compiler/rustc_ty_utils/src/lib.rs
@@ -8,7 +8,6 @@
 #![allow(internal_features)]
 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
 #![doc(rust_logo)]
-#![feature(assert_matches)]
 #![feature(associated_type_defaults)]
 #![feature(box_patterns)]
 #![feature(if_let_guard)]
diff --git a/library/alloc/src/collections/btree/map/tests.rs b/library/alloc/src/collections/btree/map/tests.rs
index 5975134382e7d..2db2176b97607 100644
--- a/library/alloc/src/collections/btree/map/tests.rs
+++ b/library/alloc/src/collections/btree/map/tests.rs
@@ -1,4 +1,4 @@
-use core::assert_matches::assert_matches;
+use core::macros::assert_matches;
 use std::iter;
 use std::ops::Bound::{Excluded, Included, Unbounded};
 use std::panic::{AssertUnwindSafe, catch_unwind};
diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs
index 2e9dd98571537..ee9f8c52ececd 100644
--- a/library/alloc/src/lib.rs
+++ b/library/alloc/src/lib.rs
@@ -99,7 +99,6 @@
 #![feature(array_into_iter_constructors)]
 #![feature(array_windows)]
 #![feature(ascii_char)]
-#![feature(assert_matches)]
 #![feature(async_fn_traits)]
 #![feature(async_iterator)]
 #![feature(box_uninit_write)]
diff --git a/library/alloc/tests/c_str2.rs b/library/alloc/tests/c_str2.rs
index 0f4c27fa12322..71a59725bd65a 100644
--- a/library/alloc/tests/c_str2.rs
+++ b/library/alloc/tests/c_str2.rs
@@ -1,11 +1,11 @@
 use alloc::ffi::CString;
 use alloc::rc::Rc;
 use alloc::sync::Arc;
-use core::assert_matches::assert_matches;
 use core::ffi::{CStr, FromBytesUntilNulError, c_char};
 #[allow(deprecated)]
 use core::hash::SipHasher13 as DefaultHasher;
 use core::hash::{Hash, Hasher};
+use core::macros::assert_matches;
 
 #[test]
 fn c_to_rust() {
diff --git a/library/alloc/tests/lib.rs b/library/alloc/tests/lib.rs
index f95be6a6df0b3..e8f02462d6735 100644
--- a/library/alloc/tests/lib.rs
+++ b/library/alloc/tests/lib.rs
@@ -1,7 +1,6 @@
 #![feature(allocator_api)]
 #![feature(alloc_layout_extra)]
 #![feature(iter_array_chunks)]
-#![feature(assert_matches)]
 #![feature(btree_extract_if)]
 #![feature(char_max_len)]
 #![feature(cow_is_borrowed)]
diff --git a/library/alloc/tests/str.rs b/library/alloc/tests/str.rs
index 906fa2d425e77..c7f89d11866d1 100644
--- a/library/alloc/tests/str.rs
+++ b/library/alloc/tests/str.rs
@@ -1,9 +1,9 @@
 #![allow(invalid_from_utf8)]
 
-use std::assert_matches::assert_matches;
 use std::borrow::Cow;
 use std::char::MAX_LEN_UTF8;
 use std::cmp::Ordering::{Equal, Greater, Less};
+use std::macros::assert_matches;
 use std::str::{from_utf8, from_utf8_unchecked};
 
 #[test]
diff --git a/library/alloc/tests/string.rs b/library/alloc/tests/string.rs
index d996c55f94660..54e3848022510 100644
--- a/library/alloc/tests/string.rs
+++ b/library/alloc/tests/string.rs
@@ -1,7 +1,7 @@
-use std::assert_matches::assert_matches;
 use std::borrow::Cow;
 use std::cell::Cell;
 use std::collections::TryReserveErrorKind::*;
+use std::macros::assert_matches;
 use std::ops::Bound::*;
 use std::ops::{Bound, RangeBounds};
 use std::{panic, str};
diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs
index fe1db56414e0c..901ec333ec815 100644
--- a/library/alloc/tests/vec.rs
+++ b/library/alloc/tests/vec.rs
@@ -6,12 +6,12 @@ use core::num::NonZero;
 use core::ptr::NonNull;
 use core::{assert_eq, assert_ne};
 use std::alloc::System;
-use std::assert_matches::assert_matches;
 use std::borrow::Cow;
 use std::cell::Cell;
 use std::collections::TryReserveErrorKind::*;
 use std::fmt::Debug;
 use std::iter::InPlaceIterable;
+use std::macros::assert_matches;
 use std::mem::{size_of, swap};
 use std::ops::Bound::*;
 use std::panic::{AssertUnwindSafe, catch_unwind};
diff --git a/library/alloc/tests/vec_deque.rs b/library/alloc/tests/vec_deque.rs
index 1b03c29e5bda1..1fe76d7353775 100644
--- a/library/alloc/tests/vec_deque.rs
+++ b/library/alloc/tests/vec_deque.rs
@@ -2,11 +2,11 @@
 #![allow(static_mut_refs)]
 
 use core::num::NonZero;
-use std::assert_matches::assert_matches;
 use std::collections::TryReserveErrorKind::*;
 use std::collections::VecDeque;
 use std::collections::vec_deque::Drain;
 use std::fmt::Debug;
+use std::macros::assert_matches;
 use std::ops::Bound::*;
 use std::panic::{AssertUnwindSafe, catch_unwind};
 
diff --git a/library/core/src/contracts.rs b/library/core/src/contracts.rs
index 8b79a3a7eba86..802cecaffdac1 100644
--- a/library/core/src/contracts.rs
+++ b/library/core/src/contracts.rs
@@ -1,6 +1,8 @@
 //! Unstable module containing the unstable contracts lang items and attribute macros.
 
-pub use crate::macros::builtin::{contracts_ensures as ensures, contracts_requires as requires};
+pub use crate::core_macros::builtin::{
+    contracts_ensures as ensures, contracts_requires as requires,
+};
 
 /// Emitted by rustc as a desugaring of `#[ensures(PRED)] fn foo() -> R { ... [return R;] ... }`
 /// into: `fn foo() { let _check = build_check_ensures(|ret| PRED) ... [return _check(R);] ... }`
diff --git a/library/core/src/macros/mod.rs b/library/core/src/core_macros/mod.rs
similarity index 99%
rename from library/core/src/macros/mod.rs
rename to library/core/src/core_macros/mod.rs
index 16200184422b9..e115fa8c69076 100644
--- a/library/core/src/macros/mod.rs
+++ b/library/core/src/core_macros/mod.rs
@@ -138,7 +138,7 @@ macro_rules! assert_ne {
 /// be disabled. See [`debug_assert_matches!`] for assertions that are disabled in
 /// release builds by default.
 ///
-/// [`debug_assert_matches!`]: crate::assert_matches::debug_assert_matches
+/// [`debug_assert_matches!`]: crate::macros::debug_assert_matches
 ///
 /// On panic, this macro will print the value of the expression with its debug representation.
 ///
@@ -147,9 +147,7 @@ macro_rules! assert_ne {
 /// # Examples
 ///
 /// ```
-/// #![feature(assert_matches)]
-///
-/// use std::assert_matches::assert_matches;
+/// use std::macros::assert_matches;
 ///
 /// let a = Some(345);
 /// let b = Some(56);
@@ -166,7 +164,7 @@ macro_rules! assert_ne {
 /// assert_matches!(a, Some(x) if x > 100);
 /// // assert_matches!(a, Some(x) if x < 100); // panics
 /// ```
-#[unstable(feature = "assert_matches", issue = "82775")]
+#[stable(feature = "assert_matches", since = "CURRENT_RUSTC_VERSION")]
 #[allow_internal_unstable(panic_internals)]
 #[rustc_macro_transparency = "semitransparent"]
 pub macro assert_matches {
@@ -196,6 +194,55 @@ pub macro assert_matches {
     },
 }
 
+/// Asserts that an expression matches the provided pattern.
+///
+/// This macro is generally preferable to `debug_assert!(matches!(value, pattern))`, because it can
+/// print the debug representation of the actual value shape that did not meet expectations. In
+/// contrast, using [`debug_assert!`] will only print that expectations were not met, but not why.
+///
+/// The pattern syntax is exactly the same as found in a match arm and the `matches!` macro. The
+/// optional if guard can be used to add additional checks that must be true for the matched value,
+/// otherwise this macro will panic.
+///
+/// On panic, this macro will print the value of the expression with its debug representation.
+///
+/// Like [`assert!`], this macro has a second form, where a custom panic message can be provided.
+///
+/// Unlike [`assert_matches!`], `debug_assert_matches!` statements are only enabled in non optimized
+/// builds by default. An optimized build will not execute `debug_assert_matches!` statements unless
+/// `-C debug-assertions` is passed to the compiler. This makes `debug_assert_matches!` useful for
+/// checks that are too expensive to be present in a release build but may be helpful during
+/// development. The result of expanding `debug_assert_matches!` is always type checked.
+///
+/// # Examples
+///
+/// ```
+/// use std::macros::debug_assert_matches;
+///
+/// let a = Some(345);
+/// let b = Some(56);
+/// debug_assert_matches!(a, Some(_));
+/// debug_assert_matches!(b, Some(_));
+///
+/// debug_assert_matches!(a, Some(345));
+/// debug_assert_matches!(a, Some(345) | None);
+///
+/// // debug_assert_matches!(a, None); // panics
+/// // debug_assert_matches!(b, Some(345)); // panics
+/// // debug_assert_matches!(b, Some(345) | None); // panics
+///
+/// debug_assert_matches!(a, Some(x) if x > 100);
+/// // debug_assert_matches!(a, Some(x) if x < 100); // panics
+/// ```
+#[stable(feature = "assert_matches", since = "CURRENT_RUSTC_VERSION")]
+#[allow_internal_unstable(assert_matches)]
+#[rustc_macro_transparency = "semitransparent"]
+pub macro debug_assert_matches($($arg:tt)*) {
+    if $crate::cfg!(debug_assertions) {
+        $crate::macros::assert_matches!($($arg)*);
+    }
+}
+
 /// A macro for defining `#[cfg]` match-like statements.
 ///
 /// It is similar to the `if/elif` C preprocessor macro by allowing definition of a cascade of
@@ -370,57 +417,6 @@ macro_rules! debug_assert_ne {
     };
 }
 
-/// Asserts that an expression matches the provided pattern.
-///
-/// This macro is generally preferable to `debug_assert!(matches!(value, pattern))`, because it can
-/// print the debug representation of the actual value shape that did not meet expectations. In
-/// contrast, using [`debug_assert!`] will only print that expectations were not met, but not why.
-///
-/// The pattern syntax is exactly the same as found in a match arm and the `matches!` macro. The
-/// optional if guard can be used to add additional checks that must be true for the matched value,
-/// otherwise this macro will panic.
-///
-/// On panic, this macro will print the value of the expression with its debug representation.
-///
-/// Like [`assert!`], this macro has a second form, where a custom panic message can be provided.
-///
-/// Unlike [`assert_matches!`], `debug_assert_matches!` statements are only enabled in non optimized
-/// builds by default. An optimized build will not execute `debug_assert_matches!` statements unless
-/// `-C debug-assertions` is passed to the compiler. This makes `debug_assert_matches!` useful for
-/// checks that are too expensive to be present in a release build but may be helpful during
-/// development. The result of expanding `debug_assert_matches!` is always type checked.
-///
-/// # Examples
-///
-/// ```
-/// #![feature(assert_matches)]
-///
-/// use std::assert_matches::debug_assert_matches;
-///
-/// let a = Some(345);
-/// let b = Some(56);
-/// debug_assert_matches!(a, Some(_));
-/// debug_assert_matches!(b, Some(_));
-///
-/// debug_assert_matches!(a, Some(345));
-/// debug_assert_matches!(a, Some(345) | None);
-///
-/// // debug_assert_matches!(a, None); // panics
-/// // debug_assert_matches!(b, Some(345)); // panics
-/// // debug_assert_matches!(b, Some(345) | None); // panics
-///
-/// debug_assert_matches!(a, Some(x) if x > 100);
-/// // debug_assert_matches!(a, Some(x) if x < 100); // panics
-/// ```
-#[unstable(feature = "assert_matches", issue = "82775")]
-#[allow_internal_unstable(assert_matches)]
-#[rustc_macro_transparency = "semitransparent"]
-pub macro debug_assert_matches($($arg:tt)*) {
-    if $crate::cfg!(debug_assertions) {
-        $crate::assert_matches::assert_matches!($($arg)*);
-    }
-}
-
 /// Returns whether the given expression matches the provided pattern.
 ///
 /// The pattern syntax is exactly the same as found in a match arm. The optional if guard can be
diff --git a/library/core/src/macros/panic.md b/library/core/src/core_macros/panic.md
similarity index 100%
rename from library/core/src/macros/panic.md
rename to library/core/src/core_macros/panic.md
diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs
index db68f472c42f6..8e0d7805c0f51 100644
--- a/library/core/src/lib.rs
+++ b/library/core/src/lib.rs
@@ -227,16 +227,16 @@ use prelude::rust_2021::*;
 
 #[cfg(not(test))] // See #65860
 #[macro_use]
-mod macros;
+mod core_macros;
 
 // We don't export this through #[macro_export] for now, to avoid breakage.
 // See https://github.com/rust-lang/rust/issues/82913
 #[cfg(not(test))]
-#[unstable(feature = "assert_matches", issue = "82775")]
-/// Unstable module containing the unstable `assert_matches` macro.
-pub mod assert_matches {
-    #[unstable(feature = "assert_matches", issue = "82775")]
-    pub use crate::macros::{assert_matches, debug_assert_matches};
+#[stable(feature = "assert_matches", since = "CURRENT_RUSTC_VERSION")]
+/// Module that contains macros that can't be part of the prelude for compatibility reasons.
+pub mod macros {
+    #[stable(feature = "assert_matches", since = "CURRENT_RUSTC_VERSION")]
+    pub use crate::core_macros::{assert_matches, debug_assert_matches};
 }
 
 // We don't export this through #[macro_export] for now, to avoid breakage.
@@ -244,14 +244,14 @@ pub mod assert_matches {
 /// Unstable module containing the unstable `autodiff` macro.
 pub mod autodiff {
     #[unstable(feature = "autodiff", issue = "124509")]
-    pub use crate::macros::builtin::autodiff;
+    pub use crate::core_macros::builtin::autodiff;
 }
 
 #[unstable(feature = "contracts", issue = "128044")]
 pub mod contracts;
 
 #[unstable(feature = "cfg_match", issue = "115585")]
-pub use crate::macros::cfg_match;
+pub use crate::core_macros::cfg_match;
 
 #[macro_use]
 mod internal_macros;
diff --git a/library/core/src/prelude/v1.rs b/library/core/src/prelude/v1.rs
index 50fd67e839557..5435c65348dd1 100644
--- a/library/core/src/prelude/v1.rs
+++ b/library/core/src/prelude/v1.rs
@@ -77,37 +77,37 @@ pub use crate::concat_bytes;
 // Do not `doc(no_inline)` so that they become doc items on their own
 // (no public module for them to be re-exported from).
 #[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
-pub use crate::macros::builtin::{
+pub use crate::core_macros::builtin::{
     alloc_error_handler, bench, derive, global_allocator, test, test_case,
 };
 
 #[unstable(feature = "derive_const", issue = "none")]
-pub use crate::macros::builtin::derive_const;
+pub use crate::core_macros::builtin::derive_const;
 
 #[unstable(
     feature = "cfg_accessible",
     issue = "64797",
     reason = "`cfg_accessible` is not fully implemented"
 )]
-pub use crate::macros::builtin::cfg_accessible;
+pub use crate::core_macros::builtin::cfg_accessible;
 
 #[unstable(
     feature = "cfg_eval",
     issue = "82679",
     reason = "`cfg_eval` is a recently implemented feature"
 )]
-pub use crate::macros::builtin::cfg_eval;
+pub use crate::core_macros::builtin::cfg_eval;
 
 #[unstable(
     feature = "type_ascription",
     issue = "23416",
     reason = "placeholder syntax for type ascription"
 )]
-pub use crate::macros::builtin::type_ascribe;
+pub use crate::core_macros::builtin::type_ascribe;
 
 #[unstable(
     feature = "deref_patterns",
     issue = "87121",
     reason = "placeholder syntax for deref patterns"
 )]
-pub use crate::macros::builtin::deref;
+pub use crate::core_macros::builtin::deref;
diff --git a/library/std/src/collections/hash/map/tests.rs b/library/std/src/collections/hash/map/tests.rs
index a275488a55602..3cb6fc5e6a2f5 100644
--- a/library/std/src/collections/hash/map/tests.rs
+++ b/library/std/src/collections/hash/map/tests.rs
@@ -3,9 +3,9 @@ use realstd::collections::TryReserveErrorKind::*;
 
 use super::Entry::{Occupied, Vacant};
 use super::HashMap;
-use crate::assert_matches::assert_matches;
 use crate::cell::RefCell;
 use crate::hash::{BuildHasher, BuildHasherDefault, DefaultHasher, RandomState};
+use crate::macros::assert_matches;
 use crate::test_helpers::test_rng;
 
 // https://github.com/rust-lang/rust/issues/62301
diff --git a/library/std/src/io/error/tests.rs b/library/std/src/io/error/tests.rs
index edac6563478cd..56b2e07b94cd1 100644
--- a/library/std/src/io/error/tests.rs
+++ b/library/std/src/io/error/tests.rs
@@ -1,5 +1,5 @@
 use super::{Custom, Error, ErrorData, ErrorKind, Repr, SimpleMessage, const_error};
-use crate::assert_matches::assert_matches;
+use crate::macros::assert_matches;
 use crate::mem::size_of;
 use crate::sys::decode_error_kind;
 use crate::sys::os::error_string;
diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs
index 938b8c6e4f41b..d171b7db47bc1 100644
--- a/library/std/src/lib.rs
+++ b/library/std/src/lib.rs
@@ -396,7 +396,6 @@
 //
 // Only for re-exporting:
 // tidy-alphabetical-start
-#![feature(assert_matches)]
 #![feature(async_iterator)]
 #![feature(c_variadic)]
 #![feature(cfg_accessible)]
@@ -468,7 +467,7 @@ extern crate std as realstd;
 
 // The standard macros that are not built-in to the compiler.
 #[macro_use]
-mod macros;
+mod std_macros;
 
 // The runtime entry point and a few unstable public functions used by the
 // compiler
@@ -705,8 +704,8 @@ pub use core::primitive;
 #[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
 #[allow(deprecated)]
 pub use core::{
-    assert, assert_matches, cfg, column, compile_error, concat, concat_idents, const_format_args,
-    env, file, format_args, format_args_nl, include, include_bytes, include_str, line, log_syntax,
+    assert, cfg, column, compile_error, concat, concat_idents, const_format_args, env, file,
+    format_args, format_args_nl, include, include_bytes, include_str, line, log_syntax, macros,
     module_path, option_env, stringify, trace_macros,
 };
 // Re-export macros defined in core.
diff --git a/library/std/src/macros.rs b/library/std/src/std_macros.rs
similarity index 99%
rename from library/std/src/macros.rs
rename to library/std/src/std_macros.rs
index e0f9f0bb5cee4..d467b12e562f0 100644
--- a/library/std/src/macros.rs
+++ b/library/std/src/std_macros.rs
@@ -5,7 +5,7 @@
 //! library.
 // ignore-tidy-dbg
 
-#[doc = include_str!("../../core/src/macros/panic.md")]
+#[doc = include_str!("../../core/src/core_macros/panic.md")]
 #[macro_export]
 #[rustc_builtin_macro(std_panic)]
 #[stable(feature = "rust1", since = "1.0.0")]
diff --git a/library/std/src/sys/pal/unix/linux/pidfd/tests.rs b/library/std/src/sys/pal/unix/linux/pidfd/tests.rs
index 17b06bea91278..89146d37c160b 100644
--- a/library/std/src/sys/pal/unix/linux/pidfd/tests.rs
+++ b/library/std/src/sys/pal/unix/linux/pidfd/tests.rs
@@ -1,4 +1,4 @@
-use crate::assert_matches::assert_matches;
+use crate::macros::assert_matches;
 use crate::os::fd::{AsRawFd, RawFd};
 use crate::os::linux::process::{ChildExt, CommandExt as _};
 use crate::os::unix::process::{CommandExt as _, ExitStatusExt};
diff --git a/library/std/src/sys/pal/unix/process/process_unix.rs b/library/std/src/sys/pal/unix/process/process_unix.rs
index aa7406dd54874..f26f49864d70a 100644
--- a/library/std/src/sys/pal/unix/process/process_unix.rs
+++ b/library/std/src/sys/pal/unix/process/process_unix.rs
@@ -509,7 +509,7 @@ impl Command {
                             return Ok(None);
                         }
                     }
-                    core::assert_matches::debug_assert_matches!(support, SPAWN | NO);
+                    core::macros::debug_assert_matches!(support, SPAWN | NO);
                 }
             } else {
                 if self.get_create_pidfd() {
diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs
index 34656b26ce28c..89e94e75b9cfc 100644
--- a/src/librustdoc/clean/utils.rs
+++ b/src/librustdoc/clean/utils.rs
@@ -1,5 +1,5 @@
-use std::assert_matches::debug_assert_matches;
 use std::fmt::{self, Display, Write as _};
+use std::macros::debug_assert_matches;
 use std::mem;
 use std::sync::LazyLock as Lazy;
 
diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs
index 1f2f8f7d33a4a..3c15a4b6bf782 100644
--- a/src/librustdoc/lib.rs
+++ b/src/librustdoc/lib.rs
@@ -3,7 +3,6 @@
     html_playground_url = "https://play.rust-lang.org/"
 )]
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 #![feature(box_patterns)]
 #![feature(debug_closure_helpers)]
 #![feature(file_buffered)]
diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs
index 40ddd75b7fad1..60851e218e591 100644
--- a/src/tools/clippy/clippy_utils/src/lib.rs
+++ b/src/tools/clippy/clippy_utils/src/lib.rs
@@ -7,7 +7,6 @@
 #![feature(let_chains)]
 #![feature(never_type)]
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 #![feature(unwrap_infallible)]
 #![feature(array_windows)]
 #![recursion_limit = "512"]
diff --git a/src/tools/clippy/clippy_utils/src/ty/mod.rs b/src/tools/clippy/clippy_utils/src/ty/mod.rs
index 8eef6a7f57edb..569893241613f 100644
--- a/src/tools/clippy/clippy_utils/src/ty/mod.rs
+++ b/src/tools/clippy/clippy_utils/src/ty/mod.rs
@@ -27,7 +27,7 @@ use rustc_span::{DUMMY_SP, Span, Symbol, sym};
 use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
 use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt;
 use rustc_trait_selection::traits::{Obligation, ObligationCause};
-use std::assert_matches::debug_assert_matches;
+use std::macros::debug_assert_matches;
 use std::collections::hash_map::Entry;
 use std::iter;
 
diff --git a/tests/ui-fulldeps/stable-mir/check_abi.rs b/tests/ui-fulldeps/stable-mir/check_abi.rs
index ef2d5b4854bef..97d6ac4f177be 100644
--- a/tests/ui-fulldeps/stable-mir/check_abi.rs
+++ b/tests/ui-fulldeps/stable-mir/check_abi.rs
@@ -6,7 +6,6 @@
 //@ ignore-remote
 
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 #![feature(ascii_char, ascii_char_variants)]
 
 extern crate rustc_hir;
@@ -25,7 +24,7 @@ use stable_mir::abi::{
 use stable_mir::mir::mono::Instance;
 use stable_mir::target::MachineInfo;
 use stable_mir::{CrateDef, CrateItem, CrateItems, ItemKind};
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 use std::convert::TryFrom;
 use std::io::Write;
 use std::ops::ControlFlow;
diff --git a/tests/ui-fulldeps/stable-mir/check_allocation.rs b/tests/ui-fulldeps/stable-mir/check_allocation.rs
index c102f86a2286b..869e2d36f82b5 100644
--- a/tests/ui-fulldeps/stable-mir/check_allocation.rs
+++ b/tests/ui-fulldeps/stable-mir/check_allocation.rs
@@ -8,7 +8,6 @@
 //@ edition: 2021
 
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 #![feature(ascii_char, ascii_char_variants)]
 
 extern crate rustc_hir;
@@ -27,7 +26,7 @@ use stable_mir::mir::{Body, TerminatorKind};
 use stable_mir::ty::{Allocation, ConstantKind, RigidTy, TyKind};
 use stable_mir::{CrateItem, CrateItems, ItemKind};
 use std::ascii::Char;
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 use std::cmp::{max, min};
 use std::collections::HashMap;
 use std::ffi::CStr;
diff --git a/tests/ui-fulldeps/stable-mir/check_crate_defs.rs b/tests/ui-fulldeps/stable-mir/check_crate_defs.rs
index 71cca94c34f62..8800c10a0ff27 100644
--- a/tests/ui-fulldeps/stable-mir/check_crate_defs.rs
+++ b/tests/ui-fulldeps/stable-mir/check_crate_defs.rs
@@ -6,7 +6,6 @@
 //@ ignore-remote
 
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 
 extern crate rustc_hir;
 extern crate rustc_middle;
diff --git a/tests/ui-fulldeps/stable-mir/check_def_ty.rs b/tests/ui-fulldeps/stable-mir/check_def_ty.rs
index 37b9a83e33e76..d8bfddca8aead 100644
--- a/tests/ui-fulldeps/stable-mir/check_def_ty.rs
+++ b/tests/ui-fulldeps/stable-mir/check_def_ty.rs
@@ -8,7 +8,6 @@
 //@ edition: 2021
 
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 
 extern crate rustc_middle;
 #[macro_use]
diff --git a/tests/ui-fulldeps/stable-mir/check_defs.rs b/tests/ui-fulldeps/stable-mir/check_defs.rs
index cd3d76d876012..020eeb801e0e2 100644
--- a/tests/ui-fulldeps/stable-mir/check_defs.rs
+++ b/tests/ui-fulldeps/stable-mir/check_defs.rs
@@ -7,7 +7,6 @@
 //@ edition: 2021
 
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 
 extern crate rustc_middle;
 #[macro_use]
@@ -16,7 +15,7 @@ extern crate rustc_driver;
 extern crate rustc_interface;
 extern crate stable_mir;
 
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 use mir::{mono::Instance, TerminatorKind::*};
 use stable_mir::mir::mono::InstanceKind;
 use rustc_smir::rustc_internal;
diff --git a/tests/ui-fulldeps/stable-mir/check_foreign.rs b/tests/ui-fulldeps/stable-mir/check_foreign.rs
index bc3956b309088..fa763e7530e68 100644
--- a/tests/ui-fulldeps/stable-mir/check_foreign.rs
+++ b/tests/ui-fulldeps/stable-mir/check_foreign.rs
@@ -7,7 +7,6 @@
 //@ edition: 2021
 
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 
 extern crate rustc_middle;
 #[macro_use]
@@ -22,7 +21,7 @@ use stable_mir::{
     ty::{Abi, ForeignItemKind},
     *,
 };
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 use std::io::Write;
 use std::ops::ControlFlow;
 
diff --git a/tests/ui-fulldeps/stable-mir/check_instance.rs b/tests/ui-fulldeps/stable-mir/check_instance.rs
index 72a138f907e72..bd8f5547c8d3e 100644
--- a/tests/ui-fulldeps/stable-mir/check_instance.rs
+++ b/tests/ui-fulldeps/stable-mir/check_instance.rs
@@ -7,7 +7,6 @@
 //@ edition: 2021
 
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 
 extern crate rustc_middle;
 #[macro_use]
diff --git a/tests/ui-fulldeps/stable-mir/check_intrinsics.rs b/tests/ui-fulldeps/stable-mir/check_intrinsics.rs
index 2f772b978865a..2c3146eb43245 100644
--- a/tests/ui-fulldeps/stable-mir/check_intrinsics.rs
+++ b/tests/ui-fulldeps/stable-mir/check_intrinsics.rs
@@ -10,7 +10,6 @@
 //@ ignore-remote
 
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 
 extern crate rustc_middle;
 extern crate rustc_hir;
@@ -25,7 +24,7 @@ use stable_mir::mir::mono::{Instance, InstanceKind};
 use stable_mir::mir::visit::{Location, MirVisitor};
 use stable_mir::mir::{LocalDecl, Terminator, TerminatorKind};
 use stable_mir::ty::{FnDef, GenericArgs, RigidTy, TyKind};
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 use std::convert::TryFrom;
 use std::io::Write;
 use std::ops::ControlFlow;
diff --git a/tests/ui-fulldeps/stable-mir/check_item_kind.rs b/tests/ui-fulldeps/stable-mir/check_item_kind.rs
index 647ce534589e1..c56c3753a007f 100644
--- a/tests/ui-fulldeps/stable-mir/check_item_kind.rs
+++ b/tests/ui-fulldeps/stable-mir/check_item_kind.rs
@@ -7,7 +7,6 @@
 //@ edition: 2021
 
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 
 extern crate rustc_middle;
 #[macro_use]
diff --git a/tests/ui-fulldeps/stable-mir/check_trait_queries.rs b/tests/ui-fulldeps/stable-mir/check_trait_queries.rs
index 23c2844d3f166..17749d7c9f273 100644
--- a/tests/ui-fulldeps/stable-mir/check_trait_queries.rs
+++ b/tests/ui-fulldeps/stable-mir/check_trait_queries.rs
@@ -7,7 +7,6 @@
 //@ edition: 2021
 
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 
 extern crate rustc_middle;
 #[macro_use]
diff --git a/tests/ui-fulldeps/stable-mir/check_transform.rs b/tests/ui-fulldeps/stable-mir/check_transform.rs
index d9fc924933fa8..cbdb0e58adfc2 100644
--- a/tests/ui-fulldeps/stable-mir/check_transform.rs
+++ b/tests/ui-fulldeps/stable-mir/check_transform.rs
@@ -6,7 +6,6 @@
 //@ ignore-remote
 
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 #![feature(ascii_char, ascii_char_variants)]
 
 extern crate rustc_hir;
diff --git a/tests/ui-fulldeps/stable-mir/check_ty_fold.rs b/tests/ui-fulldeps/stable-mir/check_ty_fold.rs
index 9fa4929d68e27..1d1a7701c7d17 100644
--- a/tests/ui-fulldeps/stable-mir/check_ty_fold.rs
+++ b/tests/ui-fulldeps/stable-mir/check_ty_fold.rs
@@ -8,7 +8,6 @@
 //@ edition: 2021
 
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 
 extern crate rustc_middle;
 #[macro_use]
diff --git a/tests/ui-fulldeps/stable-mir/compilation-result.rs b/tests/ui-fulldeps/stable-mir/compilation-result.rs
index b8a9e720e5465..eea0f7754ee21 100644
--- a/tests/ui-fulldeps/stable-mir/compilation-result.rs
+++ b/tests/ui-fulldeps/stable-mir/compilation-result.rs
@@ -7,7 +7,6 @@
 //@ edition: 2021
 
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 
 extern crate rustc_middle;
 #[macro_use]
diff --git a/tests/ui-fulldeps/stable-mir/crate-info.rs b/tests/ui-fulldeps/stable-mir/crate-info.rs
index 7f0e9b50335d3..e43b3cda927d9 100644
--- a/tests/ui-fulldeps/stable-mir/crate-info.rs
+++ b/tests/ui-fulldeps/stable-mir/crate-info.rs
@@ -7,7 +7,6 @@
 //@ edition: 2021
 
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 
 extern crate rustc_hir;
 extern crate rustc_middle;
@@ -23,7 +22,7 @@ use stable_mir::ItemKind;
 use stable_mir::crate_def::CrateDef;
 use stable_mir::mir::mono::Instance;
 use stable_mir::ty::{RigidTy, TyKind};
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 use std::io::Write;
 use std::ops::ControlFlow;
 
diff --git a/tests/ui-fulldeps/stable-mir/projections.rs b/tests/ui-fulldeps/stable-mir/projections.rs
index 3cc71247e6744..7d9f356d8fccd 100644
--- a/tests/ui-fulldeps/stable-mir/projections.rs
+++ b/tests/ui-fulldeps/stable-mir/projections.rs
@@ -7,7 +7,6 @@
 //@ edition: 2021
 
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 
 extern crate rustc_hir;
 extern crate rustc_middle;
@@ -22,7 +21,7 @@ use stable_mir::crate_def::CrateDef;
 use stable_mir::mir::{ProjectionElem, Rvalue, StatementKind};
 use stable_mir::ty::{RigidTy, TyKind, UintTy};
 use stable_mir::ItemKind;
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 use std::io::Write;
 use std::ops::ControlFlow;
 
diff --git a/tests/ui-fulldeps/stable-mir/smir_internal.rs b/tests/ui-fulldeps/stable-mir/smir_internal.rs
index 453e5372de4f8..64f16e44043e1 100644
--- a/tests/ui-fulldeps/stable-mir/smir_internal.rs
+++ b/tests/ui-fulldeps/stable-mir/smir_internal.rs
@@ -8,7 +8,6 @@
 //@ edition: 2021
 
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 
 #[macro_use]
 extern crate rustc_smir;
diff --git a/tests/ui-fulldeps/stable-mir/smir_serde.rs b/tests/ui-fulldeps/stable-mir/smir_serde.rs
index 2c74276d550cf..c4a3dfe96f2ea 100644
--- a/tests/ui-fulldeps/stable-mir/smir_serde.rs
+++ b/tests/ui-fulldeps/stable-mir/smir_serde.rs
@@ -7,7 +7,6 @@
 //@ edition: 2021
 
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 
 #[macro_use]
 extern crate rustc_smir;
diff --git a/tests/ui-fulldeps/stable-mir/smir_visitor.rs b/tests/ui-fulldeps/stable-mir/smir_visitor.rs
index 0a6415d490e4b..a95cf02610d2e 100644
--- a/tests/ui-fulldeps/stable-mir/smir_visitor.rs
+++ b/tests/ui-fulldeps/stable-mir/smir_visitor.rs
@@ -7,7 +7,6 @@
 //@ edition: 2021
 
 #![feature(rustc_private)]
-#![feature(assert_matches)]
 
 extern crate rustc_middle;
 #[macro_use]
diff --git a/tests/ui-fulldeps/try-from-u32/values.rs b/tests/ui-fulldeps/try-from-u32/values.rs
index 180a8f2beb75b..802fba38590c4 100644
--- a/tests/ui-fulldeps/try-from-u32/values.rs
+++ b/tests/ui-fulldeps/try-from-u32/values.rs
@@ -1,4 +1,3 @@
-#![feature(assert_matches)]
 #![feature(rustc_private)]
 //@ edition: 2021
 //@ run-pass
@@ -7,7 +6,7 @@
 
 extern crate rustc_macros;
 
-use core::assert_matches::assert_matches;
+use core::macros::assert_matches;
 use rustc_macros::TryFromU32;
 
 #[derive(TryFromU32, Debug, PartialEq)]
diff --git a/tests/ui/coroutine/uninhabited-field.rs b/tests/ui/coroutine/uninhabited-field.rs
index d6ada07ce0cbc..d8baa8b0d953e 100644
--- a/tests/ui/coroutine/uninhabited-field.rs
+++ b/tests/ui/coroutine/uninhabited-field.rs
@@ -1,11 +1,10 @@
 // Test that uninhabited saved local doesn't make the entire variant uninhabited.
 //@ run-pass
 #![allow(unused)]
-#![feature(assert_matches)]
 #![feature(coroutine_trait)]
 #![feature(coroutines, stmt_expr_attributes)]
 #![feature(never_type)]
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 use std::ops::Coroutine;
 use std::ops::CoroutineState;
 use std::pin::Pin;
diff --git a/tests/ui/macros/assert-matches-macro-msg.rs b/tests/ui/macros/assert-matches-macro-msg.rs
index 956bc9cf0f49b..db7eca1432957 100644
--- a/tests/ui/macros/assert-matches-macro-msg.rs
+++ b/tests/ui/macros/assert-matches-macro-msg.rs
@@ -4,9 +4,7 @@
 //@ error-pattern: right: 3
 //@ needs-subprocess
 
-#![feature(assert_matches)]
-
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 
 fn main() {
     assert_matches!(1 + 1, 3, "1 + 1 definitely should be 3");
diff --git a/tests/ui/stdlib-unit-tests/matches2021.rs b/tests/ui/stdlib-unit-tests/matches2021.rs
index 78c8be7321362..ba11f9bac769f 100644
--- a/tests/ui/stdlib-unit-tests/matches2021.rs
+++ b/tests/ui/stdlib-unit-tests/matches2021.rs
@@ -3,9 +3,7 @@
 
 // regression test for https://github.com/rust-lang/rust/pull/85678
 
-#![feature(assert_matches)]
-
-use std::assert_matches::assert_matches;
+use std::macros::assert_matches;
 
 fn main() {
     assert!(matches!((), ()));

From 8cf7d03cd8e9623a395ab62bc5a255aaf48d8818 Mon Sep 17 00:00:00 2001
From: Lukas Bergdoll <lukas.bergdoll@gmail.com>
Date: Mon, 24 Feb 2025 14:21:30 +0100
Subject: [PATCH 2/4] Fix error tests

---
 src/doc/rustc-dev-guide/src/attributes.md                     | 4 ++--
 .../miri/tests/fail-dep/concurrency/windows_join_main.stderr  | 2 +-
 src/tools/miri/tests/fail/rc_as_ptr.stderr                    | 2 +-
 src/tools/miri/tests/fail/stacked_borrows/zst_slice.stderr    | 2 +-
 src/tools/miri/tests/pass/alloc-access-tracking.stderr        | 2 +-
 tests/ui/did_you_mean/println-typo.stderr                     | 2 +-
 tests/ui/issues/issue-32655.stderr                            | 4 ++--
 tests/ui/macros/macro-name-typo.stderr                        | 2 +-
 tests/ui/macros/macro-path-prelude-fail-3.stderr              | 2 +-
 tests/ui/macros/unknown-builtin.stderr                        | 2 +-
 tests/ui/parser/recover/recover-pat-exprs.stderr              | 2 +-
 tests/ui/suggestions/attribute-typos.stderr                   | 2 +-
 12 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/doc/rustc-dev-guide/src/attributes.md b/src/doc/rustc-dev-guide/src/attributes.md
index aae856348af17..eb146a170dfac 100644
--- a/src/doc/rustc-dev-guide/src/attributes.md
+++ b/src/doc/rustc-dev-guide/src/attributes.md
@@ -33,9 +33,9 @@ Definitions of non-builtin attributes take two forms:
 1. Proc-macro attributes, defined via a function annotated with `#[proc_macro_attribute]` in a
    proc-macro crate.
 2. AST-based attributes, defined in the standard library. These attributes have special 'stub'
-   macros defined in places like [`library/core/src/macros/mod.rs`][core_macros].
+   macros defined in places like [`library/core/src/core_macros/mod.rs`][core_macros].
 
-[core_macros]:  https://github.com/rust-lang/rust/blob/master/library/core/src/macros/mod.rs
+[core_macros]:  https://github.com/rust-lang/rust/blob/master/library/core/src/core_macros/mod.rs
 
 These definitions exist to allow the macros to participate in typical path-based resolution - they
 can be imported, re-exported, and renamed just like any other item definition. However, the body of
diff --git a/src/tools/miri/tests/fail-dep/concurrency/windows_join_main.stderr b/src/tools/miri/tests/fail-dep/concurrency/windows_join_main.stderr
index 6540543d8da3f..5d3e1350cd93d 100644
--- a/src/tools/miri/tests/fail-dep/concurrency/windows_join_main.stderr
+++ b/src/tools/miri/tests/fail-dep/concurrency/windows_join_main.stderr
@@ -5,7 +5,7 @@ LL |             assert_eq!(WaitForSingleObject(MAIN_THREAD, INFINITE), WAIT_OBJ
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program deadlocked
    |
    = note: BACKTRACE on thread `unnamed-ID`:
-   = note: inside closure at RUSTLIB/core/src/macros/mod.rs:LL:CC
+   = note: inside closure at RUSTLIB/core/src/core_macros/mod.rs:LL:CC
    = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: deadlock: the evaluated program deadlocked
diff --git a/src/tools/miri/tests/fail/rc_as_ptr.stderr b/src/tools/miri/tests/fail/rc_as_ptr.stderr
index 0fcb0faf49718..42e2c74641eae 100644
--- a/src/tools/miri/tests/fail/rc_as_ptr.stderr
+++ b/src/tools/miri/tests/fail/rc_as_ptr.stderr
@@ -17,7 +17,7 @@ help: ALLOC was deallocated here:
 LL |     drop(strong);
    |     ^^^^^^^^^^^^
    = note: BACKTRACE (of the first span):
-   = note: inside `main` at RUSTLIB/core/src/macros/mod.rs:LL:CC
+   = note: inside `main` at RUSTLIB/core/src/core_macros/mod.rs:LL:CC
    = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
diff --git a/src/tools/miri/tests/fail/stacked_borrows/zst_slice.stderr b/src/tools/miri/tests/fail/stacked_borrows/zst_slice.stderr
index 01e3c60f0fe38..16476b24e90e2 100644
--- a/src/tools/miri/tests/fail/stacked_borrows/zst_slice.stderr
+++ b/src/tools/miri/tests/fail/stacked_borrows/zst_slice.stderr
@@ -15,7 +15,7 @@ help: <TAG> would have been created here, but this is a zero-size retag ([0x0..0
 LL |         assert_eq!(*s.as_ptr().add(1), 2);
    |                     ^^^^^^^^^^
    = note: BACKTRACE (of the first span):
-   = note: inside `main` at RUSTLIB/core/src/macros/mod.rs:LL:CC
+   = note: inside `main` at RUSTLIB/core/src/core_macros/mod.rs:LL:CC
    = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
diff --git a/src/tools/miri/tests/pass/alloc-access-tracking.stderr b/src/tools/miri/tests/pass/alloc-access-tracking.stderr
index 0c85afd831b6a..b20ec9b308f18 100644
--- a/src/tools/miri/tests/pass/alloc-access-tracking.stderr
+++ b/src/tools/miri/tests/pass/alloc-access-tracking.stderr
@@ -23,7 +23,7 @@ LL |         assert_eq!(*ptr, 42);
    |         ^^^^^^^^^^^^^^^^^^^^ read access to allocation with id $ALLOC
    |
    = note: BACKTRACE:
-   = note: inside `miri_start` at RUSTLIB/core/src/macros/mod.rs:LL:CC
+   = note: inside `miri_start` at RUSTLIB/core/src/core_macros/mod.rs:LL:CC
    = note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 note: tracking was triggered
diff --git a/tests/ui/did_you_mean/println-typo.stderr b/tests/ui/did_you_mean/println-typo.stderr
index a1e0b1f1ba4f1..ab4779980261b 100644
--- a/tests/ui/did_you_mean/println-typo.stderr
+++ b/tests/ui/did_you_mean/println-typo.stderr
@@ -3,7 +3,7 @@ error: cannot find macro `prinltn` in this scope
    |
 LL |     prinltn!();
    |     ^^^^^^^ help: a macro with a similar name exists: `println`
-  --> $SRC_DIR/std/src/macros.rs:LL:COL
+  --> $SRC_DIR/std/src/std_macros.rs:LL:COL
    |
    = note: similarly named macro `println` defined here
 
diff --git a/tests/ui/issues/issue-32655.stderr b/tests/ui/issues/issue-32655.stderr
index b8362499b2d0a..fd606acf085b1 100644
--- a/tests/ui/issues/issue-32655.stderr
+++ b/tests/ui/issues/issue-32655.stderr
@@ -6,7 +6,7 @@ LL |         #[derive_Clone]
 ...
 LL | foo!();
    | ------ in this macro invocation
-  --> $SRC_DIR/core/src/macros/mod.rs:LL:COL
+  --> $SRC_DIR/core/src/core_macros/mod.rs:LL:COL
    |
    = note: similarly named attribute macro `derive_const` defined here
    |
@@ -17,7 +17,7 @@ error: cannot find attribute `derive_Clone` in this scope
    |
 LL |     #[derive_Clone]
    |       ^^^^^^^^^^^^ help: an attribute macro with a similar name exists: `derive_const`
-  --> $SRC_DIR/core/src/macros/mod.rs:LL:COL
+  --> $SRC_DIR/core/src/core_macros/mod.rs:LL:COL
    |
    = note: similarly named attribute macro `derive_const` defined here
 
diff --git a/tests/ui/macros/macro-name-typo.stderr b/tests/ui/macros/macro-name-typo.stderr
index 9059b10faaacd..63be3a70f26b5 100644
--- a/tests/ui/macros/macro-name-typo.stderr
+++ b/tests/ui/macros/macro-name-typo.stderr
@@ -3,7 +3,7 @@ error: cannot find macro `printlx` in this scope
    |
 LL |     printlx!("oh noes!");
    |     ^^^^^^^ help: a macro with a similar name exists: `println`
-  --> $SRC_DIR/std/src/macros.rs:LL:COL
+  --> $SRC_DIR/std/src/std_macros.rs:LL:COL
    |
    = note: similarly named macro `println` defined here
 
diff --git a/tests/ui/macros/macro-path-prelude-fail-3.stderr b/tests/ui/macros/macro-path-prelude-fail-3.stderr
index 485d7b7869a9a..6138d3e4298bd 100644
--- a/tests/ui/macros/macro-path-prelude-fail-3.stderr
+++ b/tests/ui/macros/macro-path-prelude-fail-3.stderr
@@ -3,7 +3,7 @@ error: cannot find macro `inline` in this scope
    |
 LL |     inline!();
    |     ^^^^^^ help: a macro with a similar name exists: `line`
-  --> $SRC_DIR/core/src/macros/mod.rs:LL:COL
+  --> $SRC_DIR/core/src/core_macros/mod.rs:LL:COL
    |
    = note: similarly named macro `line` defined here
    |
diff --git a/tests/ui/macros/unknown-builtin.stderr b/tests/ui/macros/unknown-builtin.stderr
index 22f54e04e54c3..fdda430d2c881 100644
--- a/tests/ui/macros/unknown-builtin.stderr
+++ b/tests/ui/macros/unknown-builtin.stderr
@@ -5,7 +5,7 @@ LL | macro_rules! unknown { () => () }
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0773]: attempted to define built-in macro more than once
-  --> $SRC_DIR/core/src/macros/mod.rs:LL:COL
+  --> $SRC_DIR/core/src/core_macros/mod.rs:LL:COL
    |
 note: previously defined here
   --> $DIR/unknown-builtin.rs:9:1
diff --git a/tests/ui/parser/recover/recover-pat-exprs.stderr b/tests/ui/parser/recover/recover-pat-exprs.stderr
index dcc1945d569c0..1a5bbac848ba6 100644
--- a/tests/ui/parser/recover/recover-pat-exprs.stderr
+++ b/tests/ui/parser/recover/recover-pat-exprs.stderr
@@ -806,7 +806,7 @@ error: expected one of `)`, `,`, `@`, `if`, or `|`, found `*`
    |
 LL |     let b = matches!(x, (x * x | x.f()) | x[0]);
    |                            ^ expected one of `)`, `,`, `@`, `if`, or `|`
-  --> $SRC_DIR/core/src/macros/mod.rs:LL:COL
+  --> $SRC_DIR/core/src/core_macros/mod.rs:LL:COL
    |
    = note: while parsing argument for this `pat` macro fragment
 
diff --git a/tests/ui/suggestions/attribute-typos.stderr b/tests/ui/suggestions/attribute-typos.stderr
index b871c9b45a56c..b0fd0fa0f8d4f 100644
--- a/tests/ui/suggestions/attribute-typos.stderr
+++ b/tests/ui/suggestions/attribute-typos.stderr
@@ -15,7 +15,7 @@ error: cannot find attribute `tests` in this scope
    |
 LL | #[tests]
    |   ^^^^^ help: an attribute macro with a similar name exists: `test`
-  --> $SRC_DIR/core/src/macros/mod.rs:LL:COL
+  --> $SRC_DIR/core/src/core_macros/mod.rs:LL:COL
    |
    = note: similarly named attribute macro `test` defined here
 

From 27c07311f25c8029bff43d2c49a466b51240d6b6 Mon Sep 17 00:00:00 2001
From: Lukas Bergdoll <lukas.bergdoll@gmail.com>
Date: Mon, 24 Feb 2025 15:08:22 +0100
Subject: [PATCH 3/4] Move debug_assert_matches back to its kin

Needed for doc intra links
---
 library/core/src/core_macros/mod.rs | 98 ++++++++++++++---------------
 1 file changed, 49 insertions(+), 49 deletions(-)

diff --git a/library/core/src/core_macros/mod.rs b/library/core/src/core_macros/mod.rs
index e115fa8c69076..3a650e8c9d122 100644
--- a/library/core/src/core_macros/mod.rs
+++ b/library/core/src/core_macros/mod.rs
@@ -194,55 +194,6 @@ pub macro assert_matches {
     },
 }
 
-/// Asserts that an expression matches the provided pattern.
-///
-/// This macro is generally preferable to `debug_assert!(matches!(value, pattern))`, because it can
-/// print the debug representation of the actual value shape that did not meet expectations. In
-/// contrast, using [`debug_assert!`] will only print that expectations were not met, but not why.
-///
-/// The pattern syntax is exactly the same as found in a match arm and the `matches!` macro. The
-/// optional if guard can be used to add additional checks that must be true for the matched value,
-/// otherwise this macro will panic.
-///
-/// On panic, this macro will print the value of the expression with its debug representation.
-///
-/// Like [`assert!`], this macro has a second form, where a custom panic message can be provided.
-///
-/// Unlike [`assert_matches!`], `debug_assert_matches!` statements are only enabled in non optimized
-/// builds by default. An optimized build will not execute `debug_assert_matches!` statements unless
-/// `-C debug-assertions` is passed to the compiler. This makes `debug_assert_matches!` useful for
-/// checks that are too expensive to be present in a release build but may be helpful during
-/// development. The result of expanding `debug_assert_matches!` is always type checked.
-///
-/// # Examples
-///
-/// ```
-/// use std::macros::debug_assert_matches;
-///
-/// let a = Some(345);
-/// let b = Some(56);
-/// debug_assert_matches!(a, Some(_));
-/// debug_assert_matches!(b, Some(_));
-///
-/// debug_assert_matches!(a, Some(345));
-/// debug_assert_matches!(a, Some(345) | None);
-///
-/// // debug_assert_matches!(a, None); // panics
-/// // debug_assert_matches!(b, Some(345)); // panics
-/// // debug_assert_matches!(b, Some(345) | None); // panics
-///
-/// debug_assert_matches!(a, Some(x) if x > 100);
-/// // debug_assert_matches!(a, Some(x) if x < 100); // panics
-/// ```
-#[stable(feature = "assert_matches", since = "CURRENT_RUSTC_VERSION")]
-#[allow_internal_unstable(assert_matches)]
-#[rustc_macro_transparency = "semitransparent"]
-pub macro debug_assert_matches($($arg:tt)*) {
-    if $crate::cfg!(debug_assertions) {
-        $crate::macros::assert_matches!($($arg)*);
-    }
-}
-
 /// A macro for defining `#[cfg]` match-like statements.
 ///
 /// It is similar to the `if/elif` C preprocessor macro by allowing definition of a cascade of
@@ -417,6 +368,55 @@ macro_rules! debug_assert_ne {
     };
 }
 
+/// Asserts that an expression matches the provided pattern.
+///
+/// This macro is generally preferable to `debug_assert!(matches!(value, pattern))`, because it can
+/// print the debug representation of the actual value shape that did not meet expectations. In
+/// contrast, using [`debug_assert!`] will only print that expectations were not met, but not why.
+///
+/// The pattern syntax is exactly the same as found in a match arm and the `matches!` macro. The
+/// optional if guard can be used to add additional checks that must be true for the matched value,
+/// otherwise this macro will panic.
+///
+/// On panic, this macro will print the value of the expression with its debug representation.
+///
+/// Like [`assert!`], this macro has a second form, where a custom panic message can be provided.
+///
+/// Unlike [`assert_matches!`], `debug_assert_matches!` statements are only enabled in non optimized
+/// builds by default. An optimized build will not execute `debug_assert_matches!` statements unless
+/// `-C debug-assertions` is passed to the compiler. This makes `debug_assert_matches!` useful for
+/// checks that are too expensive to be present in a release build but may be helpful during
+/// development. The result of expanding `debug_assert_matches!` is always type checked.
+///
+/// # Examples
+///
+/// ```
+/// use std::macros::debug_assert_matches;
+///
+/// let a = Some(345);
+/// let b = Some(56);
+/// debug_assert_matches!(a, Some(_));
+/// debug_assert_matches!(b, Some(_));
+///
+/// debug_assert_matches!(a, Some(345));
+/// debug_assert_matches!(a, Some(345) | None);
+///
+/// // debug_assert_matches!(a, None); // panics
+/// // debug_assert_matches!(b, Some(345)); // panics
+/// // debug_assert_matches!(b, Some(345) | None); // panics
+///
+/// debug_assert_matches!(a, Some(x) if x > 100);
+/// // debug_assert_matches!(a, Some(x) if x < 100); // panics
+/// ```
+#[stable(feature = "assert_matches", since = "CURRENT_RUSTC_VERSION")]
+#[allow_internal_unstable(assert_matches)]
+#[rustc_macro_transparency = "semitransparent"]
+pub macro debug_assert_matches($($arg:tt)*) {
+    if $crate::cfg!(debug_assertions) {
+        $crate::macros::assert_matches!($($arg)*);
+    }
+}
+
 /// Returns whether the given expression matches the provided pattern.
 ///
 /// The pattern syntax is exactly the same as found in a match arm. The optional if guard can be

From 772bf471c1a055a9cc8a7efcffd703c0694aad22 Mon Sep 17 00:00:00 2001
From: Lukas Bergdoll <lukas.bergdoll@gmail.com>
Date: Mon, 24 Feb 2025 16:12:45 +0100
Subject: [PATCH 4/4] Fix more error tests

---
 .../miri/tests/fail/dangling_pointers/dangling_primitive.stderr | 2 +-
 .../tests/fail/function_calls/return_pointer_on_unwind.stderr   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/tools/miri/tests/fail/dangling_pointers/dangling_primitive.stderr b/src/tools/miri/tests/fail/dangling_pointers/dangling_primitive.stderr
index 2d7456c15b96b..70e70f5df79d5 100644
--- a/src/tools/miri/tests/fail/dangling_pointers/dangling_primitive.stderr
+++ b/src/tools/miri/tests/fail/dangling_pointers/dangling_primitive.stderr
@@ -17,7 +17,7 @@ help: ALLOC was deallocated here:
 LL |     };
    |     ^
    = note: BACKTRACE (of the first span):
-   = note: inside `main` at RUSTLIB/std/src/macros.rs:LL:CC
+   = note: inside `main` at RUSTLIB/std/src/std_macros.rs:LL:CC
    = note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
diff --git a/src/tools/miri/tests/fail/function_calls/return_pointer_on_unwind.stderr b/src/tools/miri/tests/fail/function_calls/return_pointer_on_unwind.stderr
index e2a3d1600ea75..c184ccfe2a157 100644
--- a/src/tools/miri/tests/fail/function_calls/return_pointer_on_unwind.stderr
+++ b/src/tools/miri/tests/fail/function_calls/return_pointer_on_unwind.stderr
@@ -12,7 +12,7 @@ LL |     dbg!(x.0);
    = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
    = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
    = note: BACKTRACE:
-   = note: inside `main` at RUSTLIB/std/src/macros.rs:LL:CC
+   = note: inside `main` at RUSTLIB/std/src/std_macros.rs:LL:CC
    = note: this error originates in the macro `dbg` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace