Skip to content

... cannot be unpinned diagnostic uses a wrong span #90164

Closed
@WaffleLapkin

Description

@WaffleLapkin

Given the following code: (playground)

use tokio::io::{self, AsyncRead};
use tokio::fs::File;

async fn f(mut r: impl AsyncRead) -> Result<(), ()> {
    let mut file = File::open("").await.map_err(drop)?;

    io::copy(&mut r, &mut file).await.map_err(drop)?;

    Ok(())
}

The current output is:

error[E0277]: `impl AsyncRead` cannot be unpinned
   --> src/lib.rs:7:22
    |
7   |     io::copy(&mut r, &mut file).await.map_err(drop)?;
    |     --------         ^^^^^^^^^ the trait `Unpin` is not implemented for `impl AsyncRead`
    |     |
    |     required by a bound introduced by this call
    |
    = note: consider using `Box::pin`
note: required by a bound in `tokio::io::copy`
   --> /playground/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.11.0/src/io/util/copy.rs:143:24
    |
143 |         R: AsyncRead + Unpin + ?Sized,
    |                        ^^^^^ required by this bound in `tokio::io::copy`
help: consider further restricting this bound
    |
4   | async fn f(mut r: impl AsyncRead + std::marker::Unpin) -> Result<(), ()> {
    |                                  ++++++++++++++++++++

The error mentions impl AsyncRead (ie the &mut r argument), but points to the other argument (&mut file, tokio::fs::File).

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