Closed
Description
In some cases, we can suggest the user add a where clause. This applies in cases where there are two named lifetimes already:
fn foo<'a, 'b>(mut x: Vec<&'a u32>, y: &'b u32) {
x.push(y);
}
fn main() { }
Here we currently print:
error[E0623]: lifetime mismatch
--> src/main.rs:2:12
|
1 | fn foo<'a, 'b>(mut x: Vec<&'a u32>, y: &'b u32) {
| ------- ------- these two types are declared with different lifetimes...
2 | x.push(y);
| ^ ...but data from `y` flows into `x` here
It'd be nice to add:
help: consider adding a where-clause like `where 'b: 'a`
Typically, we should only do this outside of trait impls, however, because otherwise the user may not be free to modify the signature. Or, if the trait is declared inside the same crate, we could find the corresponding method in the trait and add a note saying "the where-clause would also have to be added here" or some such thing.