From 5ea5fe30726b616a7a561d9b9737b5f4bf629118 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 21 May 2019 08:51:18 +0200 Subject: [PATCH 1/2] static_assert: make use of anonymous constants --- src/librustc_data_structures/macros.rs | 6 +++--- src/librustc_mir/transform/qualify_consts.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librustc_data_structures/macros.rs b/src/librustc_data_structures/macros.rs index 7fc23999284a7..40899c414722e 100644 --- a/src/librustc_data_structures/macros.rs +++ b/src/librustc_data_structures/macros.rs @@ -1,13 +1,13 @@ /// A simple static assertion macro. The first argument should be a unique /// ALL_CAPS identifier that describes the condition. #[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]; } } diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 579f75ba51657..84e2caec68e1c 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -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!( From a2168b0259f67ca478255239cdde9b76603b08c8 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 21 May 2019 17:14:09 +0200 Subject: [PATCH 2/2] update doc comment --- src/librustc_data_structures/macros.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/librustc_data_structures/macros.rs b/src/librustc_data_structures/macros.rs index 40899c414722e..b851263aaf9c4 100644 --- a/src/librustc_data_structures/macros.rs +++ b/src/librustc_data_structures/macros.rs @@ -1,5 +1,4 @@ -/// 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, underscore_const_names)] macro_rules! static_assert {