aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2019-02-15 20:23:32 +0100
committerGravatar Jorge Aparicio <jorge@japaric.io> 2019-02-19 13:13:16 +0100
commit28ee83dfdd76ffad0487bad83636fa600084c834 (patch)
tree8ac2879121a7380339f6e5d8ceea04987ecc10f8 /src
parentfe70817653db4f53c3069fb733b73f06ddedfbcf (diff)
downloadrtic-28ee83dfdd76ffad0487bad83636fa600084c834.tar.gz
rtic-28ee83dfdd76ffad0487bad83636fa600084c834.tar.zst
rtic-28ee83dfdd76ffad0487bad83636fa600084c834.zip
turn all potential UB into panics
Diffstat (limited to 'src')
-rw-r--r--src/export.rs38
1 files changed, 8 insertions, 30 deletions
diff --git a/src/export.rs b/src/export.rs
index f8fc8157..495468e1 100644
--- a/src/export.rs
+++ b/src/export.rs
@@ -1,7 +1,5 @@
//! IMPLEMENTATION DETAILS. DO NOT USE ANYTHING IN THIS MODULE
-#[cfg(all(not(feature = "nightly"), not(debug_assertions)))]
-use core::hint;
#[cfg(not(feature = "nightly"))]
use core::ptr;
use core::{cell::Cell, u8};
@@ -99,6 +97,10 @@ pub struct MaybeUninit<T> {
}
#[cfg(not(feature = "nightly"))]
+const MSG: &str =
+ "you have hit a bug (UB) in RTFM implementation; try enabling this crate 'nightly' feature";
+
+#[cfg(not(feature = "nightly"))]
impl<T> MaybeUninit<T> {
pub const fn uninitialized() -> Self {
MaybeUninit { value: None }
@@ -108,13 +110,7 @@ impl<T> MaybeUninit<T> {
if let Some(x) = self.value.as_ref() {
x
} else {
- match () {
- // Try to catch UB when compiling in release with debug assertions enabled
- #[cfg(debug_assertions)]
- () => unreachable!(),
- #[cfg(not(debug_assertions))]
- () => unsafe { hint::unreachable_unchecked() },
- }
+ unreachable!(MSG)
}
}
@@ -122,13 +118,7 @@ impl<T> MaybeUninit<T> {
if let Some(x) = self.value.as_mut() {
x
} else {
- match () {
- // Try to catch UB when compiling in release with debug assertions enabled
- #[cfg(debug_assertions)]
- () => unreachable!(),
- #[cfg(not(debug_assertions))]
- () => unsafe { hint::unreachable_unchecked() },
- }
+ unreachable!(MSG)
}
}
@@ -136,13 +126,7 @@ impl<T> MaybeUninit<T> {
if let Some(x) = self.value.as_ref() {
x
} else {
- match () {
- // Try to catch UB when compiling in release with debug assertions enabled
- #[cfg(debug_assertions)]
- () => unreachable!(),
- #[cfg(not(debug_assertions))]
- () => hint::unreachable_unchecked(),
- }
+ unreachable!(MSG)
}
}
@@ -150,13 +134,7 @@ impl<T> MaybeUninit<T> {
if let Some(x) = self.value.as_mut() {
x
} else {
- match () {
- // Try to catch UB when compiling in release with debug assertions enabled
- #[cfg(debug_assertions)]
- () => unreachable!(),
- #[cfg(not(debug_assertions))]
- () => hint::unreachable_unchecked(),
- }
+ unreachable!(MSG)
}
}