1+ #![ feature( ub_checks) ]
12#![ stable( feature = "wake_trait" , since = "1.51.0" ) ]
23
34//! Types and Traits for working with asynchronous tasks.
78//! This may be detected at compile time using
89//! `#[cfg(target_has_atomic = "ptr")]`.
910
11+ use safety:: { ensures, requires} ;
12+ #[ cfg( kani) ]
13+ #[ unstable( feature = "kani" , issue = "none" ) ]
14+ use core:: kani;
15+ #[ allow( unused_imports) ]
16+ #[ unstable( feature = "ub_checks" , issue = "none" ) ]
17+ use core:: ub_checks:: * ;
18+
1019use core:: mem:: ManuallyDrop ;
1120#[ cfg( target_has_atomic = "ptr" ) ]
1221use core:: task:: Waker ;
@@ -145,6 +154,7 @@ fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {
145154 // the vtable pointers, rather than comparing all four function pointers
146155 // within the vtables.
147156 #[ inline( always) ]
157+ #[ requires( waker != core:: ptr:: null( ) ) ]
148158 unsafe fn clone_waker < W : Wake + Send + Sync + ' static > ( waker : * const ( ) ) -> RawWaker {
149159 unsafe { Arc :: increment_strong_count ( waker as * const W ) } ;
150160 RawWaker :: new (
@@ -154,18 +164,21 @@ fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {
154164 }
155165
156166 // Wake by value, moving the Arc into the Wake::wake function
167+ #[ requires( waker != core:: ptr:: null( ) ) ]
157168 unsafe fn wake < W : Wake + Send + Sync + ' static > ( waker : * const ( ) ) {
158169 let waker = unsafe { Arc :: from_raw ( waker as * const W ) } ;
159170 <W as Wake >:: wake ( waker) ;
160171 }
161172
162173 // Wake by reference, wrap the waker in ManuallyDrop to avoid dropping it
174+ #[ requires( waker != core:: ptr:: null( ) ) ]
163175 unsafe fn wake_by_ref < W : Wake + Send + Sync + ' static > ( waker : * const ( ) ) {
164176 let waker = unsafe { ManuallyDrop :: new ( Arc :: from_raw ( waker as * const W ) ) } ;
165177 <W as Wake >:: wake_by_ref ( & waker) ;
166178 }
167179
168180 // Decrement the reference count of the Arc on drop
181+ #[ requires( waker != core:: ptr:: null( ) ) ]
169182 unsafe fn drop_waker < W : Wake + Send + Sync + ' static > ( waker : * const ( ) ) {
170183 unsafe { Arc :: decrement_strong_count ( waker as * const W ) } ;
171184 }
@@ -318,6 +331,7 @@ fn local_raw_waker<W: LocalWake + 'static>(waker: Rc<W>) -> RawWaker {
318331 // Refer to the comment on raw_waker's clone_waker regarding why this is
319332 // always inline.
320333 #[ inline( always) ]
334+ #[ requires( waker != core:: ptr:: null( ) ) ]
321335 unsafe fn clone_waker < W : LocalWake + ' static > ( waker : * const ( ) ) -> RawWaker {
322336 unsafe { Rc :: increment_strong_count ( waker as * const W ) } ;
323337 RawWaker :: new (
@@ -327,18 +341,21 @@ fn local_raw_waker<W: LocalWake + 'static>(waker: Rc<W>) -> RawWaker {
327341 }
328342
329343 // Wake by value, moving the Rc into the LocalWake::wake function
344+ #[ requires( waker != core:: ptr:: null( ) ) ]
330345 unsafe fn wake < W : LocalWake + ' static > ( waker : * const ( ) ) {
331346 let waker = unsafe { Rc :: from_raw ( waker as * const W ) } ;
332347 <W as LocalWake >:: wake ( waker) ;
333348 }
334349
335350 // Wake by reference, wrap the waker in ManuallyDrop to avoid dropping it
351+ #[ requires( waker != core:: ptr:: null( ) ) ]
336352 unsafe fn wake_by_ref < W : LocalWake + ' static > ( waker : * const ( ) ) {
337353 let waker = unsafe { ManuallyDrop :: new ( Rc :: from_raw ( waker as * const W ) ) } ;
338354 <W as LocalWake >:: wake_by_ref ( & waker) ;
339355 }
340356
341357 // Decrement the reference count of the Rc on drop
358+ #[ requires( waker != core:: ptr:: null( ) ) ]
342359 unsafe fn drop_waker < W : LocalWake + ' static > ( waker : * const ( ) ) {
343360 unsafe { Rc :: decrement_strong_count ( waker as * const W ) } ;
344361 }
0 commit comments