- Feature Name: remove-static-assert
- Start Date: 2015-04-28
- RFC PR: rust-lang/rfcs#1096
- Rust Issue: https://github.com/rust-lang/rust/pull/24910
static_assert looks like this:
#![feature(static_assert)] #[static_assert] static assertion: bool = true;
false instead, this fails to compile:
error: static assertion failed static assertion: bool = false; ^~~~~
If you don’t have the
feature flag, you get another interesting error:
error: `#[static_assert]` is an experimental feature, and has a poor API
The biggest problem with it is you need a static variable with a name, that goes through trans and ends up in the object file.
In other words,
assertion above ends up as a symbol in the final output. Not
something you’d usually expect from some kind of static assertion.
So why not improve
static_assert? With compile time function evaluation, the
idea of a ‘static assertion’ doesn’t need to have language semantics. Either
const functions or full-blown CTFE is a useful feature in its own right that
we’ve said we want in Rust. In light of it being eventually added,
static_assert doesn’t make sense any more.
static_assert isn’t used by the compiler at all.
static_assert. Implementation submitted here.
Why should we not do this?
This feature is pretty binary: we either remove it, or we don’t. We could keep the feature, but build out some sort of alternate version that’s not as weird.
None with the design, only “should we do this?”