Skip to content

Commit

Permalink
Rollup merge of rust-lang#60998 - RalfJung:static_assert, r=Centril
Browse files Browse the repository at this point in the history
static_assert: make use of anonymous constants
  • Loading branch information
Centril committed May 22, 2019
2 parents 03712a8 + a2168b0 commit 9c784b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/librustc_data_structures/macros.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/// A simple static assertion macro. The first argument should be a unique
/// ALL_CAPS identifier that describes the condition.
/// A simple static assertion macro.
#[macro_export]
#[allow_internal_unstable(type_ascription)]
#[allow_internal_unstable(type_ascription, underscore_const_names)]
macro_rules! static_assert {
($name:ident: $test:expr) => {
($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: bool) as usize];
const _: () = [()][!($test: bool) as usize];
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,14 +544,14 @@ impl Qualif for IsNotImplicitlyPromotable {
// Ensure the `IDX` values are sequential (`0..QUALIF_COUNT`).
macro_rules! static_assert_seq_qualifs {
($i:expr => $first:ident $(, $rest:ident)*) => {
static_assert!(SEQ_QUALIFS: {
static_assert!({
static_assert_seq_qualifs!($i + 1 => $($rest),*);

$first::IDX == $i
});
};
($i:expr =>) => {
static_assert!(SEQ_QUALIFS: QUALIF_COUNT == $i);
static_assert!(QUALIF_COUNT == $i);
};
}
static_assert_seq_qualifs!(
Expand Down

0 comments on commit 9c784b3

Please sign in to comment.