Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a5acb7b

Browse files
authoredJul 15, 2021
Rollup merge of #86947 - m-ou-se:assert-matches-to-submodule, r=yaahc
Move assert_matches to an inner module Fixes #82913
2 parents 9813013 + e304443 commit a5acb7b

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
@@ -127,6 +127,8 @@ macro_rules! assert_ne {
127127
/// ```
128128
/// #![feature(assert_matches)]
129129
///
130+
/// use std::assert::assert_matches;
131+
///
130132
/// let a = 1u32.checked_add(2);
131133
/// let b = 1u32.checked_sub(2);
132134
/// assert_matches!(a, Some(_));
@@ -135,10 +137,10 @@ macro_rules! assert_ne {
135137
/// let c = Ok("abc".to_string());
136138
/// assert_matches!(c, Ok(x) | Err(x) if x.len() < 100);
137139
/// ```
138-
#[macro_export]
139140
#[unstable(feature = "assert_matches", issue = "82775")]
140141
#[allow_internal_unstable(core_panic)]
141-
macro_rules! assert_matches {
142+
#[rustc_macro_transparency = "semitransparent"]
143+
pub macro assert_matches {
142144
($left:expr, $( $pattern:pat_param )|+ $( if $guard: expr )? $(,)?) => ({
143145
match $left {
144146
$( $pattern )|+ $( if $guard )? => {}
@@ -150,7 +152,7 @@ macro_rules! assert_matches {
150152
);
151153
}
152154
}
153-
});
155+
}),
154156
($left:expr, $( $pattern:pat_param )|+ $( if $guard: expr )?, $($arg:tt)+) => ({
155157
match $left {
156158
$( $pattern )|+ $( if $guard )? => {}
@@ -162,7 +164,7 @@ macro_rules! assert_matches {
162164
);
163165
}
164166
}
165-
});
167+
}),
166168
}
167169

168170
/// Asserts that a boolean expression is `true` at runtime.
@@ -284,6 +286,8 @@ macro_rules! debug_assert_ne {
284286
/// ```
285287
/// #![feature(assert_matches)]
286288
///
289+
/// use std::assert::debug_assert_matches;
290+
///
287291
/// let a = 1u32.checked_add(2);
288292
/// let b = 1u32.checked_sub(2);
289293
/// debug_assert_matches!(a, Some(_));
@@ -295,8 +299,9 @@ macro_rules! debug_assert_ne {
295299
#[macro_export]
296300
#[unstable(feature = "assert_matches", issue = "82775")]
297301
#[allow_internal_unstable(assert_matches)]
298-
macro_rules! debug_assert_matches {
299-
($($arg:tt)*) => (if $crate::cfg!(debug_assertions) { $crate::assert_matches!($($arg)*); })
302+
#[rustc_macro_transparency = "semitransparent"]
303+
pub macro debug_assert_matches($($arg:tt)*) {
304+
if $crate::cfg!(debug_assertions) { $crate::assert::assert_matches!($($arg)*); }
300305
}
301306

302307
/// 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)
Failed to load comments.