Open
Description
Code
I tried this code:
fn conjure<T>() -> T { panic!() }
fn what<T, F: FnOnce() -> T>(_: F) -> impl Sized {
if false {
let _: T = what::<T, _>(move || conjure::<T>());
}
conjure::<T>()
}
I expect the code to compile (although maybe the function might be impossible to call). Instead, on the latest nightly rust (1.88.0-nightly (2025-04-02 d5b4c2e4f19b6d703737)
), I got this error:
error[E0792]: expected generic type parameter, found `{closure@src/lib.rs:5:33: 5:40}`
--> src/lib.rs:5:16
|
3 | fn what<T, F: FnOnce() -> T>(_: F) -> impl Sized {
| - this generic parameter must be used with a generic type parameter
4 | if false {
5 | let _: T = what::<T, _>(move || conjure::<T>());
| ^
For more information about this error, try `rustc --explain E0792`.
Version it worked on
The code compiles fine on rust 1.72.0 on godbolt.
Version with regression
The code gives the above error on rust 1.73.0 on godbolt.
Additional context
I was playing around trying to break rust, and I ran into this.
Removing the : T
type annotation causes the code to compile fine.
The E0792 error emitted by the compiler is an error about TAIT, which is weird, given that the code uses RPIT, not TAIT.
Another variant of the code is:
#[allow(unconditional_recursion)]
fn what<T, F: FnOnce() -> T>(f: F) -> impl Sized {
what(move || what::<T, _>(move || f()))
}
This variant gives:
- the confusing E0792 error since version 1.73.0
- a "concrete type differs from previous defining opaque type use" error in versions 1.65.0 to 1.72.0
- a "broken MIR" internal compiler error in versions 1.61 to 1.64.0
- the arguably correct "cannot resolve opaque type" error in version 1.60.0. (I haven't checked earlier versions than this).
@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged +A-impl-trait
Metadata
Metadata
Assignees
Labels
Area: Documentation for any part of the project, including the compiler, standard library, and toolsArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Category: This is a bug.Relevant to the compiler team, which will review and decide on the PR/issue.Performance or correctness regression from one stable version to another.
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
theemathas commentedon Apr 4, 2025
Another variant:
This compiles and runs fine(!) in version 1.72.0. However, it gives a compilation error since 1.73.0. Again, removing the
: T
annotation makes it compile fine.theemathas commentedon Apr 4, 2025
See also #134838 (comment) for RPIT being weird.
lcnr commentedon Apr 4, 2025
This broke due to #112842 and is intended breakage. The documentation is incorrect in only talking about TAIT as recursive calls can introduce RPIT with non-universal arguments as well, e.g. here the assignment
let _: T = what::<T, _>(conjure::<T>);
tries to defineopaque<T, conjure_fn_def> = T
andconjure_fn_def
is not a generic parameter.theemathas commentedon Apr 5, 2025
Another variant:
This, like the original code, errored since 1.73.0, and compiled fine in 1.72.0
theemathas commentedon Apr 5, 2025
Another variant:
Again, this errored since 1.73.0.
3 remaining items