Open
Description
I tried this code:
fn consume_reference<T: ?Sized>(_: &T) {}
async fn foo() {
consume_reference::<i32>(&Box::new(7_i32)); // OK.
consume_reference::<i32>(&async { Box::new(7_i32) }.await); // Error.
consume_reference::<[i32]>(&vec![7_i32]); // OK.
consume_reference::<[i32]>(&async { vec![7_i32] }.await); // OK.
}
I expected to see this happen: The code compiles.
Instead, this happened: This line does not compile while the others lines do:
consume_reference::<i32>(&async { Box::new(7_i32) }.await);
The same thing also happened to awaiting futures::lock::Mutex::lock
function:
fn consume_reference(_: &mut i32) {}
async fn foo() {
let mutex = futures::lock::Mutex::new(7_i32);
consume_reference(&mut mutex.lock().await);
}
Meta
rustc --version --verbose
:
rustc 1.51.0 (2fd73fabe 2021-03-23)
binary: rustc
commit-hash: 2fd73fabe469357a12c2c974c140f67e7cdd76d0
commit-date: 2021-03-23
host: x86_64-pc-windows-msvc
release: 1.51.0
LLVM version: 11.0.1
Metadata
Metadata
Assignees
Labels
Area: Async & AwaitArea: implicit and explicit `expr as Type` coercionsAsync-await issues that have been triaged during a working group meeting.Category: This is a bug.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Status
On deck
Activity
jyn514 commentedon Apr 2, 2021
The error also happens on nightly.
[-]Deref coercion does not work for `await` returned values[/-][+]Deref coercion does not work for some `await` returned values[/+]tmandry commentedon Apr 2, 2021
@rustbot label +E-medium
Not sure what exactly is going wrong here. Doing some code spelunking with
-Ztreat-err-as-bug
(and maybe some added debug logs) should make it possible to trace the issue.ldm0 commentedon Apr 3, 2021
This issue has nothing to do with async or await, this is an old coercion issue: #57749.
pnkfelix commentedon Mar 3, 2022
@rustbot claim
2 remaining items