Confusing diagnostics when using RPIT in `Fn` return type
Open
Nobody has claimed this yet.
A-diagnostics
A-impl-trait
F-impl_trait_in_fn_trait_return
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
#![feature(impl_trait_in_fn_trait_return)]
use std::future::Future;
// ↓↓↓ remove this parameter and it works
fn f<H>() -> impl Fn() -> impl Future {
|| async {}
}
Current output
error: concrete type differs from previous defining opaque type use
--> src/lib.rs:6:8
|
6 | || async {}
| ^^^^^^^^ expected `impl Future`, got `{async block@src/lib.rs:6:8: 6:16}`
|
note: previous use here
--> src/lib.rs:6:5
|
6 | || async {}
| ^^^^^^^^^^^
error[E0720]: cannot resolve opaque type
--> src/lib.rs:5:27
|
5 | fn f<H>() -> impl Fn() -> impl Future {
| ^^^^^^^^^^^ cannot resolve opaque type
This error message doesn't mention <H> or explain why it is a problem.
I tried reproducing the same error message with other chains of impl, but I could only reproduce with FnOnce, Fn and FnMut.
Rust Version
rustc 1.78.0-nightly (b6d2d841b 2024-03-05)
binary: rustc
commit-hash: b6d2d841bcf4b77343b159f134c7d39c2dd4ceaa
commit-date: 2024-03-05
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the provided src/lib.rs example with the reported nightly rustc version and compare the diagnostics for the generic and non-generic forms. Trace the compiler diagnostic path for RPITs nested in Fn, FnMut, and FnOnce return types; done means the error explains the role of H and why the opaque type cannot be resolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100