Closed
Description
Seems like this behavior has existed for a while, so apologies in advance if this is already a settled matter. If so, I still think the failure coulld use a better error message.
In short, the following code fails to compile:
pub struct Foo<'a, A>(&'a A);
impl<'a, A> Foo<'a, A> {
pub fn foo() {}
pub fn call_foo() {
Self::foo();
}
}
Error message:
error[E0309]: the parameter type `A` may not live long enough
--> src/lib.rs:7:9
|
7 | Self::foo();
| ^^^^^^^^^ ...so that the type `A` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound...
|
3 | impl<'a, A: 'a> Foo<'a, A> {
| ++++
In call_foo
, the compiler (correctly) requires that A: 'a
, but fails to realize that this bound is already satisfied (because this is also required for callers of call_foo
).
To me, this seems like a bug. However, this behavior seems to have been present in stable for long enough that it seems highly unlikely it hasn't already been discussed at length - I couldn't find any issues referencing it though. (closest seems to be #84021).
Happy to help where I can (would need some direction).