about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2021-05-15 18:47:59 -0400
committerGitHub <noreply@github.com>2021-05-15 23:47:59 +0100
commit750250023f4b8a94d7cb0a45de9485a2c4ee47c3 (patch)
treede99c217f2b469a5e68c7a318683cf4ababa6d7b
parent09a05e02f40f981c73a50bfabc97a42c0e256fba (diff)
downloadrust-750250023f4b8a94d7cb0a45de9485a2c4ee47c3.tar.gz
rust-750250023f4b8a94d7cb0a45de9485a2c4ee47c3.zip
Use `#![feature(const_panic)]` to produce better assertion errors (#1165)
-rw-r--r--library/stdarch/crates/core_arch/src/lib.rs1
-rw-r--r--library/stdarch/crates/core_arch/src/macros.rs4
-rw-r--r--library/stdarch/crates/core_arch/src/x86/macros.rs10
-rw-r--r--library/stdarch/crates/core_arch/src/x86_64/macros.rs4
4 files changed, 10 insertions, 9 deletions
diff --git a/library/stdarch/crates/core_arch/src/lib.rs b/library/stdarch/crates/core_arch/src/lib.rs
index 30209f94446..f69de392557 100644
--- a/library/stdarch/crates/core_arch/src/lib.rs
+++ b/library/stdarch/crates/core_arch/src/lib.rs
@@ -7,6 +7,7 @@
     asm,
     const_fn_union,
     const_fn_transmute,
+    const_panic,
     custom_inner_attributes,
     link_llvm_intrinsics,
     platform_intrinsics,
diff --git a/library/stdarch/crates/core_arch/src/macros.rs b/library/stdarch/crates/core_arch/src/macros.rs
index a82604304ff..5f68ff79f8a 100644
--- a/library/stdarch/crates/core_arch/src/macros.rs
+++ b/library/stdarch/crates/core_arch/src/macros.rs
@@ -5,7 +5,7 @@
 pub(crate) struct ValidateConstImm<const IMM: i32, const MIN: i32, const MAX: i32>;
 impl<const IMM: i32, const MIN: i32, const MAX: i32> ValidateConstImm<IMM, MIN, MAX> {
     pub(crate) const VALID: () = {
-        let _ = 1 / ((IMM >= MIN && IMM <= MAX) as usize);
+        assert!(IMM >= MIN && IMM <= MAX, "IMM value not in expected range");
     };
 }
 
@@ -71,7 +71,7 @@ macro_rules! static_assert {
         struct Validate<const $imm: $ty>();
         impl<const $imm: $ty> Validate<$imm> {
             const VALID: () = {
-                let _ = 1 / ($e as usize);
+                assert!($e, concat!("Assertion failed: ", stringify!($e)));
             };
         }
         let _ = Validate::<$imm>::VALID;
diff --git a/library/stdarch/crates/core_arch/src/x86/macros.rs b/library/stdarch/crates/core_arch/src/x86/macros.rs
index 114bdf32012..b9550ce79c4 100644
--- a/library/stdarch/crates/core_arch/src/x86/macros.rs
+++ b/library/stdarch/crates/core_arch/src/x86/macros.rs
@@ -5,7 +5,7 @@
 pub(crate) struct ValidateConstRound<const IMM: i32>;
 impl<const IMM: i32> ValidateConstRound<IMM> {
     pub(crate) const VALID: () = {
-        let _ = 1 / ((IMM == 4 || IMM == 8 || IMM == 9 || IMM == 10 || IMM == 11) as usize);
+        assert!(IMM == 4 || IMM == 8 || IMM == 9 || IMM == 10 || IMM == 11, "Invalid IMM value");
     };
 }
 
@@ -21,7 +21,7 @@ macro_rules! static_assert_rounding {
 pub(crate) struct ValidateConstSae<const IMM: i32>;
 impl<const IMM: i32> ValidateConstSae<IMM> {
     pub(crate) const VALID: () = {
-        let _ = 1 / ((IMM == 4 || IMM == 8) as usize);
+        assert!(IMM == 4 || IMM == 8, "Invalid IMM value");
     };
 }
 
@@ -37,7 +37,7 @@ macro_rules! static_assert_sae {
 pub(crate) struct ValidateConstMantissasSae<const IMM: i32>;
 impl<const IMM: i32> ValidateConstMantissasSae<IMM> {
     pub(crate) const VALID: () = {
-        let _ = 1 / ((IMM == 4 || IMM == 8 || IMM == 12) as usize);
+        assert!(IMM == 4 || IMM == 8 || IMM == 12, "Invalid IMM value");
     };
 }
 
@@ -53,7 +53,7 @@ macro_rules! static_assert_mantissas_sae {
 pub(crate) struct ValidateConstImmU32<const IMM: u32, const MIN: u32, const MAX: u32>;
 impl<const IMM: u32, const MIN: u32, const MAX: u32> ValidateConstImmU32<IMM, MIN, MAX> {
     pub(crate) const VALID: () = {
-        let _ = 1 / ((IMM >= MIN && IMM <= MAX) as usize);
+        assert!(IMM >= MIN && IMM <= MAX, "IMM value not in expected range");
     };
 }
 
@@ -70,7 +70,7 @@ macro_rules! static_assert_imm_u8 {
 pub(crate) struct ValidateConstGatherScale<const SCALE: i32>;
 impl<const SCALE: i32> ValidateConstGatherScale<SCALE> {
     pub(crate) const VALID: () = {
-        let _ = 1 / ((SCALE == 1 || SCALE == 2 || SCALE == 4 || SCALE == 8) as usize);
+        assert!(SCALE == 1 || SCALE == 2 || SCALE == 4 || SCALE == 8, "Invalid SCALE value");
     };
 }
 
diff --git a/library/stdarch/crates/core_arch/src/x86_64/macros.rs b/library/stdarch/crates/core_arch/src/x86_64/macros.rs
index cafa37dd6fd..9e3faf444d3 100644
--- a/library/stdarch/crates/core_arch/src/x86_64/macros.rs
+++ b/library/stdarch/crates/core_arch/src/x86_64/macros.rs
@@ -5,7 +5,7 @@
 pub(crate) struct ValidateConstRound<const IMM: i32>;
 impl<const IMM: i32> ValidateConstRound<IMM> {
     pub(crate) const VALID: () = {
-        let _ = 1 / ((IMM == 4 || IMM == 8 || IMM == 9 || IMM == 10 || IMM == 11) as usize);
+        assert!(IMM == 4 || IMM == 8 || IMM == 9 || IMM == 10 || IMM == 11, "Invalid IMM value");
     };
 }
 
@@ -21,7 +21,7 @@ macro_rules! static_assert_rounding {
 pub(crate) struct ValidateConstSae<const IMM: i32>;
 impl<const IMM: i32> ValidateConstSae<IMM> {
     pub(crate) const VALID: () = {
-        let _ = 1 / ((IMM == 4 || IMM == 8) as usize);
+        assert!(IMM == 4 || IMM == 8, "Invalid IMM value");
     };
 }