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

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

Closed
WaffleLapkin opened this issue Oct 22, 2021 · 2 comments · Fixed by #90303
Closed

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

WaffleLapkin opened this issue Oct 22, 2021 · 2 comments · Fixed by #90303
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

@WaffleLapkin
Copy link
Member

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).

@WaffleLapkin WaffleLapkin 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 Oct 22, 2021
@WaffleLapkin
Copy link
Member Author

MRE: (playground)

fn copy<R: Unpin, W>(_: R, _: W) {}

fn f<T>(r: T) {
    let w = ();
    copy(r, w);
}
error[E0277]: `T` cannot be unpinned
 --> src/lib.rs:5:13
  |
5 |     copy(r, w);
  |     ----    ^ the trait `Unpin` is not implemented for `T`
  |     |
  |     required by a bound introduced by this call
  |
  = note: consider using `Box::pin`
note: required by a bound in `copy`
 --> src/lib.rs:1:12
  |
1 | fn copy<R: Unpin, W>(_: R, _: W) {}
  |            ^^^^^ required by this bound in `copy`
help: consider restricting type parameter `T`
  |
3 | fn f<T: std::marker::Unpin>(r: T) {
  |       ++++++++++++++++++++

@hkmatsumoto
Copy link
Member

hkmatsumoto commented Oct 24, 2021

Looks like a duplicate of #90101, but the MRE is nice and clean so we could use add it as a regression test.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 26, 2021
… r=JohnTitor

Add regression test for issue 90164

Closes rust-lang#90164 (previously fixed by rust-lang#90181)
@bors bors closed this as completed in 40d3819 Oct 26, 2021
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

Successfully merging a pull request may close this issue.

2 participants