@@ -28,71 +28,6 @@ macro_rules! panic {
2828 } ) ;
2929}
3030
31- /// Ensure that a boolean expression is `true` at runtime.
32- ///
33- /// This will invoke the [`panic!`] macro if the provided expression cannot be
34- /// evaluated to `true` at runtime.
35- ///
36- /// # Uses
37- ///
38- /// Assertions are always checked in both debug and release builds, and cannot
39- /// be disabled. See [`debug_assert!`] for assertions that are not enabled in
40- /// release builds by default.
41- ///
42- /// Unsafe code relies on `assert!` to enforce run-time invariants that, if
43- /// violated could lead to unsafety.
44- ///
45- /// Other use-cases of `assert!` include [testing] and enforcing run-time
46- /// invariants in safe code (whose violation cannot result in unsafety).
47- ///
48- /// # Custom Messages
49- ///
50- /// This macro has a second form, where a custom panic message can
51- /// be provided with or without arguments for formatting. See [`std::fmt`]
52- /// for syntax for this form.
53- ///
54- /// [`panic!`]: macro.panic.html
55- /// [`debug_assert!`]: macro.debug_assert.html
56- /// [testing]: ../book/second-edition/ch11-01-writing-tests.html#checking-results-with-the-assert-macro
57- /// [`std::fmt`]: ../std/fmt/index.html
58- ///
59- /// # Examples
60- ///
61- /// ```
62- /// // the panic message for these assertions is the stringified value of the
63- /// // expression given.
64- /// assert!(true);
65- ///
66- /// fn some_computation() -> bool { true } // a very simple function
67- ///
68- /// assert!(some_computation());
69- ///
70- /// // assert with a custom message
71- /// let x = true;
72- /// assert!(x, "x wasn't true!");
73- ///
74- /// let a = 3; let b = 27;
75- /// assert!(a + b == 30, "a = {}, b = {}", a, b);
76- /// ```
77- #[ macro_export]
78- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
79- #[ cfg( stage0) ]
80- macro_rules! assert {
81- ( $cond: expr) => (
82- if !$cond {
83- panic!( concat!( "assertion failed: " , stringify!( $cond) ) )
84- }
85- ) ;
86- ( $cond: expr, ) => (
87- assert!( $cond)
88- ) ;
89- ( $cond: expr, $( $arg: tt) +) => (
90- if !$cond {
91- panic!( $( $arg) +)
92- }
93- ) ;
94- }
95-
9631/// Asserts that two expressions are equal to each other (using [`PartialEq`]).
9732///
9833/// On panic, this macro will print the values of the expressions with their
0 commit comments