Move [debug_]assert_matches to mod {core, std}::assert.
This commit is contained in:
parent
c5e344f774
commit
e3044432c7
9 changed files with 36 additions and 15 deletions
|
@ -6,6 +6,7 @@ use crate::ich::StableHashingContext;
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_span::{BytePos, NormalizedPos, SourceFile};
|
use rustc_span::{BytePos, NormalizedPos, SourceFile};
|
||||||
|
use std::assert::assert_matches;
|
||||||
|
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
//! integer. It is crucial that these operations call `check_align` *before*
|
//! integer. It is crucial that these operations call `check_align` *before*
|
||||||
//! short-circuiting the empty case!
|
//! short-circuiting the empty case!
|
||||||
|
|
||||||
|
use std::assert::assert_matches;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::convert::{TryFrom, TryInto};
|
use std::convert::{TryFrom, TryInto};
|
||||||
|
|
|
@ -179,6 +179,16 @@ use prelude::v1::*;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod macros;
|
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.
|
||||||
|
pub mod assert {
|
||||||
|
#[unstable(feature = "assert_matches", issue = "82775")]
|
||||||
|
pub use crate::macros::{assert_matches, debug_assert_matches};
|
||||||
|
}
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod internal_macros;
|
mod internal_macros;
|
||||||
|
|
||||||
|
|
|
@ -126,6 +126,8 @@ macro_rules! assert_ne {
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(assert_matches)]
|
/// #![feature(assert_matches)]
|
||||||
///
|
///
|
||||||
|
/// use std::assert::assert_matches;
|
||||||
|
///
|
||||||
/// let a = 1u32.checked_add(2);
|
/// let a = 1u32.checked_add(2);
|
||||||
/// let b = 1u32.checked_sub(2);
|
/// let b = 1u32.checked_sub(2);
|
||||||
/// assert_matches!(a, Some(_));
|
/// assert_matches!(a, Some(_));
|
||||||
|
@ -134,10 +136,10 @@ macro_rules! assert_ne {
|
||||||
/// let c = Ok("abc".to_string());
|
/// let c = Ok("abc".to_string());
|
||||||
/// assert_matches!(c, Ok(x) | Err(x) if x.len() < 100);
|
/// assert_matches!(c, Ok(x) | Err(x) if x.len() < 100);
|
||||||
/// ```
|
/// ```
|
||||||
#[macro_export]
|
|
||||||
#[unstable(feature = "assert_matches", issue = "82775")]
|
#[unstable(feature = "assert_matches", issue = "82775")]
|
||||||
#[allow_internal_unstable(core_panic)]
|
#[allow_internal_unstable(core_panic)]
|
||||||
macro_rules! assert_matches {
|
#[rustc_macro_transparency = "semitransparent"]
|
||||||
|
pub macro assert_matches {
|
||||||
($left:expr, $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => ({
|
($left:expr, $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => ({
|
||||||
match $left {
|
match $left {
|
||||||
$( $pattern )|+ $( if $guard )? => {}
|
$( $pattern )|+ $( if $guard )? => {}
|
||||||
|
@ -149,7 +151,7 @@ macro_rules! assert_matches {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}),
|
||||||
($left:expr, $( $pattern:pat_param )|+ $( if $guard: expr )?, $($arg:tt)+) => ({
|
($left:expr, $( $pattern:pat_param )|+ $( if $guard: expr )?, $($arg:tt)+) => ({
|
||||||
match $left {
|
match $left {
|
||||||
$( $pattern )|+ $( if $guard )? => {}
|
$( $pattern )|+ $( if $guard )? => {}
|
||||||
|
@ -161,7 +163,7 @@ macro_rules! assert_matches {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Asserts that a boolean expression is `true` at runtime.
|
/// Asserts that a boolean expression is `true` at runtime.
|
||||||
|
@ -283,6 +285,8 @@ macro_rules! debug_assert_ne {
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(assert_matches)]
|
/// #![feature(assert_matches)]
|
||||||
///
|
///
|
||||||
|
/// use std::assert::debug_assert_matches;
|
||||||
|
///
|
||||||
/// let a = 1u32.checked_add(2);
|
/// let a = 1u32.checked_add(2);
|
||||||
/// let b = 1u32.checked_sub(2);
|
/// let b = 1u32.checked_sub(2);
|
||||||
/// debug_assert_matches!(a, Some(_));
|
/// debug_assert_matches!(a, Some(_));
|
||||||
|
@ -294,8 +298,9 @@ macro_rules! debug_assert_ne {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[unstable(feature = "assert_matches", issue = "82775")]
|
#[unstable(feature = "assert_matches", issue = "82775")]
|
||||||
#[allow_internal_unstable(assert_matches)]
|
#[allow_internal_unstable(assert_matches)]
|
||||||
macro_rules! debug_assert_matches {
|
#[rustc_macro_transparency = "semitransparent"]
|
||||||
($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_matches!($($arg)*); })
|
pub macro debug_assert_matches($($arg:tt)*) {
|
||||||
|
if $crate::cfg!(debug_assertions) { $crate::assert::assert_matches!($($arg)*); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether the given expression matches any of the given patterns.
|
/// Returns whether the given expression matches any of the given patterns.
|
||||||
|
|
|
@ -548,8 +548,8 @@ pub use std_detect::{
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[allow(deprecated, deprecated_in_future)]
|
#[allow(deprecated, deprecated_in_future)]
|
||||||
pub use core::{
|
pub use core::{
|
||||||
assert_eq, assert_matches, assert_ne, debug_assert, debug_assert_eq, debug_assert_matches,
|
assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, matches, r#try, todo,
|
||||||
debug_assert_ne, matches, r#try, todo, unimplemented, unreachable, write, writeln,
|
unimplemented, unreachable, write, writeln,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Re-export built-in macros defined through libcore.
|
// Re-export built-in macros defined through libcore.
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
#![feature(assert_matches)]
|
#![feature(assert_matches)]
|
||||||
|
|
||||||
|
use std::assert::assert_matches;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
assert_matches!(1 + 1, 3, "1 + 1 definitely should be 3");
|
assert_matches!(1 + 1, 3, "1 + 1 definitely should be 3");
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
#![feature(assert_matches)]
|
#![feature(assert_matches)]
|
||||||
|
|
||||||
|
use std::assert::assert_matches;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
assert!(matches!((), ()));
|
assert!(matches!((), ()));
|
||||||
assert_matches!((), ());
|
assert_matches!((), ());
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
assert(true);
|
assert_eq(1, 1);
|
||||||
//~^ ERROR expected function, found macro `assert`
|
//~^ ERROR expected function, found macro `assert_eq`
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
error[E0423]: expected function, found macro `assert`
|
error[E0423]: expected function, found macro `assert_eq`
|
||||||
--> $DIR/resolve-hint-macro.rs:2:5
|
--> $DIR/resolve-hint-macro.rs:2:5
|
||||||
|
|
|
|
||||||
LL | assert(true);
|
LL | assert_eq(1, 1);
|
||||||
| ^^^^^^ not a function
|
| ^^^^^^^^^ not a function
|
||||||
|
|
|
|
||||||
help: use `!` to invoke the macro
|
help: use `!` to invoke the macro
|
||||||
|
|
|
|
||||||
LL | assert!(true);
|
LL | assert_eq!(1, 1);
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue