Rollup merge of #82770 - m-ou-se:assert-match, r=joshtriplett
Add assert_matches macro. This adds `assert_matches!(expression, pattern)`. Unlike the other asserts, this one ~~consumes the expression~~ may consume the expression, to be able to match the pattern. (It could add a `&` implicitly, but that's noticable in the pattern, and will make a consuming guard impossible.) See https://github.com/rust-lang/rust/issues/62633#issuecomment-790737853 This re-uses the same `left: .. right: ..` output as the `assert_eq` and `assert_ne` macros, but with the pattern as the right part: assert_eq: ``` assertion failed: `(left == right)` left: `Some("asdf")`, right: `None` ``` assert_matches: ``` assertion failed: `(left matches right)` left: `Ok("asdf")`, right: `Err(_)` ``` cc ```@cuviper```
This commit is contained in:
commit
04045cc83f
3 changed files with 141 additions and 27 deletions
|
@ -228,6 +228,7 @@
|
|||
#![feature(arbitrary_self_types)]
|
||||
#![feature(array_error_internals)]
|
||||
#![feature(asm)]
|
||||
#![feature(assert_matches)]
|
||||
#![feature(associated_type_bounds)]
|
||||
#![feature(atomic_mut_ptr)]
|
||||
#![feature(box_syntax)]
|
||||
|
@ -552,8 +553,8 @@ pub use std_detect::detect;
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow(deprecated, deprecated_in_future)]
|
||||
pub use core::{
|
||||
assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, matches, r#try, todo,
|
||||
unimplemented, unreachable, write, writeln,
|
||||
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,
|
||||
};
|
||||
|
||||
// Re-export built-in macros defined through libcore.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue