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) |
estebank
left a comment
There was a problem hiding this comment.
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.
Can we make this one // run-rustfix now?
There was a problem hiding this comment.
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.
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.
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_boundto 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
'aand'bis'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_boundmethod, whichuses the lowest-numbered universal region if the only alternative is to
return
'static.