/// This will invoke the [`panic!`] macro if the provided expression cannot be
/// evaluated to `true` at runtime.
///
+/// # Uses
+///
/// Assertions are always checked in both debug and release builds, and cannot
/// be disabled. See [`debug_assert!`] for assertions that are not enabled in
/// release builds by default.
/// Other use-cases of `assert!` include [testing] and enforcing run-time
/// invariants in safe code (whose violation cannot result in unsafety).
///
-/// This macro has a second version, where a custom panic message can
+/// # Custom Messages
+///
+/// This macro has a second form, where a custom panic message can
/// be provided with or without arguments for formatting.
///
/// [`panic!`]: macro.panic.html
);
}
-/// Asserts that two expressions are equal to each other.
+/// Asserts that two expressions are equal to each other (using [`PartialEq`]).
///
/// On panic, this macro will print the values of the expressions with their
/// debug representations.
///
-/// Like [`assert!`], this macro has a second version, where a custom
+/// Like [`assert!`], this macro has a second form, where a custom
/// panic message can be provided.
///
+/// [`PartialEq`]: cmp/trait.PartialEq.html
/// [`assert!`]: macro.assert.html
///
/// # Examples
match (&$left, &$right) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
- panic!("assertion failed: `(left == right)` \
- (left: `{:?}`, right: `{:?}`)", left_val, right_val)
+ panic!(r#"assertion failed: `(left == right)`
+ left: `{:?}`
+ right: `{:?}`"#, left_val, right_val)
}
}
}
match (&($left), &($right)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
- panic!("assertion failed: `(left == right)` \
- (left: `{:?}`, right: `{:?}`): {}", left_val, right_val,
+ panic!(r#"assertion failed: `(left == right)`
+ left: `{:?}`
+ right: `{:?}`: {}"#, left_val, right_val,
format_args!($($arg)+))
}
}
});
}
-/// Asserts that two expressions are not equal to each other.
+/// Asserts that two expressions are not equal to each other (using [`PartialEq`]).
///
/// On panic, this macro will print the values of the expressions with their
/// debug representations.
///
-/// Like `assert!()`, this macro has a second version, where a custom
+/// Like [`assert!`], this macro has a second form, where a custom
/// panic message can be provided.
///
+/// [`PartialEq`]: cmp/trait.PartialEq.html
/// [`assert!`]: macro.assert.html
///
/// # Examples
/// assert_ne!(a, b, "we are testing that the values are not equal");
/// ```
#[macro_export]
-#[stable(feature = "assert_ne", since = "1.12.0")]
+#[stable(feature = "assert_ne", since = "1.13.0")]
macro_rules! assert_ne {
($left:expr, $right:expr) => ({
match (&$left, &$right) {
(left_val, right_val) => {
if *left_val == *right_val {
- panic!("assertion failed: `(left != right)` \
- (left: `{:?}`, right: `{:?}`)", left_val, right_val)
+ panic!(r#"assertion failed: `(left != right)`
+ left: `{:?}`
+ right: `{:?}`"#, left_val, right_val)
}
}
}
match (&($left), &($right)) {
(left_val, right_val) => {
if *left_val == *right_val {
- panic!("assertion failed: `(left != right)` \
- (left: `{:?}`, right: `{:?}`): {}", left_val, right_val,
+ panic!(r#"assertion failed: `(left != right)`
+ left: `{:?}`
+ right: `{:?}`: {}"#, left_val, right_val,
format_args!($($arg)+))
}
}
/// Like [`assert!`], this macro also has a second version, where a custom panic
/// message can be provided.
///
+/// # Uses
+///
/// Unlike [`assert!`], `debug_assert!` statements are only enabled in non
/// optimized builds by default. An optimized build will omit all
/// `debug_assert!` statements unless `-C debug-assertions` is passed to the
/// debug_assert_ne!(a, b);
/// ```
#[macro_export]
-#[stable(feature = "assert_ne", since = "1.12.0")]
+#[stable(feature = "assert_ne", since = "1.13.0")]
macro_rules! debug_assert_ne {
($($arg:tt)*) => (if cfg!(debug_assertions) { assert_ne!($($arg)*); })
}
/// assert_eq!(v, b"s = \"abc 123\"");
/// ```
#[macro_export]
-#[stable(feature = "core", since = "1.6.0")]
+#[stable(feature = "rust1", since = "1.0.0")]
macro_rules! write {
($dst:expr, $($arg:tt)*) => ($dst.write_fmt(format_args!($($arg)*)))
}
/// }
/// ```
#[macro_export]
-#[stable(feature = "core", since = "1.6.0")]
+#[stable(feature = "rust1", since = "1.0.0")]
macro_rules! unreachable {
() => ({
panic!("internal error: entered unreachable code")
/// }
/// ```
#[macro_export]
-#[stable(feature = "core", since = "1.6.0")]
+#[stable(feature = "rust1", since = "1.0.0")]
macro_rules! unimplemented {
() => (panic!("not yet implemented"))
}