Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/collections/btree/map/tests.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 1 addition & 1 deletion library/alloctests/tests/c_str2.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion library/alloctests/tests/str.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
3 changes: 1 addition & 2 deletions library/alloctests/tests/string.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions library/alloctests/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ 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::*;
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;

Expand Down
2 changes: 1 addition & 1 deletion library/alloctests/tests/vec_deque.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 1 addition & 5 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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)*);
}
}

Expand Down
2 changes: 1 addition & 1 deletion library/std/src/collections/hash/map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions library/std/src/fs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) => {
Expand Down
3 changes: 1 addition & 2 deletions library/std/src/io/error/tests.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
8 changes: 5 additions & 3 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/pal/unix/linux/pidfd/tests.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/process/unix/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
_ => {
Expand Down
5 changes: 4 additions & 1 deletion src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
3 changes: 3 additions & 0 deletions src/tools/clippy/clippy_utils/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/rustc_public/check_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/rustc_public/check_allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/rustc_public/check_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/rustc_public/check_foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/rustc_public/check_intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/rustc_public/crate-info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/rustc_public/projections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/coroutine/uninhabited-field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/macros/assert-matches-macro-msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/stdlib-unit-tests/matches2021.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#![feature(assert_matches)]

use std::assert_matches::assert_matches;
use std::assert_matches;

fn main() {
assert!(matches!((), ()));
Expand Down
Loading