162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci//! Build-time error.
462306a36Sopenharmony_ci//!
562306a36Sopenharmony_ci//! This crate provides a [const function][const-functions] `build_error`, which will panic in
662306a36Sopenharmony_ci//! compile-time if executed in [const context][const-context], and will cause a build error
762306a36Sopenharmony_ci//! if not executed at compile time and the optimizer does not optimise away the call.
862306a36Sopenharmony_ci//!
962306a36Sopenharmony_ci//! It is used by `build_assert!` in the kernel crate, allowing checking of
1062306a36Sopenharmony_ci//! conditions that could be checked statically, but could not be enforced in
1162306a36Sopenharmony_ci//! Rust yet (e.g. perform some checks in [const functions][const-functions], but those
1262306a36Sopenharmony_ci//! functions could still be called in the runtime).
1362306a36Sopenharmony_ci//!
1462306a36Sopenharmony_ci//! For details on constant evaluation in Rust, please see the [Reference][const-eval].
1562306a36Sopenharmony_ci//!
1662306a36Sopenharmony_ci//! [const-eval]: https://doc.rust-lang.org/reference/const_eval.html
1762306a36Sopenharmony_ci//! [const-functions]: https://doc.rust-lang.org/reference/const_eval.html#const-functions
1862306a36Sopenharmony_ci//! [const-context]: https://doc.rust-lang.org/reference/const_eval.html#const-context
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci#![no_std]
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci/// Panics if executed in [const context][const-context], or triggers a build error if not.
2362306a36Sopenharmony_ci///
2462306a36Sopenharmony_ci/// [const-context]: https://doc.rust-lang.org/reference/const_eval.html#const-context
2562306a36Sopenharmony_ci#[inline(never)]
2662306a36Sopenharmony_ci#[cold]
2762306a36Sopenharmony_ci#[export_name = "rust_build_error"]
2862306a36Sopenharmony_ci#[track_caller]
2962306a36Sopenharmony_cipub const fn build_error(msg: &'static str) -> ! {
3062306a36Sopenharmony_ci    panic!("{}", msg);
3162306a36Sopenharmony_ci}
32