-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Use an 'approximate' universal upper bound when reporting region errors #73806
Merged
bors
merged 1 commit into
rust-lang:master
from
Aaron1011:feature/approx-universal-upper
Jul 1, 2020
+101
−12
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// edition:2018 | ||
// | ||
// Regression test for issue #67765 | ||
// Tests that we point at the proper location when giving | ||
// a lifetime error. | ||
fn main() {} | ||
|
||
async fn func<'a>() -> Result<(), &'a str> { | ||
let s = String::new(); | ||
|
||
let b = &s[..]; | ||
|
||
Err(b)?; //~ ERROR cannot return value referencing local variable `s` | ||
|
||
Ok(()) | ||
} |
12 changes: 12 additions & 0 deletions
12
src/test/ui/async-await/issue-67765-async-diagnostic.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,12 @@ | ||
error[E0515]: cannot return value referencing local variable `s` | ||
--> $DIR/issue-67765-async-diagnostic.rs:13:11 | ||
| | ||
LL | let b = &s[..]; | ||
| - `s` is borrowed here | ||
LL | | ||
LL | Err(b)?; | ||
| ^ returns a value referencing data owned by the current function | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0515`. |
2 changes: 1 addition & 1 deletion
2
src/test/ui/lifetimes/unnamed-closure-doesnt-life-long-enough-issue-67634.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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
fn main() { | ||
[0].iter().flat_map(|a| [0].iter().map(|_| &a)); //~ ERROR `a` does not live long enough | ||
[0].iter().flat_map(|a| [0].iter().map(|_| &a)); //~ ERROR closure may outlive | ||
} |
24 changes: 15 additions & 9 deletions
24
src/test/ui/lifetimes/unnamed-closure-doesnt-life-long-enough-issue-67634.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 |
---|---|---|
@@ -1,15 +1,21 @@ | ||
error[E0597]: `a` does not live long enough | ||
--> $DIR/unnamed-closure-doesnt-life-long-enough-issue-67634.rs:2:49 | ||
error[E0373]: closure may outlive the current function, but it borrows `a`, which is owned by the current function | ||
--> $DIR/unnamed-closure-doesnt-life-long-enough-issue-67634.rs:2:44 | ||
| | ||
LL | [0].iter().flat_map(|a| [0].iter().map(|_| &a)); | ||
| - ^- ...but `a` will be dropped here, when the enclosing closure returns | ||
| | | | ||
| | `a` would have to be valid for `'_`... | ||
| has type `&i32` | ||
| ^^^ - `a` is borrowed here | ||
| | | ||
| may outlive borrowed value `a` | ||
| | ||
= note: functions cannot return a borrow to data owned within the function's scope, functions can only return borrows to data passed as arguments | ||
= note: to learn more, visit <https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#dangling-references> | ||
note: closure is returned here | ||
--> $DIR/unnamed-closure-doesnt-life-long-enough-issue-67634.rs:2:29 | ||
| | ||
LL | [0].iter().flat_map(|a| [0].iter().map(|_| &a)); | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
help: to force the closure to take ownership of `a` (and any other referenced variables), use the `move` keyword | ||
| | ||
LL | [0].iter().flat_map(|a| [0].iter().map(move |_| &a)); | ||
| ^^^^^^^^ | ||
Comment on lines
+14
to
+17
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. Can we make this one 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. The suggestion doesn't actually fix it - it just gets the error message back to the original one. |
||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0597`. | ||
For more information about this error, try `rustc --explain E0373`. |
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,7 @@ | ||
// See https://github.com/rust-lang/rust/pull/67911#issuecomment-576023915 | ||
fn f<'a, 'b>(x: i32) -> (&'a i32, &'b i32) { | ||
let y = &x; | ||
(y, y) //~ ERROR cannot return | ||
} | ||
|
||
fn main() {} |
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,11 @@ | ||
error[E0515]: cannot return value referencing function parameter `x` | ||
--> $DIR/return-disjoint-regions.rs:4:5 | ||
| | ||
LL | let y = &x; | ||
| -- `x` is borrowed here | ||
LL | (y, y) | ||
| ^^^^^^ returns a value referencing data owned by the current function | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0515`. |
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.
Could we move this to somewhere in
src/librustc_mir/borrow_check/diagnostics/
and make it accessible only there?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.
This method can't easily be moved, since it references private fields in
RegionInferenceContext
.