-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prefer regions with an
external_name
in approx_universal_upper_bound
Fixes #75785 When displaying a MIR borrowcheck error, we may need to find an upper bound for a region, which gives us a region to point to in the error message. However, a region might outlive multiple distinct universal regions, in which case the only upper bound is 'static To try to display a meaningful error message, we compute an 'approximate' upper bound by picking one of the universal regions. Currently, we pick the region with the lowest index - however, this caused us to produce a suboptimal error message in issue #75785 This PR `approx_universal_upper_bound` to prefer regions with an `external_name`. This causes us to prefer regions from function arguments/upvars, which seems to lead to a nicer error message in some cases.
- Loading branch information
Showing
4 changed files
with
46 additions
and
2 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
13 changes: 13 additions & 0 deletions
13
src/test/ui/async-await/issue-75785-confusing-named-region.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,13 @@ | ||
// edition:2018 | ||
// | ||
// Regression test for issue #75785 | ||
// Tests that we don't point to a confusing named | ||
// region when emitting a diagnostic | ||
|
||
pub async fn async_fn(x: &mut i32) -> (&i32, &i32) { | ||
let y = &*x; | ||
*x += 1; //~ ERROR cannot assign to | ||
(&32, y) | ||
} | ||
|
||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
src/test/ui/async-await/issue-75785-confusing-named-region.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,15 @@ | ||
error[E0506]: cannot assign to `*x` because it is borrowed | ||
--> $DIR/issue-75785-confusing-named-region.rs:9:5 | ||
| | ||
LL | pub async fn async_fn(x: &mut i32) -> (&i32, &i32) { | ||
| - let's call the lifetime of this reference `'1` | ||
LL | let y = &*x; | ||
| --- borrow of `*x` occurs here | ||
LL | *x += 1; | ||
| ^^^^^^^ assignment to borrowed `*x` occurs here | ||
LL | (&32, y) | ||
| -------- returning this value requires that `*x` is borrowed for `'1` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0506`. |