-
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
Use an 'approximate' universal upper bound when reporting region errors #73806
Use an 'approximate' universal upper bound when reporting region errors #73806
Conversation
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`.
r? @estebank (rust_highfive has picked a reviewer for you, use r? to override) |
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.
The code changes look reasonable and the output improvements are very welcome. I left a couple of nitpicks, but r=me.
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)); | ||
| ^^^^^^^^ |
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.
Can we make this one // run-rustfix
now?
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.
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 { |
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
.
@bors r+ |
📌 Commit 517d361 has been approved by |
…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`.
…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`.
…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`.
@bors r- try @rust-timer queue |
Awaiting bors try build completion |
⌛ Trying commit 517d361 with merge 91c610e689edb8d299333c89cc783cf7b3727b61... |
☀️ Try build successful - checks-actions, checks-azure |
Queued 91c610e689edb8d299333c89cc783cf7b3727b61 with parent 665190b, future comparison URL. |
Finished benchmarking try commit (91c610e689edb8d299333c89cc783cf7b3727b61): comparison url. |
No perf impact @bors r=estebank |
📌 Commit 517d361 has been approved by |
…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
Fixes #67765
When reporting errors during MIR region inference, we sometimes use
universal_upper_bound
to obtain a named universal region that wecan display to the user. However, this is not always possible - in a
case like
fn foo<'a, 'b>() { .. }
, the only upper bound for a regioncontaining
'a
and'b
is'static
. When displaying diagnostics, it'susually 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, whichuses the lowest-numbered universal region if the only alternative is to
return
'static
.