<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-toradex.git/rust/kernel/build_assert.rs, branch v6.4-rc1</title>
<subtitle>Linux kernel for Apalis and Colibri modules</subtitle>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/'/>
<entry>
<title>rust: build_assert: add `build_{error,assert}!` macros</title>
<updated>2022-12-04T00:59:16+00:00</updated>
<author>
<name>Gary Guo</name>
<email>gary@garyguo.net</email>
</author>
<published>2022-11-10T16:41:38+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=0f595bab9d1c1a10c6ab5ff3f9140cfc26600349'/>
<id>0f595bab9d1c1a10c6ab5ff3f9140cfc26600349</id>
<content type='text'>
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&lt;const N: usize&gt;() {
        static_assert!(N &gt; 1);` // Error.
        build_assert!(N &gt; 1);   // Build-time check.
        assert!(N &gt; 1);         // Run-time check.
    }

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

Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Wei Liu &lt;wei.liu@kernel.org&gt;
[Reworded, adapted for upstream and applied latest changes]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
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&lt;const N: usize&gt;() {
        static_assert!(N &gt; 1);` // Error.
        build_assert!(N &gt; 1);   // Build-time check.
        assert!(N &gt; 1);         // Run-time check.
    }

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

Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Wei Liu &lt;wei.liu@kernel.org&gt;
[Reworded, adapted for upstream and applied latest changes]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</pre>
</div>
</content>
</entry>
</feed>
