Universe errors involving an opaque type results in hallucinations and unused bound vars #124472
Open
Description
opened on Apr 28, 2024
Code (Rust ≥2018)
use std::future::Future;
fn main() {
consume_async(async_fn);
}
async fn async_fn(_: &u32) {}
fn consume_async<F>(_: impl FnOnce(&u32) -> F) where F: Future<Output = ()> {}
Current output
error[E0308]: mismatched types
--> ./t.rs:4:5
|
4 | consume_async(async_fn);
| ^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected opaque type `impl for<'a> Future<Output = ()>`
found opaque type `impl Future<Output = ()>`
= help: consider `await`ing on both `Future`s
= note: distinct uses of `impl Trait` result in different opaque types
note: the lifetime requirement is introduced here
--> ./t.rs:9:45
|
9 | fn consume_async<F>(_: impl FnOnce(&u32) -> F) where F: Future<Output = ()> {}
| ^
Desired output
error[E0308]: mismatched types
--> ./t.rs:4:5
|
4 | consume_async(async_fn);
| ^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected `_`
found some type `for<'a> T<'a>` which implements `Future<Output = ()>`
note: the lifetime requirement is introduced here
--> ./t.rs:9:45
|
9 | fn consume_async<F>(_: impl FnOnce(&u32) -> F) where F: Future<Output = ()> {}
| ^
Rationale and extra context
It's very confusing to see a second opaque type and suggestions "to await both futures" (???, there is only one). Ideally we would properly note that the generic can't name the lifetime or something.
Other cases
No response
Rust Version
rustc 1.79.0-nightly (ef8b9dcf2 2024-04-24)
binary: rustc
commit-hash: ef8b9dcf23700f2e2265317611460d3a65c19eff
commit-date: 2024-04-24
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.4
Anything else?
#124471 has a simiular test case/issue but without the opaque types.
Metadata
Assignees
Labels
Area: Async & AwaitArea: Messages for errors, warnings, and lintsArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: Lifetimes / regionsAsync-await issues that have been triaged during a working group meeting.Diagnostics: Confusing error or lint that should be reworked.Relevant to the compiler team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.Fixed by `#![feature(async_closure)]`
Activity