Skip to content

Commit 27c0731

Browse files
committed
Move debug_assert_matches back to its kin
Needed for doc intra links
1 parent 8cf7d03 commit 27c0731

File tree

1 file changed

+49
-49
lines changed
  • library/core/src/core_macros

1 file changed

+49
-49
lines changed

library/core/src/core_macros/mod.rs

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -194,55 +194,6 @@ pub macro assert_matches {
194194
},
195195
}
196196

197-
/// Asserts that an expression matches the provided pattern.
198-
///
199-
/// This macro is generally preferable to `debug_assert!(matches!(value, pattern))`, because it can
200-
/// print the debug representation of the actual value shape that did not meet expectations. In
201-
/// contrast, using [`debug_assert!`] will only print that expectations were not met, but not why.
202-
///
203-
/// The pattern syntax is exactly the same as found in a match arm and the `matches!` macro. The
204-
/// optional if guard can be used to add additional checks that must be true for the matched value,
205-
/// otherwise this macro will panic.
206-
///
207-
/// On panic, this macro will print the value of the expression with its debug representation.
208-
///
209-
/// Like [`assert!`], this macro has a second form, where a custom panic message can be provided.
210-
///
211-
/// Unlike [`assert_matches!`], `debug_assert_matches!` statements are only enabled in non optimized
212-
/// builds by default. An optimized build will not execute `debug_assert_matches!` statements unless
213-
/// `-C debug-assertions` is passed to the compiler. This makes `debug_assert_matches!` useful for
214-
/// checks that are too expensive to be present in a release build but may be helpful during
215-
/// development. The result of expanding `debug_assert_matches!` is always type checked.
216-
///
217-
/// # Examples
218-
///
219-
/// ```
220-
/// use std::macros::debug_assert_matches;
221-
///
222-
/// let a = Some(345);
223-
/// let b = Some(56);
224-
/// debug_assert_matches!(a, Some(_));
225-
/// debug_assert_matches!(b, Some(_));
226-
///
227-
/// debug_assert_matches!(a, Some(345));
228-
/// debug_assert_matches!(a, Some(345) | None);
229-
///
230-
/// // debug_assert_matches!(a, None); // panics
231-
/// // debug_assert_matches!(b, Some(345)); // panics
232-
/// // debug_assert_matches!(b, Some(345) | None); // panics
233-
///
234-
/// debug_assert_matches!(a, Some(x) if x > 100);
235-
/// // debug_assert_matches!(a, Some(x) if x < 100); // panics
236-
/// ```
237-
#[stable(feature = "assert_matches", since = "CURRENT_RUSTC_VERSION")]
238-
#[allow_internal_unstable(assert_matches)]
239-
#[rustc_macro_transparency = "semitransparent"]
240-
pub macro debug_assert_matches($($arg:tt)*) {
241-
if $crate::cfg!(debug_assertions) {
242-
$crate::macros::assert_matches!($($arg)*);
243-
}
244-
}
245-
246197
/// A macro for defining `#[cfg]` match-like statements.
247198
///
248199
/// It is similar to the `if/elif` C preprocessor macro by allowing definition of a cascade of
@@ -417,6 +368,55 @@ macro_rules! debug_assert_ne {
417368
};
418369
}
419370

371+
/// Asserts that an expression matches the provided pattern.
372+
///
373+
/// This macro is generally preferable to `debug_assert!(matches!(value, pattern))`, because it can
374+
/// print the debug representation of the actual value shape that did not meet expectations. In
375+
/// contrast, using [`debug_assert!`] will only print that expectations were not met, but not why.
376+
///
377+
/// The pattern syntax is exactly the same as found in a match arm and the `matches!` macro. The
378+
/// optional if guard can be used to add additional checks that must be true for the matched value,
379+
/// otherwise this macro will panic.
380+
///
381+
/// On panic, this macro will print the value of the expression with its debug representation.
382+
///
383+
/// Like [`assert!`], this macro has a second form, where a custom panic message can be provided.
384+
///
385+
/// Unlike [`assert_matches!`], `debug_assert_matches!` statements are only enabled in non optimized
386+
/// builds by default. An optimized build will not execute `debug_assert_matches!` statements unless
387+
/// `-C debug-assertions` is passed to the compiler. This makes `debug_assert_matches!` useful for
388+
/// checks that are too expensive to be present in a release build but may be helpful during
389+
/// development. The result of expanding `debug_assert_matches!` is always type checked.
390+
///
391+
/// # Examples
392+
///
393+
/// ```
394+
/// use std::macros::debug_assert_matches;
395+
///
396+
/// let a = Some(345);
397+
/// let b = Some(56);
398+
/// debug_assert_matches!(a, Some(_));
399+
/// debug_assert_matches!(b, Some(_));
400+
///
401+
/// debug_assert_matches!(a, Some(345));
402+
/// debug_assert_matches!(a, Some(345) | None);
403+
///
404+
/// // debug_assert_matches!(a, None); // panics
405+
/// // debug_assert_matches!(b, Some(345)); // panics
406+
/// // debug_assert_matches!(b, Some(345) | None); // panics
407+
///
408+
/// debug_assert_matches!(a, Some(x) if x > 100);
409+
/// // debug_assert_matches!(a, Some(x) if x < 100); // panics
410+
/// ```
411+
#[stable(feature = "assert_matches", since = "CURRENT_RUSTC_VERSION")]
412+
#[allow_internal_unstable(assert_matches)]
413+
#[rustc_macro_transparency = "semitransparent"]
414+
pub macro debug_assert_matches($($arg:tt)*) {
415+
if $crate::cfg!(debug_assertions) {
416+
$crate::macros::assert_matches!($($arg)*);
417+
}
418+
}
419+
420420
/// Returns whether the given expression matches the provided pattern.
421421
///
422422
/// The pattern syntax is exactly the same as found in a match arm. The optional if guard can be

0 commit comments

Comments
 (0)