You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
impl Trait in return position implicitly captures non-'static type parameter despite + 'static #132364
error[E0597]: `deserializer` does not live long enough
--> src/lib.rs:15:24
|
14 | let deserializer = DeserStruct;
| ------------ binding `deserializer` declared here
15 | let graph = testfn(&deserializer);
| -------^^^^^^^^^^^^^-
| | |
| | borrowed value does not live long enough
| argument requires that `deserializer` is borrowed for `'static`
16 | graph
17 | }
| - `deserializer` dropped here while still borrowed
Desired output
I'm not sure, but adding + use<> to the function's return type explains what the issue is actually that impl Trait implicitly captured the trait bound:
error: `impl Trait` must mention all type parameters in scope in `use<...>`
--> src/lib.rs:9:61
|
9 | pub fn testfn<'de, D: DeserTrait<'de>>(_deserializer: D) -> impl MyTrait + use<> + 'static {
| - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| type parameter is implicitly captured by this `impl Trait`
|
= note: currently, all type parameters are required to be mentioned in the precise captures list
Rationale and extra context
It's impossible to debug (or google) otherwise, and I only figured it out because I remembered + use<> from the stabilization blog post
Activity
compiler-errors commentedon Oct 30, 2024
This is a known limitation, see #116733 Limitation: Opaque hidden types.
compiler-errors commentedon Oct 30, 2024
I'd recommend usingedit: Actually, not totally sure if that will work for your usecase.+ use<>syntax, which doesn't have this problem.progval commentedon Oct 30, 2024
I understand, but I wrote issue about the diagnostic that is unclear, not about limitations of the type system