aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2018-04-26 22:31:01 +0200
committerGravatar Jorge Aparicio <jorge@japaric.io> 2018-04-26 22:31:01 +0200
commitb098b6af6aa48826aa1471ba3359a42d6d3e059a (patch)
tree9bd6f2980efd7c3ebffbc3c7407dbbf76b716d7f
parentbff66f8fa796e305df93f28d9a5e352eb51596e5 (diff)
downloadcortex-m-b098b6af6aa48826aa1471ba3359a42d6d3e059a.tar.gz
cortex-m-b098b6af6aa48826aa1471ba3359a42d6d3e059a.tar.zst
cortex-m-b098b6af6aa48826aa1471ba3359a42d6d3e059a.zip
make singleton! work on stable
-rw-r--r--Cargo.toml7
-rw-r--r--src/lib.rs2
-rw-r--r--src/macros.rs19
3 files changed, 5 insertions, 23 deletions
diff --git a/Cargo.toml b/Cargo.toml
index ceee903..4d93dbb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"]
diff --git a/src/lib.rs b/src/lib.rs
index 802a2d5..407c5ac 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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: () = ();