Commit graph

59 commits

Author SHA1 Message Date
Manish Goregaokar
3cecd6003b Revert "Remove spotlight usage"
This reverts commit 13c6d5819a.
2020-07-16 09:58:34 -07:00
Manish Goregaokar
d82588b45a
Rollup merge of #72303 - yoshuawuyts:future-poll-fn, r=dtolnay
Add core::future::{poll_fn, PollFn}

This is a sibling PR to #70834, adding `future::poll_fn`. This is a small helper function that helps bridge the gap between "poll state machines" and "async/await". It was first introduced in [futures@0.1.7](https://docs.rs/futures/0.1.7/futures/future/fn.poll_fn.html) in December of 2016, and has been tried and tested as part of the ecosystem for the past 3.5 years.

## Implementation

Much of the same reasoning from #70834 applies: by returning a concrete struct rather than an `async fn` we get to mark the future as `Unpin`. It also becomes named which allows storing it in structs without boxing. This implementation has been modified from the implementation in `futures-rs`.

## References
- [`futures::future::poll_fn`](https://docs.rs/futures/0.3.5/futures/future/fn.poll_fn.html)
- [`async_std::future::poll_fn`](https://docs.rs/async-std/1.5.0/async_std/future/fn.poll_fn.html)
2020-07-10 23:26:24 -07:00
LeSeulArtichaut
a1623ff3b6 Deny unsafe ops in unsafe fns, part 6
And final part!!!
2020-06-30 19:28:51 +02:00
Nell Shamrell
5e28eb580f Adds a clearer message for when the async keyword is missing from a function
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
2020-06-25 16:01:45 -07:00
Aaron Hill
9cee22c1a4
Display information about captured variable in FnMut error
Fixes #69446

When we encounter a region error involving an `FnMut` closure, we
display a specialized error message. However, we currently do not
tell the user which upvar was captured. This makes it difficult to
determine the cause of the error, especially when the closure is large.

This commit records marks constraints involving closure upvars
with `ConstraintCategory::ClosureUpvar`. When we decide to 'blame'
a `ConstraintCategory::Return`, we additionall store
the captured upvar if we found a `ConstraintCategory::ClosureUpvar` in
the path.

When generating an error message, we point to relevant spans if we have
closure upvar information available. We further customize the message if
an `async` closure is being returned, to make it clear that the captured
variable is being returned indirectly.
2020-05-25 23:18:00 -04:00
Yoshua Wuyts
9ff502029d Add core::future::IntoFuture
This patch adds `core::future::IntoFuture`. However unlike earlier PRs this patch does not integrate it into the `async/.await` lowering. That integration should be done in a follow-up PR.
2020-05-22 10:55:01 +02:00
Yoshua Wuyts
a31f103fd2 Add core::future::{poll_fn, PollFn} 2020-05-18 21:54:14 +02:00
Dylan DPC
62374ee4ad
Rollup merge of #70834 - yoshuawuyts:future-pending-ready, r=sfackler
Add core::future::{pending,ready}

Adds two future constructors to `core`: `future::ready` and `future::pending`. These functions enable constructing futures of any type that either immediately resolve, or never resolve which is an incredible useful tool when writing documentation.

These functions have prior art in both the `futures` and `async-std` crates. This implementation has been adapted from the `futures` crate.

## Examples

In https://github.com/rust-lang/rust/pull/70817 we propose adding the `ready!` macro. In the example we use an `async fn` which does not return a future that implements `Unpin`, which leads to the use of `unsafe`. Instead had we had `future::ready` available, we could've written the same example without using `unsafe`:

```rust
use core::task::{Context, Poll};
use core::future::{self, Future};
use core::pin::Pin;

pub fn do_poll(cx: &mut Context<'_>) -> Poll<()> {
    let mut fut = future::ready(42_u8);
    let num = ready!(Pin::new(fut).poll(cx));
    // ... use num

    Poll::Ready(())
}
```

## Why future::ready?

Arguably `future::ready` and `async {}` can be considered equivalent. The main differences are that `future::ready` returns a future that implements `Unpin`, and the returned future is a concrete type. This is useful for traits that require a future as an associated type that can sometimes be a no-op ([example](https://docs.rs/http-service/0.4.0/http_service/trait.HttpService.html#associatedtype.ConnectionFuture)).

The final, minor argument is that `future::ready` and `future::pending` form a counterpart to the enum members of `Poll`: `Ready` and `Pending`. These functions form a conceptual bridge between `Poll` and `Future`, and can be used as a useful teaching device.

## References
- [`futures::future::ready`](https://docs.rs/futures/0.3.4/futures/future/fn.ready.html)
- [`futures::future::pending`](https://docs.rs/futures/0.3.4/futures/future/fn.pending.html)
- [`async_std::future::pending`](https://docs.rs/async-std/1.5.0/async_std/future/fn.pending.html)
- [`async_std::future::ready`](https://docs.rs/async-std/1.5.0/async_std/future/fn.ready.html)
2020-05-09 03:10:01 +02:00
Yoshua Wuyts
029515d916 Add core::future::{pending,ready} 2020-05-07 15:19:27 +02:00
Mark Rousskov
93eed402ad Bump bootstrap compiler 2020-04-25 09:25:33 -04:00
Steven Fackler
5dc8ec8dc3 Remove a stack frame from .await calls 2020-04-05 18:51:21 -07:00
Jonas Schievink
db0126a7c2 Add issue reference 2020-03-17 22:19:11 +01:00
Jonas Schievink
e419168bb8 Clarify comment 2020-03-17 22:17:31 +01:00
Jonas Schievink
50b9d772db Make ResumeTy contents private 2020-03-17 22:17:31 +01:00
Jonas Schievink
be62aed202 Remove useless derives on GenFuture
Not sure why these were there, I guess because this type used
to kind of be part of public API?
2020-03-17 22:17:31 +01:00
Jonas Schievink
b7fba973cb Format 2020-03-17 22:17:31 +01:00
Jonas Schievink
1a764a7ef5 Add futures scaffolding to libcore 2020-03-17 22:17:31 +01:00
Guillaume Gomez
13c6d5819a Remove spotlight usage 2020-02-27 14:51:22 +01:00
Wesley Wiser
717702dffd Revert "core: add IntoFuture trait and support for await"
This reverts commit f35517ee86.
2019-12-31 19:18:08 -05:00
Sean McArthur
f35517ee86 core: add IntoFuture trait and support for await 2019-12-27 11:56:11 -08:00
Ilija Tovilo
3a6a29b4ec
Use associated_type_bounds where applicable - closes #61738 2019-08-08 22:39:15 +02:00
Bruce Mitchener
325c6a56c2 Futures: Add link to Waker in trait doc. 2019-08-02 01:39:25 +07:00
Mark Rousskov
8a7dded1a2 Switch master to 1.38 2019-07-04 11:26:57 -04:00
Nathan Corbyn
88194200e5 Add suggestion for missing .await keyword 2019-06-27 13:56:55 +01:00
diwic
5c5f08ab93
Use .await syntax instead of await! 2019-05-27 07:27:13 +02:00
Benjamin Schultzer
58c6a94f00 Improve the "must use" lint for Future
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-05-13 16:01:20 -07:00
Taylor Cramer
3f966dcd53 Stabilize futures_api 2019-04-23 16:13:53 -07:00
Jim Blandy
f8f02debbb core::future::Future: Fix markup typo in docs. 2019-04-19 19:25:40 -07:00
Jim Blandy
d0b84e9a8b Doc fixes for core::future::Future.
Fixed outdated reference to `waker` argument; now futures are passed a
`Context`, from which one can obtain a `waker`.

Cleaned up explanation of what happens when you call `poll` on a completed
future. It doesn't make sense to say that `poll` implementations can't cause
memory unsafety; no safe function is ever allowed to cause memory unsafety, so
why mention it here? It seems like the intent is to say that the `Future` trait
doesn't say what the consequences of excess polls will be, and they might be
bad; but that the usual constraints that Rust imposes on any non-`unsafe`
function still apply. It's also oddly specific to say 'memory corruption'
instead of just 'undefined behavior'; UB is a bit jargony, so the text should
provide examples.
2019-04-19 19:10:24 -07:00
Taiki Endo
360432f1e8 libcore => 2018 2019-04-18 14:47:35 +09:00
Taylor Cramer
1691e06db6 Future-proof the Futures API 2019-04-05 15:03:33 -07:00
Stjepan Glavina
102436d16a Put Future trait into spotlight 2019-02-20 22:06:30 +01:00
kennytm
09c85a1d22
Rollup merge of #58565 - thomaseizinger:typo-future-docs, r=frewsxcv
Fix typo in std::future::Future docs

I am not quite sure if this is actually a typo but

1. to me the sentence doesn't make sense if it says "expect"
2. I hope that `Future`s are not really allowed to cause memory unsafety if they are polled after completion.
2019-02-20 11:59:17 +08:00
kennytm
e3a8f7db47
Rollup merge of #58553 - scottmcm:more-ihle, r=Centril
Use more impl header lifetime elision

Inspired by seeing explicit lifetimes on these two:

- https://doc.rust-lang.org/nightly/std/slice/struct.Iter.html#impl-FusedIterator
- https://doc.rust-lang.org/nightly/std/primitive.u32.html#impl-Not

And a follow-up to https://github.com/rust-lang/rust/pull/54687, that started using IHLE in libcore.

Most of the changes in here fall into two big categories:

- Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop`, `Debug`, and `Clone`)

- Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`)

I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations [where the flipped one cannot elide the lifetime](https://internals.rust-lang.org/t/impl-type-parameter-aliases/9403/2?u=scottmcm).

I also removed two lifetimes that turned out to be completely unused; see https://github.com/rust-lang/rust/issues/41960#issuecomment-464557423
2019-02-20 11:59:10 +08:00
Thomas Eizinger
75c541f228 Fix typo in std::future::Future docs 2019-02-19 09:36:41 +11:00
Scott McMurray
3bea2ca49d Use more impl header lifetime elision
There are two big categories of changes in here

- Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop` & `Debug`)
- Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`)

I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations where the flipped one cannot elide the lifetime.
2019-02-17 19:42:36 -08:00
Matthias Einwag
871338c3ae Merging master 2019-02-12 22:46:14 -08:00
Alexander Regueiro
99ed06eb88 libs: doc comments 2019-02-10 23:57:25 +00:00
Matthias Einwag
363e992b98 review suggestions 2019-02-05 01:30:00 -08:00
Matthias Einwag
e1ec81459d Apply more review suggestions 2019-02-05 01:14:09 -08:00
Matthias Einwag
d9a4b22d32 Update the future/task API
This change updates the future and task API as discussed in the stabilization RFC at https://github.com/rust-lang/rfcs/pull/2592.

Changes:
- Replacing UnsafeWake with RawWaker and RawWakerVtable
- Removal of LocalWaker
- Removal of Arc-based Wake trait
2019-02-03 13:46:53 -08:00
Taiki Endo
6d442938e0 Add #[must_use] message to Iterator and Future 2019-01-13 02:57:27 +09:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Taylor Cramer
20d694a95f Update Pin API to match the one proposed for stabilization
Remove pin::Unpin reexport and add Unpin to the prelude.
Change Pin associated functions to methods.
Rename get_mut_unchecked_ to get_unchecked_mut
Remove impl Unpin for Pin
Mark Pin repr(transparent)
2018-12-21 20:41:24 -08:00
Felix Chapman
ecc4ca54a4 Add #[must_use] attribute to stdlib traits 2018-12-10 14:45:26 +00:00
Bruce Mitchener
9b4d68e53b Fix documentation typos. 2018-11-10 19:31:49 +07:00
Taylor Cramer
1b00f0b9fa Remove spawning from task::Context 2018-09-19 15:01:19 -07:00
Taylor Cramer
3ec1810e32 Cleanup and fix method resolution issue 2018-09-17 16:31:33 -07:00
Without Boats
974bdc80fe
Update to a new pinning API. 2018-09-01 06:57:58 +02:00
Niv Kaminer
13da951868 move PinMut into pin module and export through std 2018-08-23 01:37:03 +03:00