Rollup merge of #151423 - Voultapher:move-assert-matches, r=Amanieu

Move assert_matches to planned stable path

Another prep PR for https://github.com/rust-lang/rust/pull/137487
This commit is contained in:
Jonathan Brouwer
2026-01-22 13:35:41 +01:00
committed by GitHub
27 changed files with 43 additions and 40 deletions

View File

@@ -41,8 +41,11 @@
// have to worry about it being moved to a different module in std during stabilization.
// FIXME(#151359): Remove this when `feature(assert_matches)` is stable in stage0.
// (This doesn't necessarily need to be fixed during the beta bump itself.)
#[cfg(bootstrap)]
pub use std::assert_matches::{assert_matches, debug_assert_matches};
use std::fmt;
#[cfg(not(bootstrap))]
pub use std::{assert_matches, debug_assert_matches};
pub use atomic_ref::AtomicRef;
pub use ena::{snapshot_vec, undo_log, unify};

View File

@@ -1,4 +1,4 @@
use core::assert_matches::assert_matches;
use core::assert_matches;
use std::iter;
use std::ops::Bound::{Excluded, Included, Unbounded};
use std::panic::{AssertUnwindSafe, catch_unwind};

View File

@@ -1,7 +1,7 @@
use alloc::ffi::CString;
use alloc::rc::Rc;
use alloc::sync::Arc;
use core::assert_matches::assert_matches;
use core::assert_matches;
use core::ffi::{CStr, FromBytesUntilNulError, c_char};
#[allow(deprecated)]
use core::hash::SipHasher13 as DefaultHasher;

View File

@@ -1,6 +1,6 @@
#![allow(invalid_from_utf8)]
use std::assert_matches::assert_matches;
use std::assert_matches;
use std::borrow::Cow;
use std::cmp::Ordering::{Equal, Greater, Less};
use std::str::{from_utf8, from_utf8_unchecked};

View File

@@ -1,10 +1,9 @@
use std::assert_matches::assert_matches;
use std::borrow::Cow;
use std::cell::Cell;
use std::collections::TryReserveErrorKind::*;
use std::ops::Bound::*;
use std::ops::{Bound, RangeBounds};
use std::{panic, str};
use std::{assert_matches, panic, str};
pub trait IntoCow<'a, B: ?Sized>
where

View File

@@ -3,12 +3,10 @@ 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::hint;
use std::iter::InPlaceIterable;
use std::mem::swap;
use std::ops::Bound::*;
@@ -16,6 +14,7 @@ use std::panic::{AssertUnwindSafe, catch_unwind};
use std::rc::Rc;
use std::sync::atomic::{AtomicU32, Ordering};
use std::vec::{Drain, IntoIter, PeekMut};
use std::{assert_matches, hint};
use crate::testing::macros::struct_with_counted_drop;

View File

@@ -1,6 +1,6 @@
use core::cell::Cell;
use core::num::NonZero;
use std::assert_matches::assert_matches;
use std::assert_matches;
use std::collections::TryReserveErrorKind::*;
use std::collections::VecDeque;
use std::collections::vec_deque::Drain;

View File

@@ -223,11 +223,7 @@ use prelude::rust_2024::*;
mod macros;
#[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};
}
pub use crate::macros::{assert_matches, debug_assert_matches};
#[unstable(feature = "derive_from", issue = "144889")]
/// Unstable module containing the unstable `From` derive macro.

View File

