Skip to content

Commit c446e30

Browse files
committed
Remove #[static_assert]
This was always a weird feature, and isn't being used in the compiler. Static assertions should be done better than this. Fixes #13951 Fixes #23008 Fixes #6676 This is behind a feature gate, but that's still a [breaking-change]
1 parent da2276e commit c446e30

File tree

8 files changed

+0
-129
lines changed

8 files changed

+0
-129
lines changed

src/doc/reference.md

-8
Original file line numberDiff line numberDiff line change
@@ -1872,8 +1872,6 @@ macro scope.
18721872
- `simd` - on certain tuple structs, derive the arithmetic operators, which
18731873
lower to the target's SIMD instructions, if any; the `simd` feature gate
18741874
is necessary to use this attribute.
1875-
- `static_assert` - on statics whose type is `bool`, terminates compilation
1876-
with an error if it is not initialized to `true`.
18771875
- `unsafe_destructor` - allow implementations of the "drop" language item
18781876
where the type it is implemented for does not implement the "send" language
18791877
item; the `unsafe_destructor` feature gate is needed to use this attribute
@@ -2231,12 +2229,6 @@ The currently implemented features of the reference compiler are:
22312229
crate. Stability markers are also attributes: `#[stable]`,
22322230
`#[unstable]`, and `#[deprecated]` are the three levels.
22332231

2234-
* `static_assert` - The `#[static_assert]` functionality is experimental and
2235-
unstable. The attribute can be attached to a `static` of
2236-
type `bool` and the compiler will error if the `bool` is
2237-
`false` at compile time. This version of this functionality
2238-
is unintuitive and suboptimal.
2239-
22402232
* `start` - Allows use of the `#[start]` attribute, which changes the entry point
22412233
into a Rust program. This capability, especially the signature for the
22422234
annotated function, is subject to change.

src/librustc_trans/trans/base.rs

-22
Original file line numberDiff line numberDiff line change
@@ -2025,28 +2025,6 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
20252025

20262026
let g = consts::trans_static(ccx, m, item.id);
20272027
update_linkage(ccx, g, Some(item.id), OriginalTranslation);
2028-
2029-
// Do static_assert checking. It can't really be done much earlier
2030-
// because we need to get the value of the bool out of LLVM
2031-
if attr::contains_name(&item.attrs, "static_assert") {
2032-
if !ty::type_is_bool(ty::expr_ty(ccx.tcx(), expr)) {
2033-
ccx.sess().span_fatal(expr.span,
2034-
"can only have static_assert on a static \
2035-
with type `bool`");
2036-
}
2037-
if m == ast::MutMutable {
2038-
ccx.sess().span_fatal(expr.span,
2039-
"cannot have static_assert on a mutable \
2040-
static");
2041-
}
2042-
2043-
let v = ccx.static_values().borrow().get(&item.id).unwrap().clone();
2044-
unsafe {
2045-
if !(llvm::LLVMConstIntGetZExtValue(v) != 0) {
2046-
ccx.sess().span_fatal(expr.span, "static assertion failed");
2047-
}
2048-
}
2049-
}
20502028
},
20512029
ast::ItemForeignMod(ref foreign_mod) => {
20522030
foreign::trans_foreign_mod(ccx, foreign_mod);

src/libsyntax/feature_gate.rs

-5
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,6 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
141141
// Allows the use of rustc_* attributes; RFC 572
142142
("rustc_attrs", "1.0.0", Active),
143143

144-
// Allows the use of `static_assert`
145-
("static_assert", "1.0.0", Active),
146-
147144
// Allows the use of #[allow_internal_unstable]. This is an
148145
// attribute on macro_rules! and can't use the attribute handling
149146
// below (it has to be checked before expansion possibly makes
@@ -265,8 +262,6 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
265262
("no_mangle", Whitelisted),
266263
("no_stack_check", Whitelisted),
267264
("packed", Whitelisted),
268-
("static_assert", Gated("static_assert",
269-
"`#[static_assert]` is an experimental feature, and has a poor API")),
270265
("no_debug", Whitelisted),
271266
("omit_gdb_pretty_printer_section", Whitelisted),
272267
("unsafe_no_drop_flag", Gated("unsafe_no_drop_flag",

src/test/compile-fail/feature-gate-static-assert.rs

-14
This file was deleted.

src/test/compile-fail/nonbool_static_assert.rs

-17
This file was deleted.

src/test/compile-fail/static-assert.rs

-18
This file was deleted.

src/test/compile-fail/static-assert2.rs

-17
This file was deleted.

src/test/run-pass/static-assert.rs

-28
This file was deleted.

0 commit comments

Comments
 (0)