diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index dd04d3e548f8c..ab9ea2f3e91da 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -1,5 +1,4 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] -#![feature(assert_matches)] #![feature(bool_to_option)] #![feature(box_patterns)] #![feature(drain_filter)] diff --git a/compiler/rustc_middle/src/ich/impls_syntax.rs b/compiler/rustc_middle/src/ich/impls_syntax.rs index 31374429940ca..aacec86071197 100644 --- a/compiler/rustc_middle/src/ich/impls_syntax.rs +++ b/compiler/rustc_middle/src/ich/impls_syntax.rs @@ -45,11 +45,7 @@ impl<'ctx> rustc_ast::HashStableContext for StableHashingContext<'ctx> { item.hash_stable(self, hasher); style.hash_stable(self, hasher); span.hash_stable(self, hasher); - assert_matches!( - tokens.as_ref(), - None, - "Tokens should have been removed during lowering!" - ); + assert!(tokens.as_ref().is_none(), "Tokens should have been removed during lowering!"); } else { unreachable!(); } diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index 6ddc38b006687..49765166c871d 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -24,7 +24,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(array_windows)] -#![feature(assert_matches)] #![feature(backtrace)] #![feature(bool_to_option)] #![feature(box_patterns)] diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index 766d6a06f7e59..898c375e9ae1a 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -339,7 +339,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra> Allocation { for dest in bytes { *dest = src.next().expect("iterator was shorter than it said it would be"); } - assert_matches!(src.next(), None, "iterator was longer than it said it would be"); + assert!(src.next().is_none(), "iterator was longer than it said it would be"); Ok(()) } diff --git a/compiler/rustc_mir/src/interpret/memory.rs b/compiler/rustc_mir/src/interpret/memory.rs index fe5ebf0b6fe97..3648748a90908 100644 --- a/compiler/rustc_mir/src/interpret/memory.rs +++ b/compiler/rustc_mir/src/interpret/memory.rs @@ -854,11 +854,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { Some(ptr) => ptr, None => { // zero-sized access - assert_matches!( - src.next(), - None, - "iterator said it was empty but returned an element" - ); + assert!(src.next().is_none(), "iterator said it was empty but returned an element"); return Ok(()); } }; @@ -884,11 +880,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { Some(ptr) => ptr, None => { // zero-sized access - assert_matches!( - src.next(), - None, - "iterator said it was empty but returned an element" - ); + assert!(src.next().is_none(), "iterator said it was empty but returned an element"); return Ok(()); } }; @@ -902,7 +894,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { let offset_ptr = ptr.offset(Size::from_bytes(idx) * 2, &tcx)?; // `Size` multiplication allocation.write_scalar(&tcx, offset_ptr, val.into(), Size::from_bytes(2))?; } - assert_matches!(src.next(), None, "iterator was longer than it said it would be"); + assert!(src.next().is_none(), "iterator was longer than it said it would be"); Ok(()) } diff --git a/compiler/rustc_mir/src/lib.rs b/compiler/rustc_mir/src/lib.rs index f73d5dc0c116d..bf4eeb408ec84 100644 --- a/compiler/rustc_mir/src/lib.rs +++ b/compiler/rustc_mir/src/lib.rs @@ -7,7 +7,6 @@ Rust MIR: a lowered representation of Rust. #![feature(nll)] #![feature(in_band_lifetimes)] #![feature(array_windows)] -#![feature(assert_matches)] #![feature(bindings_after_at)] #![feature(bool_to_option)] #![feature(box_patterns)] diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 99894b5605e6d..a0a8eecbc2527 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -110,60 +110,6 @@ macro_rules! assert_ne { }); } -/// Asserts that an expression matches any of the given patterns. -/// -/// Like in a `match` expression, the pattern can be optionally followed by `if` -/// and a guard expression that has access to names bound by the pattern. -/// -/// 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. -/// -/// # Examples -/// -/// ``` -/// #![feature(assert_matches)] -/// -/// let a = 1u32.checked_add(2); -/// let b = 1u32.checked_sub(2); -/// assert_matches!(a, Some(_)); -/// assert_matches!(b, None); -/// -/// let c = Ok("abc".to_string()); -/// assert_matches!(c, Ok(x) | Err(x) if x.len() < 100); -/// ``` -#[macro_export] -#[unstable(feature = "assert_matches", issue = "82775")] -#[allow_internal_unstable(core_panic)] -macro_rules! assert_matches { - ($left:expr, $( $pattern:pat )|+ $( if $guard: expr )? $(,)?) => ({ - match $left { - $( $pattern )|+ $( if $guard )? => {} - ref left_val => { - $crate::panicking::assert_matches_failed( - left_val, - $crate::stringify!($($pattern)|+ $(if $guard)?), - $crate::option::Option::None - ); - } - } - }); - ($left:expr, $( $pattern:pat )|+ $( if $guard: expr )?, $($arg:tt)+) => ({ - match $left { - $( $pattern )|+ $( if $guard )? => {} - ref left_val => { - $crate::panicking::assert_matches_failed( - left_val, - $crate::stringify!($($pattern)|+ $(if $guard)?), - $crate::option::Option::Some($crate::format_args!($($arg)+)) - ); - } - } - }); -} - /// Asserts that a boolean expression is `true` at runtime. /// /// This will invoke the [`panic!`] macro if the provided expression cannot be @@ -262,42 +208,6 @@ macro_rules! debug_assert_ne { ($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_ne!($($arg)*); }) } -/// Asserts that an expression matches any of the given patterns. -/// -/// Like in a `match` expression, the pattern can be optionally followed by `if` -/// and a guard expression that has access to names bound by the pattern. -/// -/// On panic, this macro will print the value of the expression with its -/// debug representation. -/// -/// Unlike [`assert_matches!`], `debug_assert_matches!` statements are only -/// enabled in non optimized builds by default. An optimized build will not -/// execute `debug_assert_matches!` statements unless `-C debug-assertions` is -/// passed to the compiler. This makes `debug_assert_matches!` useful for -/// checks that are too expensive to be present in a release build but may be -/// helpful during development. The result of expanding `debug_assert_matches!` -/// is always type checked. -/// -/// # Examples -/// -/// ``` -/// #![feature(assert_matches)] -/// -/// let a = 1u32.checked_add(2); -/// let b = 1u32.checked_sub(2); -/// debug_assert_matches!(a, Some(_)); -/// debug_assert_matches!(b, None); -/// -/// let c = Ok("abc".to_string()); -/// 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)] -macro_rules! debug_assert_matches { - ($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_matches!($($arg)*); }) -} - /// Returns whether the given expression matches any of the given patterns. /// /// Like in a `match` expression, the pattern can be optionally followed by `if` diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index 3e3e96fcd7f78..35d9b2c5d267f 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -97,7 +97,6 @@ pub fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! { pub enum AssertKind { Eq, Ne, - Match, } /// Internal function for `assert_eq!` and `assert_ne!` macros @@ -114,54 +113,32 @@ where T: fmt::Debug + ?Sized, U: fmt::Debug + ?Sized, { - assert_failed_inner(kind, &left, &right, args) -} - -/// Internal function for `assert_match!` -#[cold] -#[track_caller] -#[doc(hidden)] -pub fn assert_matches_failed( - left: &T, - right: &str, - args: Option>, -) -> ! { - // Use the Display implementation to display the pattern. - struct Pattern<'a>(&'a str); - impl fmt::Debug for Pattern<'_> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(self.0, f) - } - } - assert_failed_inner(AssertKind::Match, &left, &Pattern(right), args); -} - -/// Non-generic version of the above functions, to avoid code bloat. -#[track_caller] -fn assert_failed_inner( - kind: AssertKind, - left: &dyn fmt::Debug, - right: &dyn fmt::Debug, - args: Option>, -) -> ! { - let op = match kind { - AssertKind::Eq => "==", - AssertKind::Ne => "!=", - AssertKind::Match => "matches", - }; - - match args { - Some(args) => panic!( - r#"assertion failed: `(left {} right)` + #[track_caller] + fn inner( + kind: AssertKind, + left: &dyn fmt::Debug, + right: &dyn fmt::Debug, + args: Option>, + ) -> ! { + let op = match kind { + AssertKind::Eq => "==", + AssertKind::Ne => "!=", + }; + + match args { + Some(args) => panic!( + r#"assertion failed: `(left {} right)` left: `{:?}`, right: `{:?}`: {}"#, - op, left, right, args - ), - None => panic!( - r#"assertion failed: `(left {} right)` + op, left, right, args + ), + None => panic!( + r#"assertion failed: `(left {} right)` left: `{:?}`, right: `{:?}`"#, - op, left, right, - ), + op, left, right, + ), + } } + inner(kind, &left, &right, args) } diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 8149858e10338..1f53a4c783c7a 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -228,7 +228,6 @@ #![feature(arbitrary_self_types)] #![feature(array_error_internals)] #![feature(asm)] -#![feature(assert_matches)] #![feature(associated_type_bounds)] #![feature(atomic_mut_ptr)] #![feature(box_syntax)] @@ -559,8 +558,8 @@ pub use std_detect::detect; #[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated, deprecated_in_future)] pub use core::{ - assert_eq, assert_matches, assert_ne, debug_assert, debug_assert_eq, debug_assert_matches, - debug_assert_ne, matches, r#try, todo, unimplemented, unreachable, write, writeln, + assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, matches, r#try, todo, + unimplemented, unreachable, write, writeln, }; // Re-export built-in macros defined through libcore. diff --git a/src/test/ui/macros/assert-matches-macro-msg.rs b/src/test/ui/macros/assert-matches-macro-msg.rs deleted file mode 100644 index 43be9532f5d1c..0000000000000 --- a/src/test/ui/macros/assert-matches-macro-msg.rs +++ /dev/null @@ -1,11 +0,0 @@ -// run-fail -// error-pattern:panicked at 'assertion failed: `(left matches right)` -// error-pattern: left: `2` -// error-pattern:right: `3`: 1 + 1 definitely should be 3' -// ignore-emscripten no processes - -#![feature(assert_matches)] - -fn main() { - assert_matches!(1 + 1, 3, "1 + 1 definitely should be 3"); -}