linux/rust
Gary Guo 0f595bab9d rust: build_assert: add build_{error,assert}! macros
Add the `build_error!` and `build_assert!` macros which leverage
the previously introduced `build_error` crate. Do so in a new
module, called `build_assert`.

The former fails the build if the code path calling it can possibly
be executed. The latter asserts that a boolean expression is `true`
at compile time.

In particular, `build_assert!` can be used in some contexts where
`static_assert!` cannot:

    fn f1<const N: usize>() {
        static_assert!(N > 1);` // Error.
        build_assert!(N > 1);   // Build-time check.
        assert!(N > 1);         // Run-time check.
    }

    #[inline]
    fn f2(n: usize) {
        static_assert!(n > 1);  // Error.
        build_assert!(n > 1);   // Build-time check.
        assert!(n > 1);         // Run-time check.
    }

Signed-off-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Wei Liu <wei.liu@kernel.org>
[Reworded, adapted for upstream and applied latest changes]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-12-04 01:59:16 +01:00
..
alloc rust: alloc: add Vec::try_with_capacity{,_in}() constructors 2022-12-04 01:59:15 +01:00
bindings rust: add bindings crate 2022-09-28 08:58:00 +02:00
kernel rust: build_assert: add build_{error,assert}! macros 2022-12-04 01:59:16 +01:00
macros rust: macros: take string literals in module! 2022-12-04 01:59:15 +01:00
.gitignore Kbuild: add Rust support 2022-09-28 09:02:20 +02:00
bindgen_parameters Kbuild: add Rust support 2022-09-28 09:02:20 +02:00
build_error.rs rust: add build_error crate 2022-12-04 01:59:16 +01:00
compiler_builtins.rs rust: add compiler_builtins crate 2022-09-28 08:58:00 +02:00
exports.c rust: add build_error crate 2022-12-04 01:59:16 +01:00
helpers.c rust: add C helpers 2022-09-28 08:56:43 +02:00
Makefile rust: add build_error crate 2022-12-04 01:59:16 +01:00