From a6e8fb10e95a9db690221584bb6cbf74562fe185 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Sat, 6 Jul 2024 14:25:57 +1000 Subject: [PATCH] Use token tree in const_asset Instead of our current `const_assert` we can use a macro token tree and call through to `assert`. Doing so makes the macro more general. --- internals/src/macros.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internals/src/macros.rs b/internals/src/macros.rs index 6b9aa6aaf7..be894d1b89 100644 --- a/internals/src/macros.rs +++ b/internals/src/macros.rs @@ -137,11 +137,12 @@ macro_rules! debug_from_display { } /// Asserts a boolean expression at compile time. +// Copied from: https://internals.rust-lang.org/t/nicer-static-assertions/15986 #[macro_export] macro_rules! const_assert { - ($x:expr) => {{ - const _: [(); 0 - !$x as usize] = []; - }}; + ($($tt:tt)*) => { + const _: () = assert!($($tt)*); + } } /// Derives `From` for the given type.