-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.F-impl_trait_in_fn_trait_return`#![feature(impl_trait_in_fn_trait_return)]``#![feature(impl_trait_in_fn_trait_return)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Description
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
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.F-impl_trait_in_fn_trait_return`#![feature(impl_trait_in_fn_trait_return)]``#![feature(impl_trait_in_fn_trait_return)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.