Fix suggestion to introduce explicit lifetime
This commit is contained in:
parent
07194ffcd2
commit
788e4bb4e5
3 changed files with 53 additions and 1 deletions
|
|
@ -0,0 +1,26 @@
|
|||
// Regression test for #81650
|
||||
|
||||
struct Foo<'a> {
|
||||
x: &'a mut &'a i32,
|
||||
}
|
||||
|
||||
impl<'a> Foo<'a> {
|
||||
fn bar<F, T>(&self, f: F)
|
||||
where
|
||||
F: FnOnce(&Foo<'a>) -> T,
|
||||
F: 'a,
|
||||
{}
|
||||
}
|
||||
|
||||
trait Test {
|
||||
fn test(&self);
|
||||
}
|
||||
|
||||
fn func<T: Test>(foo: &Foo, t: T) {
|
||||
foo.bar(move |_| {
|
||||
//~^ ERROR the parameter type `T` may not live long enough
|
||||
t.test();
|
||||
});
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
error[E0311]: the parameter type `T` may not live long enough
|
||||
--> $DIR/missing-lifetimes-in-signature-2.rs:20:9
|
||||
|
|
||||
LL | fn func<T: Test>(foo: &Foo, t: T) {
|
||||
| -- help: consider adding an explicit lifetime bound...: `T: 'a +`
|
||||
LL | foo.bar(move |_| {
|
||||
| ^^^
|
||||
|
|
||||
note: the parameter type `T` must be valid for the anonymous lifetime #2 defined on the function body at 19:1...
|
||||
--> $DIR/missing-lifetimes-in-signature-2.rs:19:1
|
||||
|
|
||||
LL | fn func<T: Test>(foo: &Foo, t: T) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature-2.rs:20:13: 23:6]` will meet its required lifetime bounds
|
||||
--> $DIR/missing-lifetimes-in-signature-2.rs:20:9
|
||||
|
|
||||
LL | foo.bar(move |_| {
|
||||
| ^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue