Confusing diagnostics with nested precise capturing RPIT #133716
Open
Description
opened on Dec 1, 2024
Code
#![feature(impl_trait_in_fn_trait_return)]
trait Foo {}
impl Foo for &() {}
fn foo<'a>(u: &'a ()) -> impl FnOnce() -> (impl Foo + use<'a>) + use<'a> {
move || u
}
Current output
error[E0700]: hidden type for `impl Foo` captures lifetime that does not appear in bounds
--> src/main.rs:7:13
|
6 | fn foo<'a>(u: &'a ()) -> impl FnOnce() -> (impl Foo + use<'a>) + use<'a> {
| ------------------ opaque type defined here
7 | move || u
| ^
|
= note: hidden type `&()` captures lifetime `'_`
error[E0720]: cannot resolve opaque type
--> src/main.rs:6:44
|
6 | fn foo<'a>(u: &'a ()) -> impl FnOnce() -> (impl Foo + use<'a>) + use<'a> {
| ^^^^^^^^^^^^^^^^^^ recursive opaque type
7 | move || u
| --------- returning here with type `{closure@src/main.rs:7:5: 7:12}`
Desired output
Rationale and extra context
I assume using precise capturing in this position isn't meant to be supported.
Both of these diagnostics seem inaccurate.
The first is talking about some elided lifetime, when the only relevant lifetime is named.
The second is claiming that the return type is recursive when it obviously isn't. This disappears when getting rid of the inner use<'a>
so is somehow triggered by using that in this location.
Equivalent-ish code avoiding the closure traits compiles successfully on stable:
trait Foo {}
trait Bar { type Foo: Foo; }
impl Foo for &() {}
impl Bar for &() { type Foo = Self; }
fn foo<'a>(u: &'a ()) -> impl Bar<Foo = impl Foo + use<'a>> + use<'a> {
u
}
Other cases
Rust Version
1.85.0-nightly
(2024-11-30 7442931d49b199ad0a1c)
Anything else?
No response
Activity