mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
static_assert: make use of anonymous constants
This commit is contained in:
parent
46ad3e1882
commit
5ea5fe3072
@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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!(
|
||||
|
Loading…
Reference in New Issue
Block a user