File tree 1 file changed +9
-5
lines changed
1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,9 @@ macro_rules! iprintln {
43
43
/// let y = alias();
44
44
/// // BAD this second call to `alias` will definitively `panic!`
45
45
/// let y_alias = alias();
46
+ ///
47
+ /// # // check that the call to `uninitialized` requires unsafe
48
+ /// # singleton!(: u8 = unsafe { std::mem::uninitialized() });
46
49
/// }
47
50
///
48
51
/// fn alias() -> &'static mut bool {
@@ -52,16 +55,17 @@ macro_rules! iprintln {
52
55
#[ macro_export]
53
56
macro_rules! singleton {
54
57
( : $ty: ty = $expr: expr) => {
55
- $crate:: interrupt:: free( |_| unsafe {
58
+ $crate:: interrupt:: free( |_| {
56
59
static mut USED : bool = false ;
57
60
static mut VAR : $crate:: UntaggedOption <$ty> = $crate:: UntaggedOption { none: ( ) } ;
58
61
59
- if USED {
62
+ if unsafe { USED } {
60
63
None
61
64
} else {
62
- USED = true ;
63
- VAR . some = $expr;
64
- let var: & ' static mut _ = & mut VAR . some;
65
+ unsafe { USED = true }
66
+ let expr = $expr;
67
+ unsafe { VAR . some = expr }
68
+ let var: & ' static mut _ = unsafe { & mut VAR . some } ;
65
69
Some ( var)
66
70
}
67
71
} )
You can’t perform that action at this time.
0 commit comments