Skip to content

Commit e304443

Browse files
committed
Move [debug_]assert_matches to mod {core, std}::assert.
1 parent c5e344f commit e304443

File tree

9 files changed

+36
-15
lines changed

9 files changed

+36
-15
lines changed

compiler/rustc_middle/src/ich/impls_syntax.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::ich::StableHashingContext;
66
use rustc_ast as ast;
77
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
88
use rustc_span::{BytePos, NormalizedPos, SourceFile};
9+
use std::assert::assert_matches;
910

1011
use smallvec::SmallVec;
1112

compiler/rustc_mir/src/interpret/memory.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//! integer. It is crucial that these operations call `check_align` *before*
77
//! short-circuiting the empty case!
88
9+
use std::assert::assert_matches;
910
use std::borrow::Cow;
1011
use std::collections::VecDeque;
1112
use std::convert::{TryFrom, TryInto};

library/core/src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,16 @@ use prelude::v1::*;
179179
#[macro_use]
180180
mod macros;
181181

182+
// We don't export this through #[macro_export] for now, to avoid breakage.
183+
// See https://github.com/rust-lang/rust/issues/82913
184+
#[cfg(not(test))]
185+
#[unstable(feature = "assert_matches", issue = "82775")]
186+
/// Unstable module containing the unstable `assert_matches` macro.
187+
pub mod assert {
188+
#[unstable(feature = "assert_matches", issue = "82775")]
189+
pub use crate::macros::{assert_matches, debug_assert_matches};
190+
}
191+
182192
#[macro_use]
183193
mod internal_macros;
184194

library/core/src/macros/mod.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ macro_rules! assert_ne {
126126
/// ```
127127
/// #![feature(assert_matches)]
128128
///
129+
/// use std::assert::assert_matches;
130+
///
129131
/// let a = 1u32.checked_add(2);
130132
/// let b = 1u32.checked_sub(2);
131133
/// assert_matches!(a, Some(_));
@@ -134,10 +136,10 @@ macro_rules! assert_ne {
134136
/// let c = Ok("abc".to_string());
135137
/// assert_matches!(c, Ok(x) | Err(x) if x.len() < 100);
136138
/// ```
137-
#[macro_export]
138139
#[unstable(feature = "assert_matches", issue = "82775")]
139140
#[allow_internal_unstable(core_panic)]
140-
macro_rules! assert_matches {
141+
#[rustc_macro_transparency = "semitransparent"]
142+
pub macro assert_matches {
141143
($left:expr, $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => ({
142144
match $left {
143145
$( $pattern )|+ $( if $guard )? => {}
@@ -149,7 +151,7 @@ macro_rules! assert_matches {
149151
);
150152
}
151153
}
152-
});
154+
}),
153155
($left:expr, $( $pattern:pat_param )|+ $( if $guard: expr )?, $($arg:tt)+) => ({
154156
match $left {
155157
$( $pattern )|+ $( if $guard )? => {}
@@ -161,7 +163,7 @@ macro_rules! assert_matches {
161163
);
162164
}
163165
}
164-
});
166+
}),
165167
}
166168

167169
/// Asserts that a boolean expression is `true` at runtime.
@@ -283,6 +285,8 @@ macro_rules! debug_assert_ne {
283285
/// ```
284286
/// #![feature(assert_matches)]
285287
///
288+
/// use std::assert::debug_assert_matches;
289+
///
286290
/// let a = 1u32.checked_add(2);
287291
/// let b = 1u32.checked_sub(2);
288292
/// debug_assert_matches!(a, Some(_));
@@ -294,8 +298,9 @@ macro_rules! debug_assert_ne {
294298
#[macro_export]
295299
#[unstable(feature = "assert_matches", issue = "82775")]
296300
#[allow_internal_unstable(assert_matches)]
297-
macro_rules! debug_assert_matches {
298-
($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_matches!($($arg)*); })
301+
#[rustc_macro_transparency = "semitransparent"]
302+
pub macro debug_assert_matches($($arg:tt)*) {
303+
if $crate::cfg!(debug_assertions) { $crate::assert::assert_matches!($($arg)*); }
299304
}
300305

301306
/// Returns whether the given expression matches any of the given patterns.

library/std/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ pub use std_detect::{
548548
#[stable(feature = "rust1", since = "1.0.0")]
549549
#[allow(deprecated, deprecated_in_future)]
550550
pub use core::{
551-
assert_eq, assert_matches, assert_ne, debug_assert, debug_assert_eq, debug_assert_matches,
552-
debug_assert_ne, matches, r#try, todo, unimplemented, unreachable, write, writeln,
551+
assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, matches, r#try, todo,
552+
unimplemented, unreachable, write, writeln,
553553
};
554554

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

src/test/ui/macros/assert-matches-macro-msg.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#![feature(assert_matches)]
88

9+
use std::assert::assert_matches;
10+
911
fn main() {
1012
assert_matches!(1 + 1, 3, "1 + 1 definitely should be 3");
1113
}

src/test/ui/matches2021.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#![feature(assert_matches)]
88

9+
use std::assert::assert_matches;
10+
911
fn main() {
1012
assert!(matches!((), ()));
1113
assert_matches!((), ());
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
fn main() {
2-
assert(true);
3-
//~^ ERROR expected function, found macro `assert`
2+
assert_eq(1, 1);
3+
//~^ ERROR expected function, found macro `assert_eq`
44
}

src/test/ui/resolve/resolve-hint-macro.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
error[E0423]: expected function, found macro `assert`
1+
error[E0423]: expected function, found macro `assert_eq`
22
--> $DIR/resolve-hint-macro.rs:2:5
33
|
4-
LL | assert(true);
5-
| ^^^^^^ not a function
4+
LL | assert_eq(1, 1);
5+
| ^^^^^^^^^ not a function
66
|
77
help: use `!` to invoke the macro
88
|
9-
LL | assert!(true);
10-
| ^
9+
LL | assert_eq!(1, 1);
10+
| ^
1111

1212
error: aborting due to previous error
1313

0 commit comments

Comments
 (0)