diff --git a/library/core/src/option.rs b/library/core/src/option.rs index fe8ec7db184b7..e0d753d4ace72 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -551,9 +551,12 @@ use crate::marker::Destruct; use crate::panicking::{panic, panic_str}; use crate::pin::Pin; use crate::{ - cmp, convert, hint, mem, + cmp, convert, + future::Future, + hint, mem, ops::{self, ControlFlow, Deref, DerefMut}, slice, + task::Poll, }; /// The `Option` type. See [the module level documentation](self) for more. @@ -2293,6 +2296,19 @@ impl SpecOptionPartialEq for cmp::Ordering { } } +#[stable(feature = "option_future", since = "CURRENT_RUSTC_VERSION")] +impl Future for Option { + type Output = Option; + + #[inline] + fn poll(self: Pin<&mut Self>, cx: &mut crate::task::Context<'_>) -> Poll { + match self.as_pin_mut() { + Some(f) => f.poll(cx).map(Some), + None => Poll::Ready(None), + } + } +} + ///////////////////////////////////////////////////////////////////////////// // The Option Iterators ///////////////////////////////////////////////////////////////////////////// diff --git a/tests/ui/async-await/drop-track-bad-field-in-fru.rs b/tests/ui/async-await/drop-track-bad-field-in-fru.rs index 28ad7767583cf..c483505d8839b 100644 --- a/tests/ui/async-await/drop-track-bad-field-in-fru.rs +++ b/tests/ui/async-await/drop-track-bad-field-in-fru.rs @@ -5,6 +5,5 @@ fn main() {} async fn foo() { None { value: (), ..Default::default() }.await; - //~^ ERROR `Option<_>` is not a future - //~| ERROR variant `Option<_>::None` has no field named `value` + //~^ ERROR variant `Option<_>::None` has no field named `value` } diff --git a/tests/ui/async-await/drop-track-bad-field-in-fru.stderr b/tests/ui/async-await/drop-track-bad-field-in-fru.stderr index 819b64ad77f5d..e087d156f760b 100644 --- a/tests/ui/async-await/drop-track-bad-field-in-fru.stderr +++ b/tests/ui/async-await/drop-track-bad-field-in-fru.stderr @@ -4,20 +4,6 @@ error[E0559]: variant `Option<_>::None` has no field named `value` LL | None { value: (), ..Default::default() }.await; | ^^^^^ `Option<_>::None` does not have this field -error[E0277]: `Option<_>` is not a future - --> $DIR/drop-track-bad-field-in-fru.rs:7:45 - | -LL | None { value: (), ..Default::default() }.await; - | ^^^^^^ - | | - | `Option<_>` is not a future - | help: remove the `.await` - | - = help: the trait `Future` is not implemented for `Option<_>` - = note: Option<_> must be a future or must implement `IntoFuture` to be awaited - = note: required for `Option<_>` to implement `IntoFuture` - -error: aborting due to 2 previous errors +error: aborting due to previous error -Some errors have detailed explanations: E0277, E0559. -For more information about an error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0559`.