Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #72036

Merged
merged 21 commits into from
May 9, 2020
Merged

Rollup of 8 pull requests #72036

merged 21 commits into from
May 9, 2020

Conversation

Dylan-DPC-zz
Copy link

Successful merges:

Failed merges:

r? @ghost

Luca Gladiator and others added 21 commits May 3, 2020 14:02
This commit adds some new `LocalDecl` methods:
- `with_source_info`, a most general constructor.
- `new`, a variant of `with_source_info` which represents the most
  common use case.
- `internal` a modifying method (like the already present `immutable`).

It removes some old `LocalDecl` methods:
- `new_internal` and `new_local`, because they're subsumed by the new
  methods.
- `new_return_place`, because it was identical to `new_temp`.

Finally, it cleans up all the use sites.
By boxing `local_info`.
By boxing `user_ty`.
…=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 rust-lang#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)
Make BTreeMap::new and BTreeSet::new const
…amertj

Simplify the error Registry methods a little
…thewjasper

Shrink `LocalDecl`

`LocalDecl` contributes 4-8% of peak heap memory usage on a range of benchmarks. This PR reduces its size from 128 bytes to 56 bytes on 64-bit, and does some clean-ups as well.

r? @matthewjasper
Dead-code pass highlights too much of impl functions

Fixes rust-lang#66627.
Previous diagnostic:
```
error: method is never used: `unused_impl_fn_3`
  --> src/main.rs:28:5
   |
28 | /     fn unused_impl_fn_3(
29 | |         var: i32,
30 | |     ) {
31 | |         println!("bar {}", var);
32 | |     }
   | |_____^
```
New diagnostic:
```
error: associated function is never used: `unused_impl_fn_3`
  --> $DIR/lint-dead-code-6.rs:13:8
   |
LL |     fn unused_impl_fn_3(
   |        ^^^^^^^^^^^^^^^^
```

This makes associated functions in line with free-standing functions.
Fix `strip-priv-imports` pass name in the rustdoc documentation
Better documentation for io::Read::read() return value

Aims to provide the clarity requested in rust-lang#70360
@Dylan-DPC-zz
Copy link
Author

@bors p=8 rollup=never

@Dylan-DPC-zz
Copy link
Author

@bors p+

@Dylan-DPC-zz
Copy link
Author

@bors r+

@bors
Copy link
Contributor

bors commented May 9, 2020

📌 Commit 4b337d2 has been approved by Dylan-DPC

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label May 9, 2020
@bors
Copy link
Contributor

bors commented May 9, 2020

⌛ Testing commit 4b337d2 with merge 945d110...

@bors
Copy link
Contributor

bors commented May 9, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: Dylan-DPC
Pushing 945d110 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 9, 2020
@bors bors merged commit 945d110 into rust-lang:master May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.