Skip to content

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

Open
@jyn514

Description

@jyn514

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions