brintos

brintos / linux-shallow public Read only

0
0
Text · 1.3 KiB · fa24eee Raw
32 lines · rust
1// SPDX-License-Identifier: GPL-2.02 3//! Build-time error.4//!5//! This crate provides a [const function][const-functions] `build_error`, which will panic in6//! compile-time if executed in [const context][const-context], and will cause a build error7//! if not executed at compile time and the optimizer does not optimise away the call.8//!9//! It is used by `build_assert!` in the kernel crate, allowing checking of10//! conditions that could be checked statically, but could not be enforced in11//! Rust yet (e.g. perform some checks in [const functions][const-functions], but those12//! functions could still be called in the runtime).13//!14//! For details on constant evaluation in Rust, please see the [Reference][const-eval].15//!16//! [const-eval]: https://doc.rust-lang.org/reference/const_eval.html17//! [const-functions]: https://doc.rust-lang.org/reference/const_eval.html#const-functions18//! [const-context]: https://doc.rust-lang.org/reference/const_eval.html#const-context19 20#![no_std]21 22/// Panics if executed in [const context][const-context], or triggers a build error if not.23///24/// [const-context]: https://doc.rust-lang.org/reference/const_eval.html#const-context25#[inline(never)]26#[cold]27#[export_name = "rust_build_error"]28#[track_caller]29pub const fn build_error(msg: &'static str) -> ! {30    panic!("{}", msg);31}32