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

Suggest that Pin<Box<dyn Unpin + Future>> is redundant #95089

Open
jyn514 opened this issue Mar 18, 2022 · 2 comments
Open

Suggest that Pin<Box<dyn Unpin + Future>> is redundant #95089

jyn514 opened this issue Mar 18, 2022 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jyn514
Copy link
Member

jyn514 commented Mar 18, 2022

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=232bc66719a632fbcb8f5d400a58f74e

use core::future::Future;
use core::pin::Pin;
fn f() -> Pin<Box<dyn Unpin + Future<Output = ()>>> {
    Box::pin(async {})
}

The current output is:

error[E0277]: `from_generator::GenFuture<[static generator@src/lib.rs:4:20: 4:22]>` cannot be unpinned
  --> src/lib.rs:4:5
   |
4  |     Box::pin(async {})
   |     ^^^^^^^^^^^^^^^^^^ within `impl Future<Output = [async output]>`, the trait `Unpin` is not implemented for `from_generator::GenFuture<[static generator@src/lib.rs:4:20: 4:22]>`
   |
   = note: consider using `Box::pin`
   = note: required because it appears within the type `impl Future<Output = [async output]>`
   = note: required for the cast to the object type `dyn Future<Output = ()> + Unpin`

For more information about this error, try `rustc --explain E0277`.

Ideally the output should look like:

error[E0277]: async blocks cannot be unpinned
  --> src/lib.rs:4:5
   |
4  |     Box::pin(async {})
   |     ^^^^^^^^^^^^^^^^^^ within `impl Future<Output = ()>`, the trait `Unpin` is not implemented for `from_generator::GenFuture<[static generator@src/lib.rs:4:20: 4:22]>`
   |
   = note: async blocks never implement `Unpin`
   = note: required because it appears within the type `impl Future<Output = [async output]>`
   = note: required for the cast to the object type `dyn Future<Output = ()> + Unpin`

warning: `Pin<Box<dyn Pin + Future<Output = ()>>>` is redundant and most likely not what you intended
   = help: remove the `Unpin` requirement: `Pin<Box<dyn Future<Output = ()>>>`

For more information about this error, try `rustc --explain E0277`.

Pin<Box<T>> is always Unpin and therefore there's no need to require T: Unpin.
Also note the "[async output]" message in the first block; that looks like an outright bug.

@jyn514 jyn514 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 18, 2022
@compiler-errors
Copy link
Member

Also note the "[async output]" message in the first block; that looks like an outright bug.

That's actually just because the pretty-printing code sees an infer variable in the return type of the generator. Might be able to solve this by adding a few resolve_var_if_possible, but that's just the placeholder that the impl Future printing code outputs for unresolved generators.

@jyn514
Copy link
Member Author

jyn514 commented Mar 22, 2022

that's just the placeholder that the impl Future printing code outputs for unresolved generators.

Sure - but to a user it still looks like a bug, it doesn't give them any further information.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 23, 2022
…or-ty, r=oli-obk

remove `[async output]` from `impl Future` pretty-printing

self-explanatory, guess it's not as helpful as I thought when I added it 4 months ago
re rust-lang#95089 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants