-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Const assertions are not guaranteed to cause compile failures #351
Comments
This is not actually related to the issue.
|
I tried this out for /// ```compile_fail
/// use heapless::mpmc::MpMcQueue;
/// let q: MpMcQueue<i32, 1> = MpMcQueue::new();
/// ```
const _ASSERT1: () = assert!(N > 1);
/// ```compile_fail
/// use heapless::mpmc::MpMcQueue;
/// let q: MpMcQueue<i32, 3> = MpMcQueue::new();
/// ```
const _ASSERT2: () = assert!(N.is_power_of_two());
I'm surprised this compiles successfully 🤔 Edit: They needed to be used, see #403 |
From https://doc.rust-lang.org/reference/const_eval.html:
As long as we always evaluate the const expressions in const context (so in |
In
sealed.rs
, there are a number of associated constants which are used in const fns to try and trigger compile failures when const generics don't match particular requirements.These const fns contain constant expressions, which may (but are not guaranteed to) evaluate at compile time. AFAICT from https://doc.rust-lang.org/reference/const_eval.html while this works now it might stop working in the future and instead cause a runtime panic.
Running
cargo check
on an example which we know won't build:We know this is a bit of a hack evidenced by the comments:
// Const assert hack
. It would be good to try and add coverage for these compile fails in thecfail
test suite so that we can detect if/when this stops being a compile-time error. Unfortunately thetrybuild
crate is usingcargo check
under the hood and would not be able to hit this.The text was updated successfully, but these errors were encountered: