Skip to content

Commit b098b6a

Browse files
committed
make singleton! work on stable
1 parent bff66f8 commit b098b6a

File tree

3 files changed

+5
-23
lines changed

3 files changed

+5
-23
lines changed

Cargo.toml

+1-6
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ version = "0.1.2"
2323
default-features = false
2424
version = "0.1.2"
2525

26-
[dependencies.untagged-option]
27-
optional = true
28-
version = "0.1.1"
29-
3026
[features]
3127
cm7-r0p1 = []
32-
default = ["inline-asm", "singleton"]
28+
default = ["inline-asm"]
3329
inline-asm = []
34-
singleton = ["untagged-option"]

src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
extern crate aligned;
1616
extern crate bare_metal;
17-
#[cfg(feature = "singleton")]
18-
extern crate untagged_option;
1917
extern crate volatile_register;
2018

2119
#[macro_use]

src/macros.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,23 @@ macro_rules! iprintln {
5050
/// }
5151
/// ```
5252
#[macro_export]
53-
// TODO(stable) needs stable const `mem::uninitialized` OR stable const `MaybeUninit::new()` (RFC
54-
// 1892)
55-
#[cfg(feature = "singleton")]
5653
macro_rules! singleton {
5754
(: $ty:ty = $expr:expr) => {
5855
$crate::interrupt::free(|_| {
59-
static mut USED: bool = false;
60-
static mut VAR: $crate::UntaggedOption<$ty> = $crate::UntaggedOption { none: () };
56+
static mut VAR: Option<$ty> = None;
6157

6258
#[allow(unsafe_code)]
63-
let used = unsafe { USED };
59+
let used = unsafe { VAR.is_some() };
6460
if used {
6561
None
6662
} else {
67-
#[allow(unsafe_code)]
68-
unsafe { USED = true }
69-
7063
let expr = $expr;
7164

7265
#[allow(unsafe_code)]
73-
unsafe { VAR.some = expr }
66+
unsafe { VAR = Some(expr) }
7467

7568
#[allow(unsafe_code)]
76-
let var: &'static mut _ = unsafe { &mut VAR.some };
77-
78-
Some(var)
69+
unsafe { VAR.as_mut() }
7970
}
8071
})
8172
}
@@ -94,7 +85,6 @@ macro_rules! singleton {
9485
/// }
9586
/// ```
9687
#[allow(dead_code)]
97-
#[cfg(feature = "singleton")]
9888
const CFAIL: () = ();
9989

10090
/// ```
@@ -110,5 +100,4 @@ const CFAIL: () = ();
110100
/// }
111101
/// ```
112102
#[allow(dead_code)]
113-
#[cfg(feature = "singleton")]
114103
const CPASS: () = ();

0 commit comments

Comments
 (0)