Skip to content

Feature gate #[static_assert]. #22960

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

Merged
merged 1 commit into from
Mar 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2495,6 +2495,12 @@ The currently implemented features of the reference compiler are:

* `staged_api` - Allows usage of stability markers and `#![staged_api]` in a crate

* `static_assert` - The `#[static_assert]` functionality is experimental and
unstable. The attribute can be attached to a `static` of
type `bool` and the compiler will error if the `bool` is
`false` at compile time. This version of this functionality
is unintuitive and suboptimal.

* `start` - Allows use of the `#[start]` attribute, which changes the entry point
into a Rust program. This capabiilty, especially the signature for the
annotated function, is subject to change.
Expand Down
7 changes: 5 additions & 2 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ static KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[

// Allows the use of rustc_* attributes; RFC 572
("rustc_attrs", "1.0.0", Active),

// Allows the use of `static_assert`
("static_assert", "1.0.0", Active),
];
// (changing above list without updating src/doc/reference.md makes @cmr sad)

Expand Down Expand Up @@ -241,7 +244,8 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
("no_split_stack", Whitelisted),
("no_stack_check", Whitelisted),
("packed", Whitelisted),
("static_assert", Whitelisted),
("static_assert", Gated("static_assert",
"`#[static_assert]` is an experimental feature, and has a poor API")),
("no_debug", Whitelisted),
("omit_gdb_pretty_printer_section", Whitelisted),
("unsafe_no_drop_flag", Gated("unsafe_no_drop_flag",
Expand Down Expand Up @@ -769,4 +773,3 @@ pub fn check_crate(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::Crate)
|ctx, krate| visit::walk_crate(&mut PostExpansionVisitor { context: ctx },
krate))
}

9 changes: 3 additions & 6 deletions src/test/compile-fail/asm-misplaced-option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@

// ignore-android

#![feature(asm)]
#![feature(asm, rustc_attrs)]

#![allow(dead_code, non_upper_case_globals)]

#[cfg(any(target_arch = "x86",
target_arch = "x86_64"))]
pub fn main() {
#[rustc_error]
pub fn main() { //~ ERROR compilation successful
// assignment not dead
let mut x: isize = 0;
unsafe {
Expand All @@ -33,7 +34,3 @@ pub fn main() {
}
assert_eq!(x, 13);
}

// At least one error is needed so that compilation fails
#[static_assert]
static b: bool = false; //~ ERROR static assertion failed
14 changes: 14 additions & 0 deletions src/test/compile-fail/feature-gate-static-assert.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[static_assert] //~ ERROR `#[static_assert]` is an experimental feature
static X: bool = true;

fn main() {}
8 changes: 3 additions & 5 deletions src/test/compile-fail/issue-6804.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(rustc_attrs)]
#![allow(dead_code)]

// Matching against NaN should result in a warning

use std::f64::NAN;

fn main() {
#[rustc_error]
fn main() { //~ ERROR compilation successful
let x = NAN;
match x {
NAN => {},
Expand All @@ -27,7 +29,3 @@ fn main() {
};
//~^^^ WARNING unmatchable NaN in pattern, use the is_nan method in a guard instead
}

// At least one error is needed so that compilation fails
#[static_assert]
static B: bool = false; //~ ERROR static assertion failed
1 change: 1 addition & 0 deletions src/test/compile-fail/nonbool_static_assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(static_assert)]
#![allow(dead_code)]

#[static_assert]
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/static-assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(static_assert)]
#![allow(dead_code)]

#[static_assert]
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/static-assert2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(static_assert)]
#![allow(dead_code)]

#[static_assert]
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/static-assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(static_assert)]

#[static_assert]
static b: bool = true;

Expand Down