@@ -719,6 +719,60 @@ pub mod builtin {
719719 ( $file: expr) => ( { /* compiler built-in */ } ) ;
720720 ( $file: expr, ) => ( { /* compiler built-in */ } ) ;
721721 }
722+
723+ /// Ensure that a boolean expression is `true` at runtime.
724+ ///
725+ /// This will invoke the [`panic!`] macro if the provided expression cannot be
726+ /// evaluated to `true` at runtime.
727+ ///
728+ /// # Uses
729+ ///
730+ /// Assertions are always checked in both debug and release builds, and cannot
731+ /// be disabled. See [`debug_assert!`] for assertions that are not enabled in
732+ /// release builds by default.
733+ ///
734+ /// Unsafe code relies on `assert!` to enforce run-time invariants that, if
735+ /// violated could lead to unsafety.
736+ ///
737+ /// Other use-cases of `assert!` include [testing] and enforcing run-time
738+ /// invariants in safe code (whose violation cannot result in unsafety).
739+ ///
740+ /// # Custom Messages
741+ ///
742+ /// This macro has a second form, where a custom panic message can
743+ /// be provided with or without arguments for formatting. See [`std::fmt`]
744+ /// for syntax for this form.
745+ ///
746+ /// [`panic!`]: macro.panic.html
747+ /// [`debug_assert!`]: macro.debug_assert.html
748+ /// [testing]: ../book/second-edition/ch11-01-writing-tests.html#checking-results-with-the-assert-macro
749+ /// [`std::fmt`]: ../std/fmt/index.html
750+ ///
751+ /// # Examples
752+ ///
753+ /// ```
754+ /// // the panic message for these assertions is the stringified value of the
755+ /// // expression given.
756+ /// assert!(true);
757+ ///
758+ /// fn some_computation() -> bool { true } // a very simple function
759+ ///
760+ /// assert!(some_computation());
761+ ///
762+ /// // assert with a custom message
763+ /// let x = true;
764+ /// assert!(x, "x wasn't true!");
765+ ///
766+ /// let a = 3; let b = 27;
767+ /// assert!(a + b == 30, "a = {}, b = {}", a, b);
768+ /// ```
769+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
770+ #[ macro_export]
771+ macro_rules! assert {
772+ ( $cond: expr) => ( { /* compiler built-in */ } ) ;
773+ ( $cond: expr, ) => ( { /* compiler built-in */ } ) ;
774+ ( $cond: expr, $( $arg: tt) +) => ( { /* compiler built-in */ } ) ;
775+ }
722776}
723777
724778/// A macro for defining #[cfg] if-else statements.
0 commit comments