Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Register
  • Sign in
  • L linux
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • Deployments
    • Deployments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • Kirill Smelkov
  • linux
  • Repository
You need to sign in or sign up before continuing.
  • linux
  • rust
  • kernel
  • static_assert.rs
Find file BlameHistoryPermalink
  • Miguel Ojeda's avatar
    rust: static_assert: add `static_assert!` macro · ef9e3797
    Miguel Ojeda authored Nov 10, 2022
    Add the `static_assert!` macro, which is a compile-time assert, similar
    to the C11 `_Static_assert` and C++11 `static_assert` declarations [1,2].
    Do so in a new module, called `static_assert`.
    
    For instance:
    
        static_assert!(42 > 24);
        static_assert!(core::mem::size_of::<u8>() == 1);
    
        const X: &[u8] = b"bar";
        static_assert!(X[1] == b'a');
    
        const fn f(x: i32) -> i32 {
            x + 2
        }
        static_assert!(f(40) == 42);
    
    Link: https://en.cppreference.com/w/c/language/_Static_assert [1]
    Link: https://en.cppreference.com/w/cpp/language/static_assert
    
     [2]
    Co-developed-by: default avatarAlex Gaynor <alex.gaynor@gmail.com>
    Signed-off-by: default avatarAlex Gaynor <alex.gaynor@gmail.com>
    Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
    ef9e3797
GitLab Nexedi Edition | About GitLab | About Nexedi | 沪ICP备2021021310号-2 | 沪ICP备2021021310号-7