diff options
author | 2018-04-26 22:31:01 +0200 | |
---|---|---|
committer | 2018-04-26 22:31:01 +0200 | |
commit | b098b6af6aa48826aa1471ba3359a42d6d3e059a (patch) | |
tree | 9bd6f2980efd7c3ebffbc3c7407dbbf76b716d7f | |
parent | bff66f8fa796e305df93f28d9a5e352eb51596e5 (diff) | |
download | cortex-m-b098b6af6aa48826aa1471ba3359a42d6d3e059a.tar.gz cortex-m-b098b6af6aa48826aa1471ba3359a42d6d3e059a.tar.zst cortex-m-b098b6af6aa48826aa1471ba3359a42d6d3e059a.zip |
make singleton! work on stable
-rw-r--r-- | Cargo.toml | 7 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/macros.rs | 19 |
3 files changed, 5 insertions, 23 deletions
@@ -23,12 +23,7 @@ version = "0.1.2" default-features = false version = "0.1.2" -[dependencies.untagged-option] -optional = true -version = "0.1.1" - [features] cm7-r0p1 = [] -default = ["inline-asm", "singleton"] +default = ["inline-asm"] inline-asm = [] -singleton = ["untagged-option"] @@ -14,8 +14,6 @@ extern crate aligned; extern crate bare_metal; -#[cfg(feature = "singleton")] -extern crate untagged_option; extern crate volatile_register; #[macro_use] diff --git a/src/macros.rs b/src/macros.rs index 7af64bc..7bbc9be 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -50,32 +50,23 @@ macro_rules! iprintln { /// } /// ``` #[macro_export] -// TODO(stable) needs stable const `mem::uninitialized` OR stable const `MaybeUninit::new()` (RFC -// 1892) -#[cfg(feature = "singleton")] macro_rules! singleton { (: $ty:ty = $expr:expr) => { $crate::interrupt::free(|_| { - static mut USED: bool = false; - static mut VAR: $crate::UntaggedOption<$ty> = $crate::UntaggedOption { none: () }; + static mut VAR: Option<$ty> = None; #[allow(unsafe_code)] - let used = unsafe { USED }; + let used = unsafe { VAR.is_some() }; if used { None } else { - #[allow(unsafe_code)] - unsafe { USED = true } - let expr = $expr; #[allow(unsafe_code)] - unsafe { VAR.some = expr } + unsafe { VAR = Some(expr) } #[allow(unsafe_code)] - let var: &'static mut _ = unsafe { &mut VAR.some }; - - Some(var) + unsafe { VAR.as_mut() } } }) } @@ -94,7 +85,6 @@ macro_rules! singleton { /// } /// ``` #[allow(dead_code)] -#[cfg(feature = "singleton")] const CFAIL: () = (); /// ``` @@ -110,5 +100,4 @@ const CFAIL: () = (); /// } /// ``` #[allow(dead_code)] -#[cfg(feature = "singleton")] const CPASS: () = (); |