Skip to content
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
merged 1 commit into from
Jul 1, 2020

Conversation

Aaron1011
Copy link
Member

Fixes #67765

When reporting errors during MIR region inference, we sometimes use
universal_upper_bound to obtain a named universal region that we
can display to the user. However, this is not always possible - in a
case like fn foo<'a, 'b>() { .. }, the only upper bound for a region
containing 'a and 'b is 'static. When displaying diagnostics, it's
usually better to display some named region (even if there are
multiple involved) rather than fall back to a generic error involving
'static.

This commit adds a new approx_universal_upper_bound method, which
uses the lowest-numbered universal region if the only alternative is to
return 'static.

Fixes rust-lang#67765

When reporting errors during MIR region inference, we sometimes use
`universal_upper_bound` to obtain a named universal region that we
can display to the user. However, this is not always possible - in a
case like `fn foo<'a, 'b>() { .. }`, the only upper bound for a region
containing `'a` and `'b` is `'static`. When displaying diagnostics, it's
usually better to display *some* named region (even if there are
multiple involved) rather than fall back to a generic error involving
`'static`.

This commit adds a new `approx_universal_upper_bound` method, which
uses the lowest-numbered universal region if the only alternative is to
return `'static`.
@rust-highfive
Copy link
Collaborator

r? @estebank

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 27, 2020
Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code changes look reasonable and the output improvements are very welcome. I left a couple of nitpicks, but r=me.

Comment on lines +14 to +17
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));
| ^^^^^^^^
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this one // run-rustfix now?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

/// Therefore, this method should only be used in diagnostic code,
/// where displaying *some* named universal region is better than
/// falling back to 'static.
pub(in crate::borrow_check) fn approx_universal_upper_bound(&self, r: RegionVid) -> RegionVid {
Copy link
Contributor

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?

Copy link
Member Author

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.

@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jun 29, 2020

📌 Commit 517d361 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 29, 2020
Manishearth added a commit to Manishearth/rust that referenced this pull request Jun 29, 2020
…upper, r=estebank

Use an 'approximate' universal upper bound when reporting region errors

Fixes rust-lang#67765

When reporting errors during MIR region inference, we sometimes use
`universal_upper_bound` to obtain a named universal region that we
can display to the user. However, this is not always possible - in a
case like `fn foo<'a, 'b>() { .. }`, the only upper bound for a region
containing `'a` and `'b` is `'static`. When displaying diagnostics, it's
usually better to display *some* named region (even if there are
multiple involved) rather than fall back to a generic error involving
`'static`.

This commit adds a new `approx_universal_upper_bound` method, which
uses the lowest-numbered universal region if the only alternative is to
return `'static`.
Manishearth added a commit to Manishearth/rust that referenced this pull request Jun 29, 2020
…upper, r=estebank

Use an 'approximate' universal upper bound when reporting region errors

Fixes rust-lang#67765

When reporting errors during MIR region inference, we sometimes use
`universal_upper_bound` to obtain a named universal region that we
can display to the user. However, this is not always possible - in a
case like `fn foo<'a, 'b>() { .. }`, the only upper bound for a region
containing `'a` and `'b` is `'static`. When displaying diagnostics, it's
usually better to display *some* named region (even if there are
multiple involved) rather than fall back to a generic error involving
`'static`.

This commit adds a new `approx_universal_upper_bound` method, which
uses the lowest-numbered universal region if the only alternative is to
return `'static`.
Manishearth added a commit to Manishearth/rust that referenced this pull request Jun 30, 2020
…upper, r=estebank

Use an 'approximate' universal upper bound when reporting region errors

Fixes rust-lang#67765

When reporting errors during MIR region inference, we sometimes use
`universal_upper_bound` to obtain a named universal region that we
can display to the user. However, this is not always possible - in a
case like `fn foo<'a, 'b>() { .. }`, the only upper bound for a region
containing `'a` and `'b` is `'static`. When displaying diagnostics, it's
usually better to display *some* named region (even if there are
multiple involved) rather than fall back to a generic error involving
`'static`.

This commit adds a new `approx_universal_upper_bound` method, which
uses the lowest-numbered universal region if the only alternative is to
return `'static`.
@Manishearth
Copy link
Member

Is there a chance this PR is massively slowing down CI? It was a part of two rollups (#73880, #73864) that timed out, and while this is not the only suspect, it's worth investigating.

@Mark-Simulacrum
Copy link
Member

@bors r- try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 30, 2020
@bors
Copy link
Contributor

bors commented Jun 30, 2020

⌛ Trying commit 517d361 with merge 91c610e689edb8d299333c89cc783cf7b3727b61...

@bors
Copy link
Contributor

bors commented Jun 30, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: 91c610e689edb8d299333c89cc783cf7b3727b61 (91c610e689edb8d299333c89cc783cf7b3727b61)

@rust-timer
Copy link
Collaborator

Queued 91c610e689edb8d299333c89cc783cf7b3727b61 with parent 665190b, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (91c610e689edb8d299333c89cc783cf7b3727b61): comparison url.

@Aaron1011
Copy link
Member Author

No perf impact

@bors r=estebank

@bors
Copy link
Contributor

bors commented Jun 30, 2020

📌 Commit 517d361 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 30, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 1, 2020
…arth

Rollup of 17 pull requests

Successful merges:

 - rust-lang#72071 (Added detailed error code explanation for issue E0687 in Rust compiler.)
 - rust-lang#72369 (Bring net/parser.rs up to modern up to date with modern rust patterns)
 - rust-lang#72445 (Stabilize `#[track_caller]`.)
 - rust-lang#73466 (impl From<char> for String)
 - rust-lang#73548 (remove rustdoc warnings)
 - rust-lang#73649 (Fix sentence structure)
 - rust-lang#73678 (Update Box::from_raw example to generalize better)
 - rust-lang#73705 (stop taking references in Relate)
 - rust-lang#73716 (Document the static keyword)
 - rust-lang#73752 (Remap Windows ERROR_INVALID_PARAMETER to ErrorKind::InvalidInput from Other)
 - rust-lang#73776 (Move terminator to new module)
 - rust-lang#73778 (Make `likely` and `unlikely` const, gated by feature `const_unlikely`)
 - rust-lang#73805 (Document the type keyword)
 - rust-lang#73806 (Use an 'approximate' universal upper bound when reporting region errors)
 - rust-lang#73828 (Fix wording for anonymous parameter name help)
 - rust-lang#73846 (Fix comma in debug_assert! docs)
 - rust-lang#73847 (Edit cursor.prev() method docs in lexer)

Failed merges:

r? @ghost
@bors bors merged commit f213957 into rust-lang:master Jul 1, 2020
@cuviper cuviper added this to the 1.46 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unhelpful error messages from borrow checker with async/await
8 participants