File tree 4 files changed +9
-8
lines changed
4 files changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ impl<T: Send + Sync + 'static> Lazy<T> {
37
37
let ptr = self . ptr . get ( ) ;
38
38
let ret = if ptr. is_null ( ) {
39
39
Some ( self . init ( ) )
40
- } else if ptr as usize == 1 {
40
+ } else if ptr == ptr :: dangling_mut ( ) {
41
41
None
42
42
} else {
43
43
Some ( ( * ptr) . clone ( ) )
@@ -55,7 +55,7 @@ impl<T: Send + Sync + 'static> Lazy<T> {
55
55
let registered = sys_common:: at_exit ( move || {
56
56
self . lock . lock ( ) ;
57
57
let ptr = self . ptr . get ( ) ;
58
- self . ptr . set ( 1 as * mut _ ) ;
58
+ self . ptr . set ( ptr :: dangling_mut ( ) ) ;
59
59
self . lock . unlock ( ) ;
60
60
drop ( Box :: from_raw ( ptr) )
61
61
} ) ;
Original file line number Diff line number Diff line change 301
301
#![ feature( placement_in_syntax) ]
302
302
#![ feature( placement_new_protocol) ]
303
303
#![ feature( prelude_import) ]
304
+ #![ feature( ptr_dangling) ]
304
305
#![ feature( rand) ]
305
306
#![ feature( raw) ]
306
307
#![ feature( repr_align) ]
Original file line number Diff line number Diff line change 36
36
//! ```ignore (cannot-doctest-private-modules)
37
37
//! let key = Key::new(None);
38
38
//! assert!(key.get().is_null());
39
- //! key.set(1 as *mut u8 );
39
+ //! key.set(std::ptr::dangling_mut::<u8>() );
40
40
//! assert!(!key.get().is_null());
41
41
//!
42
42
//! drop(key); // deallocate this TLS slot.
50
50
//!
51
51
//! unsafe {
52
52
//! assert!(KEY.get().is_null());
53
- //! KEY.set(1 as *mut u8 );
53
+ //! KEY.set(std::ptr::dangling_mut::<u8>() );
54
54
//! }
55
55
//! ```
56
56
@@ -81,7 +81,7 @@ use sys_common::mutex::Mutex;
81
81
///
82
82
/// unsafe {
83
83
/// assert!(KEY.get().is_null());
84
- /// KEY.set(1 as *mut u8 );
84
+ /// KEY.set(std::ptr::dangling_mut::<u8>() );
85
85
/// }
86
86
/// ```
87
87
pub struct StaticKey {
@@ -110,7 +110,7 @@ pub struct StaticKey {
110
110
///
111
111
/// let key = Key::new(None);
112
112
/// assert!(key.get().is_null());
113
- /// key.set(1 as *mut u8 );
113
+ /// key.set(std::ptr::dangling_mut::<u8>() );
114
114
/// assert!(!key.get().is_null());
115
115
///
116
116
/// drop(key); // deallocate this TLS slot.
Original file line number Diff line number Diff line change @@ -492,7 +492,7 @@ pub mod os {
492
492
pub unsafe fn get ( & ' static self ) -> Option < & ' static UnsafeCell < Option < T > > > {
493
493
let ptr = self . os . get ( ) as * mut Value < T > ;
494
494
if !ptr. is_null ( ) {
495
- if ptr as usize == 1 {
495
+ if ptr == ptr :: dangling_mut ( ) {
496
496
return None
497
497
}
498
498
return Some ( & ( * ptr) . value ) ;
@@ -520,7 +520,7 @@ pub mod os {
520
520
// before we return from the destructor ourselves.
521
521
let ptr = Box :: from_raw ( ptr as * mut Value < T > ) ;
522
522
let key = ptr. key ;
523
- key. os . set ( 1 as * mut u8 ) ;
523
+ key. os . set ( ptr :: dangling_mut ( ) ) ;
524
524
drop ( ptr) ;
525
525
key. os . set ( ptr:: null_mut ( ) ) ;
526
526
}
You can’t perform that action at this time.
0 commit comments