]> git.lizzy.rs Git - rust.git/commit
Use an 'approximate' universal upper bound when reporting region errors
authorAaron Hill <aa1ronham@gmail.com>
Sat, 27 Jun 2020 17:54:56 +0000 (13:54 -0400)
committerAaron Hill <aa1ronham@gmail.com>
Sat, 27 Jun 2020 18:01:59 +0000 (14:01 -0400)
commit517d361a1f78cf13d589d0f6b94f5ca005bef540
tree01b4e4dcce5dbb0ada91a25ada41119a0c9205cc
parent394e1b40d264aa6928811919c1124fa248e7d802
Use an 'approximate' universal upper bound when reporting region errors

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`.
src/librustc_mir/borrow_check/diagnostics/region_errors.rs
src/librustc_mir/borrow_check/region_infer/mod.rs
src/librustc_mir/borrow_check/region_infer/opaque_types.rs
src/test/ui/async-await/issue-67765-async-diagnostic.rs [new file with mode: 0644]
src/test/ui/async-await/issue-67765-async-diagnostic.stderr [new file with mode: 0644]
src/test/ui/lifetimes/unnamed-closure-doesnt-life-long-enough-issue-67634.rs
src/test/ui/lifetimes/unnamed-closure-doesnt-life-long-enough-issue-67634.stderr
src/test/ui/return-disjoint-regions.rs [new file with mode: 0644]
src/test/ui/return-disjoint-regions.stderr [new file with mode: 0644]