diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs index d688331ae0a56..4a2e784311f72 100644 --- a/compiler/rustc_const_eval/src/lib.rs +++ b/compiler/rustc_const_eval/src/lib.rs @@ -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)] diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index fa2dad5ce25f0..8d0812c5cadff 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -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)] diff --git a/compiler/rustc_query_system/src/lib.rs b/compiler/rustc_query_system/src/lib.rs index 6b70e9342fa64..1c93a3e414eb5 100644 --- a/compiler/rustc_query_system/src/lib.rs +++ b/compiler/rustc_query_system/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(assert_matches)] #![feature(bool_to_option)] #![feature(core_intrinsics)] #![feature(hash_raw_entry)] diff --git a/library/alloc/tests/lib.rs b/library/alloc/tests/lib.rs index 16d3b36859570..fe35265bf3a02 100644 --- a/library/alloc/tests/lib.rs +++ b/library/alloc/tests/lib.rs @@ -1,6 +1,5 @@ #![feature(allocator_api)] #![feature(alloc_layout_extra)] -#![feature(assert_matches)] #![feature(box_syntax)] #![feature(cow_is_borrowed)] #![feature(const_box)] diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 6546a5244fd03..b58944bb50810 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -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}; } diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 83f33ca007af1..1c36aaa532b2e 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -126,8 +126,6 @@ macro_rules! assert_ne { /// # Examples /// /// ``` -/// #![feature(assert_matches)] -/// /// use std::assert_matches::assert_matches; /// /// let a = 1u32.checked_add(2); @@ -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 { @@ -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); @@ -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) { @@ -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) -> 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")] diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 91e4708f6a609..721d63df0d028 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -589,7 +589,7 @@ impl Option { /// 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")] diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 60e7c2af8e4a5..39659846babe8 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -299,7 +299,6 @@ #![feature(panic_unwind)] // // Only for re-exporting: -#![feature(assert_matches)] #![feature(async_iterator)] #![feature(c_size_t)] #![feature(c_variadic)] diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 0fcfabba4c0a1..1ae7e537633f6 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -4,7 +4,6 @@ )] #![feature(rustc_private)] #![feature(array_methods)] -#![feature(assert_matches)] #![feature(bool_to_option)] #![feature(box_patterns)] #![feature(control_flow_enum)] diff --git a/src/test/ui/macros/assert-matches-macro-msg.rs b/src/test/ui/macros/assert-matches-macro-msg.rs index fd8cd5a1a0566..23caf5441ca5f 100644 --- a/src/test/ui/macros/assert-matches-macro-msg.rs +++ b/src/test/ui/macros/assert-matches-macro-msg.rs @@ -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() { diff --git a/src/test/ui/stdlib-unit-tests/matches2021.rs b/src/test/ui/stdlib-unit-tests/matches2021.rs index 9143a8cdd59bc..ccbfabc4baf78 100644 --- a/src/test/ui/stdlib-unit-tests/matches2021.rs +++ b/src/test/ui/stdlib-unit-tests/matches2021.rs @@ -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() {