mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-27 14:04:56 +01:00
turn all potential UB into panics
This commit is contained in:
parent
fe70817653
commit
28ee83dfdd
1 changed files with 8 additions and 30 deletions
|
@ -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};
|
||||
|
@ -98,6 +96,10 @@ pub struct MaybeUninit<T> {
|
|||
value: Option<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 {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue