Error code E0794
A lifetime parameter of a function definition is called late-bound if it both:
- appears in an argument type
- does not appear in a generic type constraint
You cannot specify lifetime arguments for late-bound lifetime parameters.
Erroneous code example:
ⓘ
The type of a concrete instance of a generic function is universally quantified over late-bound lifetime parameters. This is because we want the function to work for any lifetime instantiated for the late-bound lifetime parameter, no matter where the function is called. Consequently, it doesn't make sense to specify arguments for late-bound lifetime parameters, since they are not resolved until the function's call site(s).
To fix the issue, remove the specified lifetime:
Additional information
Lifetime parameters that are not late-bound are called early-bound. Confusion may arise from the fact that late-bound and early-bound lifetime parameters are declared the same way in function definitions. When referring to a function pointer type, universal quantification over late-bound lifetime parameters can be made explicit:
In the definition of bar
, the lifetime parameter 'a
is late-bound, while
'b
is early-bound. This is reflected in the type annotation for bar_fn
,
where 'a
is universally quantified and 'b
is instantiated with a specific
lifetime. It is not allowed to explicitly specify early-bound lifetime
arguments when late-bound lifetime parameters are present (as for bar_fn2
,
see issue #42868), although
the types that are constrained by early-bound parameters can be specified (as
for bar_fn3
).