Skip to content

Commit

Permalink
Ensure that the static_assert! argument is a bool
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Nov 16, 2018
1 parent 6b9b97b commit 65e6fdb
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/librustc_data_structures/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
/// A simple static assertion macro. The first argument should be a unique
/// ALL_CAPS identifier that describes the condition.
#[macro_export]
#[allow_internal_unstable]
macro_rules! static_assert {
($name:ident: $test:expr) => {
// Use the bool to access an array such that if the bool is false, the access
// is out-of-bounds.
#[allow(dead_code)]
static $name: () = [()][!$test as usize];
static $name: () = [()][!($test: bool) as usize];
}
}

0 comments on commit 65e6fdb

Please sign in to comment.