forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#81995 - 0yoyoyo:fix-issue-81650-explicit-li…
…fetime-error, r=estebank Fix suggestion to introduce explicit lifetime Addresses rust-lang#81650 Error message after fix: ``` error[E0311]: the parameter type `T` may not live long enough --> src/main.rs:25:11 | 24 | fn play_with<T: Animal + Send>(scope: &Scope, animal: T) { | -- help: consider adding an explicit lifetime bound...: `T: 'a +` 25 | scope.spawn(move |_| { | ^^^^^ | note: the parameter type `T` must be valid for the anonymous lifetime #2 defined on the function body at 24:1... --> src/main.rs:24:1 | 24 | fn play_with<T: Animal + Send>(scope: &Scope, animal: T) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...so that the type `[closure@src/main.rs:25:17: 27:6]` will meet its required lifetime bounds --> src/main.rs:25:11 | 25 | scope.spawn(move |_| { | ^^^^^ ```
- Loading branch information
Showing
3 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
21 changes: 21 additions & 0 deletions
21
src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|