@@ -124,6 +124,8 @@ macro_rules! assert_ne {
};
}
// FIXME add back debug_assert_matches doc link after bootstrap.
/// Asserts that an expression matches the provided pattern.
///
/// This macro is generally preferable to `assert!(matches!(value, pattern))`, because it can print
@@ -135,11 +137,9 @@ macro_rules! assert_ne {
/// otherwise this macro will panic.
///
/// Assertions are always checked in both debug and release builds, and cannot
/// be disabled. See [`debug_assert_matches!`] for assertions that are disabled in
/// 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
///
/// 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.
@@ -149,7 +149,7 @@ macro_rules! assert_ne {
/// ```
/// #![feature(assert_matches)]
///
/// use std::assert_matches::assert_matches;
/// use std::assert_matches;
///
/// let a = Some(345);
/// let b = Some(56);
@@ -382,7 +382,7 @@ macro_rules! debug_assert_ne {
/// ```
/// #![feature(assert_matches)]
///
/// use std::assert_matches::debug_assert_matches;
/// use std::debug_assert_matches;
///
/// let a = Some(345);
/// let b = Some(56);
@@ -404,7 +404,7 @@ macro_rules! debug_assert_ne {
#[rustc_macro_transparency = "semiopaque"]
pub macro debug_assert_matches($($arg:tt)*) {
if $crate::cfg!(debug_assertions) {
$crate::assert_matches::assert_matches!($($arg)*);
$crate::assert_matches!($($arg)*);
}
}

View File

@@ -3,7 +3,7 @@ use realstd::collections::TryReserveErrorKind::*;
use super::Entry::{Occupied, Vacant};
use super::HashMap;
use crate::assert_matches::assert_matches;
use crate::assert_matches;
use crate::cell::RefCell;
use crate::hash::{BuildHasher, BuildHasherDefault, DefaultHasher, RandomState};
use crate::test_helpers::test_rng;

View File

@@ -2,7 +2,6 @@ use rand::RngCore;
#[cfg(not(miri))]
use super::Dir;
use crate::assert_matches::assert_matches;
use crate::fs::{self, File, FileTimes, OpenOptions, TryLockError};
#[cfg(not(miri))]
use crate::io;
@@ -21,7 +20,7 @@ use crate::path::Path;
use crate::sync::Arc;
use crate::test_helpers::{TempDir, tmpdir};
use crate::time::{Duration, Instant, SystemTime};
use crate::{env, str, thread};
use crate::{assert_matches, env, str, thread};
macro_rules! check {
($e:expr) => {

View File

@@ -1,7 +1,6 @@
use super::{Custom, Error, ErrorData, ErrorKind, Repr, SimpleMessage, const_error};
use crate::assert_matches::assert_matches;
use crate::sys::io::{decode_error_kind, error_string};
use crate::{error, fmt};
use crate::{assert_matches, error, fmt};
#[test]
fn test_size() {

View File

@@ -711,9 +711,9 @@ pub use core::todo;
// Re-export built-in macros defined through core.
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
pub use core::{
assert, assert_matches, cfg, column, compile_error, concat, const_format_args, env, file,
format_args, format_args_nl, include, include_bytes, include_str, line, log_syntax,
module_path, option_env, stringify, trace_macros,
assert, cfg, column, compile_error, concat, const_format_args, env, file, format_args,
format_args_nl, include, include_bytes, include_str, line, log_syntax, module_path, option_env,
stringify, trace_macros,
};
// Re-export macros defined in core.
#[stable(feature = "rust1", since = "1.0.0")]
@@ -722,6 +722,8 @@ pub use core::{
assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, r#try, unimplemented,
unreachable, write, writeln,
};
#[unstable(feature = "assert_matches", issue = "82775")]
pub use core::{assert_matches, debug_assert_matches};
// Re-export unstable derive macro defined through core.
#[unstable(feature = "derive_from", issue = "144889")]

View File

@@ -1,5 +1,5 @@
use super::PidFd as InternalPidFd;
use crate::assert_matches::assert_matches;
use crate::assert_matches;
use crate::os::fd::AsRawFd;
use crate::os::linux::process::{ChildExt, CommandExt as _};
use crate::os::unix::process::{CommandExt as _, ExitStatusExt};

View File

@@ -524,7 +524,7 @@ impl Command {
return Ok(None);
}
}
core::assert_matches::debug_assert_matches!(support, SPAWN | NO);
core::debug_assert_matches!(support, SPAWN | NO);
}
}
_ => {

View File

@@ -1,4 +1,7 @@
use std::assert_matches::debug_assert_matches;
#[cfg(bootstrap)]
pub use std::assert_matches::debug_assert_matches;
#[cfg(not(bootstrap))]
pub use std::debug_assert_matches;
use std::fmt::{self, Display, Write as _};
use std::sync::LazyLock as Lazy;
use std::{ascii, mem};

View File

@@ -29,7 +29,10 @@ 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};
#[cfg(bootstrap)]
use std::assert_matches::debug_assert_matches;
#[cfg(not(bootstrap))]
use std::debug_assert_matches;
use std::collections::hash_map::Entry;
use std::{iter, mem};

View File

@@ -25,7 +25,7 @@ use rustc_public::mir::mono::Instance;
use rustc_public::target::MachineInfo;
use rustc_public::ty::{AdtDef, RigidTy, Ty, TyKind};
use rustc_public::{CrateDef, CrateItem, CrateItems, ItemKind};
use std::assert_matches::assert_matches;
use std::assert_matches;
use std::collections::HashSet;
use std::convert::TryFrom;
use std::io::Write;

View File

@@ -20,7 +20,7 @@ extern crate rustc_interface;
extern crate rustc_public;
use std::ascii::Char;
use std::assert_matches::assert_matches;
use std::assert_matches;
use std::cmp::{max, min};
use std::collections::HashMap;
use std::ffi::CStr;

View File

@@ -19,7 +19,7 @@ use mir::{TerminatorKind::*, mono::Instance};
use rustc_public::mir::mono::InstanceKind;
use rustc_public::ty::{RigidTy, Ty, TyKind, UintTy};
use rustc_public::*;
use std::assert_matches::assert_matches;
use std::assert_matches;
use std::io::Write;
use std::ops::ControlFlow;

View File

@@ -20,7 +20,7 @@ use rustc_public::{
ty::{Abi, ForeignItemKind},
*,
};
use std::assert_matches::assert_matches;
use std::assert_matches;
use std::io::Write;
use std::ops::ControlFlow;

View File

@@ -24,7 +24,7 @@ use rustc_public::mir::mono::{Instance, InstanceKind};
use rustc_public::mir::visit::{Location, MirVisitor};
use rustc_public::mir::{LocalDecl, Terminator, TerminatorKind};
use rustc_public::ty::{FnDef, GenericArgs, RigidTy, TyKind};
use std::assert_matches::assert_matches;
use std::assert_matches;
use std::convert::TryFrom;
use std::io::Write;
use std::ops::ControlFlow;

View File

@@ -22,7 +22,7 @@ use rustc_public::ItemKind;
use rustc_public::crate_def::CrateDef;
use rustc_public::mir::mono::Instance;
use rustc_public::ty::{RigidTy, TyKind};
use std::assert_matches::assert_matches;
use std::assert_matches;
use std::io::Write;
use std::ops::ControlFlow;

View File

@@ -21,7 +21,7 @@ use rustc_public::ItemKind;
use rustc_public::crate_def::CrateDef;
use rustc_public::mir::{ProjectionElem, Rvalue, StatementKind};
use rustc_public::ty::{RigidTy, TyKind, UintTy};
use std::assert_matches::assert_matches;
use std::assert_matches;
use std::io::Write;
use std::ops::ControlFlow;

View File

@@ -5,7 +5,7 @@
#![feature(coroutine_trait)]
#![feature(coroutines, stmt_expr_attributes)]
#![feature(never_type)]
use std::assert_matches::assert_matches;
use std::assert_matches;
use std::ops::Coroutine;
use std::ops::CoroutineState;
use std::pin::Pin;

View File

@@ -6,7 +6,7 @@
#![feature(assert_matches)]
use std::assert_matches::assert_matches;
use std::assert_matches;
fn main() {
assert_matches!(1 + 1, 3, "1 + 1 definitely should be 3");

View File

@@ -5,7 +5,7 @@
#![feature(assert_matches)]
use std::assert_matches::assert_matches;
use std::assert_matches;
fn main() {
assert!(matches!((), ()));