-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide more information for HRTB lifetime errors involving closures #79588
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
oli-obk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--> $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) {} | ||
| ^^^ | ||
Comment on lines
+14
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hadn't considered this case in particular, but ideally we would (also) point at the |
||
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we have the information available anywhere, but could emit a diagnostic of this quality for the
the required lifetime does not necessarily outlive the anonymous lifetime #1 defined on the body
, too? This occurs insrc/test/ui/generator/resume-arg-late-bound.stderr