Skip to content

Commit b70f49b

Browse files
committed
Auto merge of #24910 - steveklabnik:remove_static_assert, r=alexcrichton
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] (It's not entirely clear to me that this should or shouldn't have an RFC, but if it does, I'm fine blocking on such a thing.)
2 parents 9a2f68e + 5235065 commit b70f49b

File tree

8 files changed

+0
-130
lines changed

8 files changed

+0
-130
lines changed

src/doc/reference.md

-9
Original file line numberDiff line numberDiff line change
@@ -1943,9 +1943,6 @@ macro scope.
19431943
- `simd` - on certain tuple structs, derive the arithmetic operators, which
19441944
lower to the target's SIMD instructions, if any; the `simd` feature gate
19451945
is necessary to use this attribute.
1946-
- `static_assert` - on statics whose type is `bool`, terminates compilation
1947-
with an error if it is not initialized to `true`. To use this, the `static_assert`
1948-
feature gate must be enabled.
19491946
- `unsafe_no_drop_flag` - on structs, remove the flag that prevents
19501947
destructors from being run twice. Destructors might be run multiple times on
19511948
the same object with this attribute. To use this, the `unsafe_no_drop_flag` feature
@@ -2301,12 +2298,6 @@ The currently implemented features of the reference compiler are:
23012298
crate. Stability markers are also attributes: `#[stable]`,
23022299
`#[unstable]`, and `#[deprecated]` are the three levels.
23032300

2304-
* `static_assert` - The `#[static_assert]` functionality is experimental and
2305-
unstable. The attribute can be attached to a `static` of
2306-
type `bool` and the compiler will error if the `bool` is
2307-
`false` at compile time. This version of this functionality
2308-
is unintuitive and suboptimal.
2309-
23102301
* `start` - Allows use of the `#[start]` attribute, which changes the entry point
23112302
into a Rust program. This capability, especially the signature for the
23122303
annotated function, is subject to change.

src/librustc_trans/trans/base.rs

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

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

src/libsyntax/feature_gate.rs

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

140-
// Allows the use of `static_assert`
141-
("static_assert", "1.0.0", Active),
142-
143140
// Allows the use of #[allow_internal_unstable]. This is an
144141
// attribute on macro_rules! and can't use the attribute handling
145142
// below (it has to be checked before expansion possibly makes
@@ -261,8 +258,6 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
261258
("no_builtins", Whitelisted),
262259
("no_mangle", Whitelisted),
263260
("no_stack_check", Whitelisted),
264-
("static_assert", Gated("static_assert",
265-
"`#[static_assert]` is an experimental feature, and has a poor API")),
266261
("no_debug", Whitelisted),
267262
("omit_gdb_pretty_printer_section", Whitelisted),
268263
("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)