Skip to content

Commit c385c9b

Browse files
committed
remove static_assert
1 parent ef831bb commit c385c9b

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

0000-remove-static-assert.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
- Feature Name: remove-static-assert
2+
- Start Date: 2015-04-28
3+
- RFC PR:
4+
- Rust Issue: https://github.com/rust-lang/rust/pull/24910
5+
6+
# Summary
7+
8+
Remove the `static_assert` feature.
9+
10+
# Motivation
11+
12+
To recap, `static_assert` looks like this:
13+
14+
```rust
15+
#![feature(static_assert)]
16+
#[static_assert]
17+
static asssertion: bool = true;
18+
```
19+
20+
If `assertion` is `false` instead, this fails to compile:
21+
22+
```text
23+
error: static assertion failed
24+
static asssertion: bool = false;
25+
^~~~~
26+
```
27+
28+
If you don’t have the `feature` flag, you get another interesting error:
29+
30+
```text
31+
error: `#[static_assert]` is an experimental feature, and has a poor API
32+
```
33+
34+
Throughout its life, `static_assert` has been... weird. Graydon suggested it
35+
[in May of 2013][suggest], and it was
36+
[implemented][https://github.com/rust-lang/rust/pull/6670] shortly after.
37+
[Another issue][issue] was created to give it a ‘better interface’. Here’s why:
38+
39+
> The biggest problem with it is you need a static variable with a name, that
40+
> goes through trans and ends up in the object file.
41+
42+
In other words, `assertion` above ends up as a symbol in the final output. Not
43+
something you’d usually expect from some kind of static assertion.
44+
45+
[suggest]: https://github.com/rust-lang/rust/issues/6568
46+
[issue]: https://github.com/rust-lang/rust/issues/6676
47+
48+
So why not improve `static_assert`? With compile time function evaluation, the
49+
idea of a ‘static assertion’ doesn’t need to have language semantics. Either
50+
`const` functions or full-blown CTFE is a useful feature in its own right that
51+
we’ve said we want in Rust. In light of it being eventually added,
52+
`static_assert` doesn’t make sense any more.
53+
54+
`static_assert` isn’t used by the compiler at all.
55+
56+
# Detailed design
57+
58+
Remove `static_assert`. [Implementation submitted here][here].
59+
60+
[here]: https://github.com/rust-lang/rust/pull/24910
61+
62+
# Drawbacks
63+
64+
Why should we *not* do this?
65+
66+
# Alternatives
67+
68+
This feature is pretty binary: we either remove it, or we don’t. We could keep the feature,
69+
but build out some sort of alternate version that’s not as weird.
70+
71+
# Unresolved questions
72+
73+
None with the design, only “should we do this?”

0 commit comments

Comments
 (0)