• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /// A simple `assert` macro that works in `const fn`, for use until the
2 /// standard `assert` macro works in `const fn`.
3 ///
4 /// TODO: Replace this with just `assert!`, once that's stable for use in
5 /// a `const fn` context.
6 #[allow(unused_macros)]
7 macro_rules! const_assert {
8     ($x:expr) => {
9         let b: bool = $x;
10         let _ = [()][!b as usize];
11     };
12 }
13 
14 #[test]
15 #[allow(clippy::missing_const_for_fn)]
test_const_assert()16 fn test_const_assert() {
17     const_assert!(true);
18 }
19 
20 #[test]
test_const_assert_in_const_fn()21 const fn test_const_assert_in_const_fn() {
22     const_assert!(true);
23 }
24