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