Description
What is this lint about
In functions not all lifetime parameters are created equal.
For example, if you have a function like
fn f<'a, 'b>(arg: &'a u8) -> &'b u8 { .... }
both 'a
and 'b
are listed in the same parameter list, but when stripped from the surface syntax the function looks more like
for<'a> fn f<'b>(arg: &'a u8) -> &'b u8 { .... }
where 'b
is a "true" ("early-bound") parameter of the function, and 'a
is an "existential" ("late-bound") parameter. This means the function is not parameterized by 'a
.
To give some more intuition, let's write a type for function pointer to f
:
// PtrF is not parameterized by 'a,
type PtrF<'b> = for<'a> fn(&'a u8) -> &'b u8;
// but it has to be parameterized by 'b
type PtrF = for<'a, 'b> fn(&'a u8) -> &'b u8; // ERROR
See more about this distinction in http://smallcultfollowing.com/babysteps/blog/2013/10/29/intermingled-parameter-lists/#early--vs-late-bound-lifetimes
When lifetime arguments are provided to a function explicitly, e.g.
f::<'my_a, 'my_b>
the first argument doesn't make much sense because the function is not parameterized by 'a
.
Providing arguments for "late-bound" lifetime parameters in general doesn't make sense, while arguments for "early-bound" lifetime parameters can be provided.
It's not clear how to provide arguments for early-bound lifetime parameters if they are intermixed with late-bound parameters in the same list. For now providing any explicit arguments is prohibited if late-bound parameters are present, so in the future we can adopt any solution without hitting backward compatibility issues.
Note that late-bound lifetime parameters can be introduced implicitly through lifetime elision:
fn f(&u8) {}
// Desugars into
fn f<'a>(&'a u8) {} // 'a is late-bound
The precise rules discerning between early- and late-bound lifetimes can be found here:
rust/src/librustc/middle/resolve_lifetime.rs
Lines 1541 to 1700 in 91aff57
How to fix this warning/error
Just removing the lifetime arguments pointed to by the lint should be enough in most cases.
Current status
- Support generic lifetime arguments in method calls #42492 introduces the
late_bound_lifetime_arguments
lint as warn-by-default - PR ? makes the
late_bound_lifetime_arguments
lint deny-by-default - PR ? makes the
late_bound_lifetime_arguments
lint a hard error
Metadata
Metadata
Assignees
Labels
Type
Projects
Status