Skip to content

Stabilize assert_matches #95886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
1 change: 0 additions & 1 deletion compiler/rustc_const_eval/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Rust MIR: a lowered representation of Rust.

*/

#![feature(assert_matches)]
#![feature(bool_to_option)]
#![feature(box_patterns)]
#![feature(control_flow_enum)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(allocator_api)]
#![feature(array_windows)]
#![feature(assert_matches)]
#![feature(backtrace)]
#![feature(bool_to_option)]
#![feature(box_patterns)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_query_system/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(assert_matches)]
#![feature(bool_to_option)]
#![feature(core_intrinsics)]
#![feature(hash_raw_entry)]
Expand Down
1 change: 0 additions & 1 deletion library/alloc/tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![feature(allocator_api)]
#![feature(alloc_layout_extra)]
#![feature(assert_matches)]
#![feature(box_syntax)]
#![feature(cow_is_borrowed)]
#![feature(const_box)]
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ mod 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.
#[stable(feature = "assert_matches", since = "1.62.0")]
/// Module containing the `assert_matches` macro.
pub mod assert_matches {
#[unstable(feature = "assert_matches", issue = "82775")]
#[stable(feature = "assert_matches", since = "1.62.0")]
pub use crate::macros::{assert_matches, debug_assert_matches};
}

Expand Down
23 changes: 12 additions & 11 deletions library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ macro_rules! assert_ne {
/// # Examples
///
/// ```
/// #![feature(assert_matches)]
///
/// use std::assert_matches::assert_matches;
///
/// let a = 1u32.checked_add(2);
Expand All @@ -138,7 +136,7 @@ macro_rules! assert_ne {
/// let c = Ok("abc".to_string());
/// assert_matches!(c, Ok(x) | Err(x) if x.len() < 100);
/// ```
#[unstable(feature = "assert_matches", issue = "82775")]
#[stable(feature = "assert_matches", since = "1.62.0")]
#[allow_internal_unstable(core_panic)]
#[rustc_macro_transparency = "semitransparent"]
pub macro assert_matches {
Expand Down Expand Up @@ -300,8 +298,6 @@ macro_rules! debug_assert_ne {
/// # Examples
///
/// ```
/// #![feature(assert_matches)]
///
/// use std::assert_matches::debug_assert_matches;
///
/// let a = 1u32.checked_add(2);
Expand All @@ -313,8 +309,7 @@ macro_rules! debug_assert_ne {
/// debug_assert_matches!(c, Ok(x) | Err(x) if x.len() < 100);
/// ```
#[macro_export]
#[unstable(feature = "assert_matches", issue = "82775")]
#[allow_internal_unstable(assert_matches)]
#[stable(feature = "assert_matches", since = "1.62.0")]
#[rustc_macro_transparency = "semitransparent"]
pub macro debug_assert_matches($($arg:tt)*) {
if $crate::cfg!(debug_assertions) {
Expand All @@ -330,12 +325,18 @@ pub macro debug_assert_matches($($arg:tt)*) {
/// # Examples
///
/// ```
/// let foo = 'f';
/// assert!(matches!(foo, 'A'..='Z' | 'a'..='z'));
/// /// Checks if the value is an ASCII alphabetic character.
/// fn is_ascii_alphabetic(c: char) -> bool {
/// matches!(c, 'A'..='Z' | 'a'..='z')
/// }
///
/// let bar = Some(4);
/// assert!(matches!(bar, Some(x) if x > 2));
/// /// Returns whether the given Option contains a value AND that value is positive.
/// fn is_some_positive(op: Option<i32>) -> bool {
/// matches!(op, Some(x) if x > 0)
/// }
/// ```
///
/// See also [`assert_matches!`] and [`debug_assert_matches!`].
#[macro_export]
#[stable(feature = "matches_macro", since = "1.42.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "matches_macro")]
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ impl<T> Option<T> {
/// assert_eq!(x.is_none(), true);
/// ```
#[must_use = "if you intended to assert that this doesn't have a value, consider \
`.and_then(|_| panic!(\"`Option` had a value when expected `None`\"))` instead"]
`assert_matches!(x, None)` instead"]
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_option_basics", since = "1.48.0")]
Expand Down
1 change: 0 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@
#![feature(panic_unwind)]
//
// Only for re-exporting:
#![feature(assert_matches)]
#![feature(async_iterator)]
#![feature(c_size_t)]
#![feature(c_variadic)]
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
)]
#![feature(rustc_private)]
#![feature(array_methods)]
#![feature(assert_matches)]
#![feature(bool_to_option)]
#![feature(box_patterns)]
#![feature(control_flow_enum)]
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/macros/assert-matches-macro-msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
// error-pattern:right: `3`: 1 + 1 definitely should be 3'
// ignore-emscripten no processes

#![feature(assert_matches)]

use std::assert_matches::assert_matches;

fn main() {
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/stdlib-unit-tests/matches2021.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

// regression test for https://github.com/rust-lang/rust/pull/85678

#![feature(assert_matches)]

use std::assert_matches::assert_matches;

fn main() {
Expand Down