Feature gate #[static_assert].

The API this exposes is a little strange (being attached to `static`s),
so it makes sense to conservatively feature gate it. If it is highly
popular, it is possible to reverse this gating.
This commit is contained in:
Huon Wilson 2015-03-02 21:46:31 +11:00
parent 1576142495
commit c195783c05
9 changed files with 36 additions and 13 deletions

View file

@ -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 {
@ -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

View file

@ -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() {}

View file

@ -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 => {},
@ -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

View file

@ -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]

View file

@ -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]

View file

@ -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]

View file

@ -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;