Skip to content

Commit 4923e56

Browse files
Revert "Add assert_matches!(expr, pat)."
This reverts commit eb18746.
1 parent 9a1dfd2 commit 4923e56

File tree

3 files changed

+25
-103
lines changed

3 files changed

+25
-103
lines changed

library/core/src/macros/mod.rs

-54
Original file line numberDiff line numberDiff line change
@@ -110,60 +110,6 @@ macro_rules! assert_ne {
110110
});
111111
}
112112

113-
/// Asserts that an expression matches any of the given patterns.
114-
///
115-
/// Like in a `match` expression, the pattern can be optionally followed by `if`
116-
/// and a guard expression that has access to names bound by the pattern.
117-
///
118-
/// On panic, this macro will print the value of the expression with its
119-
/// debug representation.
120-
///
121-
/// Like [`assert!`], this macro has a second form, where a custom
122-
/// panic message can be provided.
123-
///
124-
/// # Examples
125-
///
126-
/// ```
127-
/// #![feature(assert_matches)]
128-
///
129-
/// let a = 1u32.checked_add(2);
130-
/// let b = 1u32.checked_sub(2);
131-
/// assert_matches!(a, Some(_));
132-
/// assert_matches!(b, None);
133-
///
134-
/// let c = Ok("abc".to_string());
135-
/// assert_matches!(c, Ok(x) | Err(x) if x.len() < 100);
136-
/// ```
137-
#[macro_export]
138-
#[unstable(feature = "assert_matches", issue = "82775")]
139-
#[allow_internal_unstable(core_panic)]
140-
macro_rules! assert_matches {
141-
($left:expr, $( $pattern:pat )|+ $( if $guard: expr )? $(,)?) => ({
142-
match $left {
143-
$( $pattern )|+ $( if $guard )? => {}
144-
ref left_val => {
145-
$crate::panicking::assert_matches_failed(
146-
left_val,
147-
$crate::stringify!($($pattern)|+ $(if $guard)?),
148-
$crate::option::Option::None
149-
);
150-
}
151-
}
152-
});
153-
($left:expr, $( $pattern:pat )|+ $( if $guard: expr )?, $($arg:tt)+) => ({
154-
match $left {
155-
$( $pattern )|+ $( if $guard )? => {}
156-
ref left_val => {
157-
$crate::panicking::assert_matches_failed(
158-
left_val,
159-
$crate::stringify!($($pattern)|+ $(if $guard)?),
160-
$crate::option::Option::Some($crate::format_args!($($arg)+))
161-
);
162-
}
163-
}
164-
});
165-
}
166-
167113
/// Asserts that a boolean expression is `true` at runtime.
168114
///
169115
/// This will invoke the [`panic!`] macro if the provided expression cannot be

library/core/src/panicking.rs

+23-46
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ pub fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
9797
pub enum AssertKind {
9898
Eq,
9999
Ne,
100-
Match,
101100
}
102101

103102
/// Internal function for `assert_eq!` and `assert_ne!` macros
@@ -114,54 +113,32 @@ where
114113
T: fmt::Debug + ?Sized,
115114
U: fmt::Debug + ?Sized,
116115
{
117-
assert_failed_inner(kind, &left, &right, args)
118-
}
119-
120-
/// Internal function for `assert_match!`
121-
#[cold]
122-
#[track_caller]
123-
#[doc(hidden)]
124-
pub fn assert_matches_failed<T: fmt::Debug + ?Sized>(
125-
left: &T,
126-
right: &str,
127-
args: Option<fmt::Arguments<'_>>,
128-
) -> ! {
129-
// Use the Display implementation to display the pattern.
130-
struct Pattern<'a>(&'a str);
131-
impl fmt::Debug for Pattern<'_> {
132-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
133-
fmt::Display::fmt(self.0, f)
134-
}
135-
}
136-
assert_failed_inner(AssertKind::Match, &left, &Pattern(right), args);
137-
}
138-
139-
/// Non-generic version of the above functions, to avoid code bloat.
140-
#[track_caller]
141-
fn assert_failed_inner(
142-
kind: AssertKind,
143-
left: &dyn fmt::Debug,
144-
right: &dyn fmt::Debug,
145-
args: Option<fmt::Arguments<'_>>,
146-
) -> ! {
147-
let op = match kind {
148-
AssertKind::Eq => "==",
149-
AssertKind::Ne => "!=",
150-
AssertKind::Match => "matches",
151-
};
152-
153-
match args {
154-
Some(args) => panic!(
155-
r#"assertion failed: `(left {} right)`
116+
#[track_caller]
117+
fn inner(
118+
kind: AssertKind,
119+
left: &dyn fmt::Debug,
120+
right: &dyn fmt::Debug,
121+
args: Option<fmt::Arguments<'_>>,
122+
) -> ! {
123+
let op = match kind {
124+
AssertKind::Eq => "==",
125+
AssertKind::Ne => "!=",
126+
};
127+
128+
match args {
129+
Some(args) => panic!(
130+
r#"assertion failed: `(left {} right)`
156131
left: `{:?}`,
157132
right: `{:?}`: {}"#,
158-
op, left, right, args
159-
),
160-
None => panic!(
161-
r#"assertion failed: `(left {} right)`
133+
op, left, right, args
134+
),
135+
None => panic!(
136+
r#"assertion failed: `(left {} right)`
162137
left: `{:?}`,
163138
right: `{:?}`"#,
164-
op, left, right,
165-
),
139+
op, left, right,
140+
),
141+
}
166142
}
143+
inner(kind, &left, &right, args)
167144
}

library/std/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@
228228
#![feature(arbitrary_self_types)]
229229
#![feature(array_error_internals)]
230230
#![feature(asm)]
231-
#![feature(assert_matches)]
232231
#![feature(associated_type_bounds)]
233232
#![feature(atomic_mut_ptr)]
234233
#![feature(box_syntax)]
@@ -559,8 +558,8 @@ pub use std_detect::detect;
559558
#[stable(feature = "rust1", since = "1.0.0")]
560559
#[allow(deprecated, deprecated_in_future)]
561560
pub use core::{
562-
assert_eq, assert_matches, assert_ne, debug_assert, debug_assert_eq, debug_assert_matches,
563-
debug_assert_ne, matches, r#try, todo, unimplemented, unreachable, write, writeln,
561+
assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_matches, debug_assert_ne,
562+
matches, r#try, todo, unimplemented, unreachable, write, writeln,
564563
};
565564

566565
// Re-export built-in macros defined through libcore.

0 commit comments

Comments
 (0)