diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 8377213850b86..49e960f82f02c 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -42,8 +42,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}; diff --git a/library/alloc/src/collections/btree/map/tests.rs b/library/alloc/src/collections/btree/map/tests.rs index a61a2da172d1e..938e867b85812 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::assert_matches; use std::iter; use std::ops::Bound::{Excluded, Included, Unbounded}; use std::panic::{AssertUnwindSafe, catch_unwind}; diff --git a/library/alloctests/tests/c_str2.rs b/library/alloctests/tests/c_str2.rs index fe7686bd1c592..8ecab03b5ceb3 100644 --- a/library/alloctests/tests/c_str2.rs +++ b/library/alloctests/tests/c_str2.rs @@ -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; diff --git a/library/alloctests/tests/str.rs b/library/alloctests/tests/str.rs index fbb3b01fd67f9..fcc4aaaa1dcd1 100644 --- a/library/alloctests/tests/str.rs +++ b/library/alloctests/tests/str.rs @@ -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}; diff --git a/library/alloctests/tests/string.rs b/library/alloctests/tests/string.rs index 71557f284f475..08eb1855a4824 100644 --- a/library/alloctests/tests/string.rs +++ b/library/alloctests/tests/string.rs @@ -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 diff --git a/library/alloctests/tests/vec.rs b/library/alloctests/tests/vec.rs index c8f9504ae14e8..5ab305f7a5048 100644 --- a/library/alloctests/tests/vec.rs +++ b/library/alloctests/tests/vec.rs @@ -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; diff --git a/library/alloctests/tests/vec_deque.rs b/library/alloctests/tests/vec_deque.rs index e9f860f8df9bd..e06d18250a51a 100644 --- a/library/alloctests/tests/vec_deque.rs +++ b/library/alloctests/tests/vec_deque.rs @@ -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; diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index dfc9a7b5dbc32..c4d16ba633b81 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -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. diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index a437a4795481c..3176f3c067092 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -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)*); } } diff --git a/library/std/src/collections/hash/map/tests.rs b/library/std/src/collections/hash/map/tests.rs index cc1a9900bec97..fd7d81b2855f3 100644 --- a/library/std/src/collections/hash/map/tests.rs +++ b/library/std/src/collections/hash/map/tests.rs @@ -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; diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs index 6a86705f2fadb..6d0b261dcadcf 100644 --- a/library/std/src/fs/tests.rs +++ b/library/std/src/fs/tests.rs @@ -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) => { diff --git a/library/std/src/io/error/tests.rs b/library/std/src/io/error/tests.rs index eef44c6ac3b6a..a8eef06381dae 100644 --- a/library/std/src/io/error/tests.rs +++ b/library/std/src/io/error/tests.rs @@ -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() { diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 03451214ccb5c..44db1bf22bc83 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -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")] 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 0330f28e647d3..4cc2368c25a22 100644 --- a/library/std/src/sys/pal/unix/linux/pidfd/tests.rs +++ b/library/std/src/sys/pal/unix/linux/pidfd/tests.rs @@ -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}; diff --git a/library/std/src/sys/process/unix/unix.rs b/library/std/src/sys/process/unix/unix.rs index 460d5ec0f0747..62d6e0581e6c8 100644 --- a/library/std/src/sys/process/unix/unix.rs +++ b/library/std/src/sys/process/unix/unix.rs @@ -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); } } _ => { diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 0f75a332ad6bc..9dc4b1ec4e9a2 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -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}; diff --git a/src/tools/clippy/clippy_utils/src/ty/mod.rs b/src/tools/clippy/clippy_utils/src/ty/mod.rs index a90d64e972c1f..53ad6675ab070 100644 --- a/src/tools/clippy/clippy_utils/src/ty/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ty/mod.rs @@ -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}; diff --git a/tests/ui-fulldeps/rustc_public/check_abi.rs b/tests/ui-fulldeps/rustc_public/check_abi.rs index b3519a2c60eda..256e267b7d303 100644 --- a/tests/ui-fulldeps/rustc_public/check_abi.rs +++ b/tests/ui-fulldeps/rustc_public/check_abi.rs @@ -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; diff --git a/tests/ui-fulldeps/rustc_public/check_allocation.rs b/tests/ui-fulldeps/rustc_public/check_allocation.rs index 3a0a2382be728..783f562d57908 100644 --- a/tests/ui-fulldeps/rustc_public/check_allocation.rs +++ b/tests/ui-fulldeps/rustc_public/check_allocation.rs @@ -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; diff --git a/tests/ui-fulldeps/rustc_public/check_defs.rs b/tests/ui-fulldeps/rustc_public/check_defs.rs index e6f9fb9972b0f..0d472e156b40f 100644 --- a/tests/ui-fulldeps/rustc_public/check_defs.rs +++ b/tests/ui-fulldeps/rustc_public/check_defs.rs @@ -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; diff --git a/tests/ui-fulldeps/rustc_public/check_foreign.rs b/tests/ui-fulldeps/rustc_public/check_foreign.rs index bd34fb5cf8a88..ea6d6585e51ec 100644 --- a/tests/ui-fulldeps/rustc_public/check_foreign.rs +++ b/tests/ui-fulldeps/rustc_public/check_foreign.rs @@ -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; diff --git a/tests/ui-fulldeps/rustc_public/check_intrinsics.rs b/tests/ui-fulldeps/rustc_public/check_intrinsics.rs index f722f0bbd7180..e3538a39f3371 100644 --- a/tests/ui-fulldeps/rustc_public/check_intrinsics.rs +++ b/tests/ui-fulldeps/rustc_public/check_intrinsics.rs @@ -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; diff --git a/tests/ui-fulldeps/rustc_public/crate-info.rs b/tests/ui-fulldeps/rustc_public/crate-info.rs index 06cbbfcd69ec7..9bf865c54eeef 100644 --- a/tests/ui-fulldeps/rustc_public/crate-info.rs +++ b/tests/ui-fulldeps/rustc_public/crate-info.rs @@ -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; diff --git a/tests/ui-fulldeps/rustc_public/projections.rs b/tests/ui-fulldeps/rustc_public/projections.rs index c1cdb5374d460..53baace827a02 100644 --- a/tests/ui-fulldeps/rustc_public/projections.rs +++ b/tests/ui-fulldeps/rustc_public/projections.rs @@ -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; diff --git a/tests/ui/coroutine/uninhabited-field.rs b/tests/ui/coroutine/uninhabited-field.rs index d6ada07ce0cbc..bc1f8d7733716 100644 --- a/tests/ui/coroutine/uninhabited-field.rs +++ b/tests/ui/coroutine/uninhabited-field.rs @@ -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; diff --git a/tests/ui/macros/assert-matches-macro-msg.rs b/tests/ui/macros/assert-matches-macro-msg.rs index 956bc9cf0f49b..8f4cd254f56b7 100644 --- a/tests/ui/macros/assert-matches-macro-msg.rs +++ b/tests/ui/macros/assert-matches-macro-msg.rs @@ -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"); diff --git a/tests/ui/stdlib-unit-tests/matches2021.rs b/tests/ui/stdlib-unit-tests/matches2021.rs index 78c8be7321362..c3276cd883471 100644 --- a/tests/ui/stdlib-unit-tests/matches2021.rs +++ b/tests/ui/stdlib-unit-tests/matches2021.rs @@ -5,7 +5,7 @@ #![feature(assert_matches)] -use std::assert_matches::assert_matches; +use std::assert_matches; fn main() { assert!(matches!((), ()));