@@ -195,7 +195,7 @@ impl RawWakerVTable {
195
195
#[ lang = "Context" ]
196
196
pub struct Context < ' a > {
197
197
waker : Option < & ' a Waker > ,
198
- local_waker : Option < & ' a LocalWaker > ,
198
+ local_waker : & ' a LocalWaker ,
199
199
// Ensure we future-proof against variance changes by forcing
200
200
// the lifetime to be invariant (argument-position lifetimes
201
201
// are contravariant while return-position lifetimes are
@@ -238,11 +238,7 @@ impl<'a> Context<'a> {
238
238
/// Returns a reference to the [`LocalWaker`] for the current task.
239
239
#[ unstable( feature = "local_waker" , issue = "none" ) ]
240
240
pub fn local_waker ( & self ) -> & ' a LocalWaker {
241
- // Safety:
242
- // It is safe to transmute a `&Waker` into a `&LocalWaker` since both are a transparent
243
- // wrapper around a local waker. Also, the Option<&Waker> here cannot be None since it is
244
- // impossible to construct a Context without any waker set.
245
- self . local_waker . unwrap_or_else ( || unsafe { transmute ( self . waker ) } )
241
+ & self . local_waker
246
242
}
247
243
}
248
244
@@ -325,7 +321,7 @@ impl<'a> ContextBuilder<'a> {
325
321
}
326
322
327
323
/// Builds the `Context`.
328
- ///
324
+ ///
329
325
/// # Panics
330
326
/// Panics if no `Waker` or `LocalWaker` is set.
331
327
#[ inline]
@@ -337,6 +333,16 @@ impl<'a> ContextBuilder<'a> {
337
333
waker. is_some( ) || local_waker. is_some( ) ,
338
334
"at least one waker must be set with either the `local_waker` or `waker` methods on `ContextBuilder`."
339
335
) ;
336
+ let local_waker = match local_waker {
337
+ Some ( local_waker) => local_waker,
338
+ None => {
339
+ // SAFETY:
340
+ // It is safe to transmute a `&Waker` into a `&LocalWaker` since both are a transparent
341
+ // wrapper around a local waker. Also, the Option<&Waker> here cannot be None because
342
+ // of the previous assert.
343
+ unsafe { transmute ( self . waker ) }
344
+ }
345
+ } ;
340
346
Context { waker, local_waker, _marker : PhantomData , _marker2 : PhantomData }
341
347
}
342
348
}
@@ -576,9 +582,10 @@ impl fmt::Debug for Waker {
576
582
/// return Poll::Ready(())
577
583
/// })
578
584
/// }
579
- /// # async {
585
+ /// # #[allow(unused_must_use)]
586
+ /// # async fn __() {
580
587
/// yield_now().await;
581
- /// # };
588
+ /// # }
582
589
/// ```
583
590
///
584
591
/// [`Future::poll()`]: core::future::Future::poll
0 commit comments