-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 #79588 - estebank:issue-79187, r=oli-obk
Provide more information for HRTB lifetime errors involving closures
- Loading branch information
Showing
18 changed files
with
392 additions
and
25 deletions.
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
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
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
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
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
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
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
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,44 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/issue-79187-2.rs:9:24 | ||
| | ||
LL | take_foo(|a: &i32| a); | ||
| - - ^ returning this value requires that `'1` must outlive `'2` | ||
| | | | ||
| | return type of closure is &'2 i32 | ||
| let's call the lifetime of this reference `'1` | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/issue-79187-2.rs:10:34 | ||
| | ||
LL | take_foo(|a: &i32| -> &i32 { a }); | ||
| - - ^ returning this value requires that `'1` must outlive `'2` | ||
| | | | ||
| | let's call the lifetime of this reference `'2` | ||
| let's call the lifetime of this reference `'1` | ||
|
||
error: higher-ranked subtype error | ||
--> $DIR/issue-79187-2.rs:8:5 | ||
| | ||
LL | take_foo(|a| a); | ||
| ^^^^^^^^^^^^^^^ | ||
|
||
error: higher-ranked subtype error | ||
--> $DIR/issue-79187-2.rs:8:5 | ||
| | ||
LL | take_foo(|a| a); | ||
| ^^^^^^^^^^^^^^^ | ||
|
||
error: higher-ranked subtype error | ||
--> $DIR/issue-79187-2.rs:9:5 | ||
| | ||
LL | take_foo(|a: &i32| a); | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: higher-ranked subtype error | ||
--> $DIR/issue-79187-2.rs:10:5 | ||
| | ||
LL | take_foo(|a: &i32| -> &i32 { a }); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 6 previous errors | ||
|
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,23 @@ | ||
trait Foo {} | ||
|
||
impl<F> Foo for F where F: Fn(&i32) -> &i32 {} | ||
|
||
fn take_foo(_: impl Foo) {} | ||
|
||
fn main() { | ||
take_foo(|a| a); //~ ERROR mismatched types | ||
take_foo(|a: &i32| a); //~ ERROR mismatched types | ||
take_foo(|a: &i32| -> &i32 { a }); //~ ERROR mismatched types | ||
|
||
// OK | ||
take_foo(identity(|a| a)); | ||
take_foo(identity(|a: &i32| a)); | ||
take_foo(identity(|a: &i32| -> &i32 { a })); | ||
|
||
fn identity<F>(t: F) -> F | ||
where | ||
F: Fn(&i32) -> &i32, | ||
{ | ||
t | ||
} | ||
} |
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,60 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-79187-2.rs:8:5 | ||
| | ||
LL | take_foo(|a| a); | ||
| ^^^^^^^^ lifetime mismatch | ||
| | ||
= note: expected type `for<'r> Fn<(&'r i32,)>` | ||
found type `Fn<(&i32,)>` | ||
note: this closure does not fulfill the lifetime requirements | ||
--> $DIR/issue-79187-2.rs:8:14 | ||
| | ||
LL | take_foo(|a| a); | ||
| ^^^^^ | ||
note: the lifetime requirement is introduced here | ||
--> $DIR/issue-79187-2.rs:5:21 | ||
| | ||
LL | fn take_foo(_: impl Foo) {} | ||
| ^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-79187-2.rs:9:5 | ||
| | ||
LL | take_foo(|a: &i32| a); | ||
| ^^^^^^^^ lifetime mismatch | ||
| | ||
= note: expected reference `&i32` | ||
found reference `&i32` | ||
note: the anonymous lifetime #1 defined on the body at 9:14 doesn't meet the lifetime requirements | ||
--> $DIR/issue-79187-2.rs:9:14 | ||
| | ||
LL | take_foo(|a: &i32| a); | ||
| ^^^^^^^^^^^ | ||
note: the lifetime requirement is introduced here | ||
--> $DIR/issue-79187-2.rs:5:21 | ||
| | ||
LL | fn take_foo(_: impl Foo) {} | ||
| ^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-79187-2.rs:10:5 | ||
| | ||
LL | take_foo(|a: &i32| -> &i32 { a }); | ||
| ^^^^^^^^ lifetime mismatch | ||
| | ||
= note: expected reference `&i32` | ||
found reference `&i32` | ||
note: the anonymous lifetime #1 defined on the body at 10:14 doesn't meet the lifetime requirements | ||
--> $DIR/issue-79187-2.rs:10:14 | ||
| | ||
LL | take_foo(|a: &i32| -> &i32 { a }); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
note: the lifetime requirement is introduced here | ||
--> $DIR/issue-79187-2.rs:5:21 | ||
| | ||
LL | fn take_foo(_: impl Foo) {} | ||
| ^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
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,14 @@ | ||
error: higher-ranked subtype error | ||
--> $DIR/issue-79187.rs:5:5 | ||
| | ||
LL | thing(f); | ||
| ^^^^^^^^ | ||
|
||
error: higher-ranked subtype error | ||
--> $DIR/issue-79187.rs:5:5 | ||
| | ||
LL | thing(f); | ||
| ^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
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,6 @@ | ||
fn thing(x: impl FnOnce(&u32)) {} | ||
|
||
fn main() { | ||
let f = |_| (); | ||
thing(f); //~ERROR mismatched types | ||
} |
Oops, something went wrong.