File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -1382,3 +1382,6 @@ impl<T> fmt::Debug for Receiver<T> {
13821382 f. pad ( "Receiver { .. }" )
13831383 }
13841384}
1385+
1386+ #[ cfg( test) ]
1387+ mod tests;
Original file line number Diff line number Diff line change 1+ // Ensure that thread_local init with `const { 0 }` still has unique address at run-time
2+ #[ test]
3+ fn waker_current_thread_id ( ) {
4+ let first = super :: waker:: current_thread_id ( ) ;
5+ let t = crate :: thread:: spawn ( move || {
6+ let second = super :: waker:: current_thread_id ( ) ;
7+ assert_ne ! ( first, second) ;
8+ assert_eq ! ( second, super :: waker:: current_thread_id( ) ) ;
9+ } ) ;
10+
11+ assert_eq ! ( first, super :: waker:: current_thread_id( ) ) ;
12+ t. join ( ) . unwrap ( ) ;
13+ assert_eq ! ( first, super :: waker:: current_thread_id( ) ) ;
14+ }
Original file line number Diff line number Diff line change @@ -204,6 +204,6 @@ impl Drop for SyncWaker {
204204pub fn current_thread_id ( ) -> usize {
205205 // `u8` is not drop so this variable will be available during thread destruction,
206206 // whereas `thread::current()` would not be
207- thread_local ! { static DUMMY : u8 = 0 }
207+ thread_local ! { static DUMMY : u8 = const { 0 } }
208208 DUMMY . with ( |x| ( x as * const u8 ) . addr ( ) )
209209}
You can’t perform that action at this time.
0 commit comments