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

Rollup of 17 pull requests #73924

Merged
merged 52 commits into from
Jul 1, 2020
Merged
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
46bfc48
Added proper explanation of ErrorCode-E0687
Polkaverse May 10, 2020
1d0378c
impl From<char> for String
matthiaskrgr Jun 17, 2020
2cde493
add test for char into string
matthiaskrgr Jun 18, 2020
886f81e
Fix sentence structure
Anirban166 Jun 23, 2020
0c88dd6
Update Box::from_raw example to generalize better
Keno Jun 24, 2020
3b5d7f8
Minor correction to sentence structure
Anirban166 Jun 24, 2020
d6cf8fc
Update README.md
Anirban166 Jun 24, 2020
2bbc2b3
Document the static keyword
poliorcetics Jun 25, 2020
22fc18f
Commit suggestion
Anirban166 Jun 25, 2020
8edcc6d
Add alternate text for rust logo image
Anirban166 Jun 25, 2020
3a1ac28
Added clickable-link
Anirban166 Jun 25, 2020
4c33b7c
Add responsiveness to logo
Anirban166 Jun 25, 2020
00ef461
Merge pull request #2 from rust-lang/master
TyPR124 Jun 26, 2020
b71a3e1
Map ERROR_INVALID_PARAMETER to InvalidInput
TyPR124 Jun 26, 2020
15e81be
moves terminator types to sub module
aszenz Jun 26, 2020
cf398a3
removes unnecessary tidy ignore
aszenz Jun 26, 2020
224bc05
Fix allow_internal_unstable with rustc_const_unstable
nbdd0121 Jun 26, 2020
fc239e8
Make `likely` and `unlikely` const
nbdd0121 Jun 26, 2020
779b05d
Fix ICE for lib features
nbdd0121 Jun 26, 2020
3fc5593
Document the type keyword
poliorcetics Jun 27, 2020
8b43012
Update src/librustc_mir/interpret/intrinsics.rs
nbdd0121 Jun 27, 2020
517d361
Use an 'approximate' universal upper bound when reporting region errors
Aaron1011 Jun 27, 2020
7231e57
Fix wording for anonymous parameter name help
nop Jun 28, 2020
4595fa8
Fix comma in debug_assert! docs
pierwill Jun 28, 2020
e611a3f
Apply suggestions from code review
poliorcetics Jun 28, 2020
dfd454b
Apply suggestions, reformulating some paragraphs and improving some e…
poliorcetics Jun 28, 2020
4224313
Fix small nits
poliorcetics Jun 28, 2020
40c74a7
Edit cursor.prev() method docs in lexer
pierwill Jun 28, 2020
1d7ba5f
stop taking references in Relate
lcnr Jun 24, 2020
71b45b9
change `skip_binder` to use T by value
lcnr Jun 24, 2020
f632bd1
remove unused `TypeError::ProjectionBoundsLength`
lcnr Jun 24, 2020
69e4990
update `equal_up_to_regions`
lcnr Jun 30, 2020
f3645ca
remove rustdoc warnings
tshepang Jun 30, 2020
3ab7ae3
Bring net/parser.rs up to modern up to date with modern rust patterns
Lucretiel May 20, 2020
f07d10d
Stabilize `#[track_caller]`.
anp May 21, 2020
128fa2b
Rollup merge of #72071 - PankajChaudhary5:ErrorCode-E0687, r=davidtwco
Manishearth Jul 1, 2020
33f8ce2
Rollup merge of #72369 - Lucretiel:socketaddr-parse, r=dtolnay
Manishearth Jul 1, 2020
ae79c30
Rollup merge of #72445 - anp:stabilize-track-caller, r=oli-obk
Manishearth Jul 1, 2020
b7d13c0
Rollup merge of #73466 - matthiaskrgr:char_into_string, r=dtolnay
Manishearth Jul 1, 2020
39209ac
Rollup merge of #73548 - tshepang:fix-rustdoc-warnings, r=ecstatic-morse
Manishearth Jul 1, 2020
0eb9799
Rollup merge of #73649 - Anirban166:patch-1, r=steveklabnik
Manishearth Jul 1, 2020
6556f26
Rollup merge of #73678 - Keno:patch-1, r=LukasKalbertodt
Manishearth Jul 1, 2020
9c65486
Rollup merge of #73705 - lcnr:skip_binder, r=nikomatsakis
Manishearth Jul 1, 2020
8ac17d1
Rollup merge of #73716 - poliorcetics:static-keyword, r=LukasKalbertodt
Manishearth Jul 1, 2020
3951a98
Rollup merge of #73752 - TyPR124:invalid-parameter-error, r=LukasKalb…
Manishearth Jul 1, 2020
d6bee55
Rollup merge of #73776 - aszenz:refactor_mir_module, r=wesleywiser
Manishearth Jul 1, 2020
ec41d01
Rollup merge of #73778 - nbdd0121:const_likely, r=oli-obk
Manishearth Jul 1, 2020
178b0c2
Rollup merge of #73805 - poliorcetics:type-keyword, r=kennytm
Manishearth Jul 1, 2020
f213957
Rollup merge of #73806 - Aaron1011:feature/approx-universal-upper, r=…
Manishearth Jul 1, 2020
db900d4
Rollup merge of #73828 - nop:fix/parameter-name-help, r=estebank
Manishearth Jul 1, 2020
affd950
Rollup merge of #73846 - pierwill:pierwill-patch-2, r=joshtriplett
Manishearth Jul 1, 2020
c9b3e86
Rollup merge of #73847 - pierwill:pierwill-cursor-doc, r=matthewjasper
Manishearth Jul 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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`.
  • Loading branch information
Aaron1011 committed Jun 27, 2020
commit 517d361a1f78cf13d589d0f6b94f5ca005bef540
4 changes: 3 additions & 1 deletion src/librustc_mir/borrow_check/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
@@ -122,7 +122,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
if self.regioncx.universal_regions().is_universal_region(r) {
Some(r)
} else {
let upper_bound = self.regioncx.universal_upper_bound(r);
// We just want something nameable, even if it's not
// actually an upper bound.
let upper_bound = self.regioncx.approx_universal_upper_bound(r);

if self.regioncx.upper_bound_in_region_scc(r, upper_bound) {
self.to_error_region_vid(upper_bound)
34 changes: 34 additions & 0 deletions src/librustc_mir/borrow_check/region_infer/mod.rs
Original file line number Diff line number Diff line change
@@ -1114,6 +1114,40 @@ impl<'tcx> RegionInferenceContext<'tcx> {
lub
}

/// Like `universal_upper_bound`, but returns an approximation more suitable
/// for diagnostics. If `r` contains multiple disjoint universal regions
/// (e.g. 'a and 'b in `fn foo<'a, 'b> { ... }`, we pick the lower-numbered region.
/// This corresponds to picking named regions over unnamed regions
/// (e.g. picking early-bound regions over a closure late-bound region).
///
/// This means that the returned value may not be a true upper bound, since
/// only 'static is known to outlive disjoint universal regions.
/// 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 {
debug!("approx_universal_upper_bound(r={:?}={})", r, self.region_value_str(r));

// Find the smallest universal region that contains all other
// universal regions within `region`.
let mut lub = self.universal_regions.fr_fn_body;
let r_scc = self.constraint_sccs.scc(r);
let static_r = self.universal_regions.fr_static;
for ur in self.scc_values.universal_regions_outlived_by(r_scc) {
let new_lub = self.universal_region_relations.postdom_upper_bound(lub, ur);
debug!("approx_universal_upper_bound: ur={:?} lub={:?} new_lub={:?}", ur, lub, new_lub);
if ur != static_r && lub != static_r && new_lub == static_r {
lub = std::cmp::min(ur, lub);
} else {
lub = new_lub;
}
}

debug!("approx_universal_upper_bound: r={:?} lub={:?}", r, lub);

lub
}

/// Tests if `test` is true when applied to `lower_bound` at
/// `point`.
fn eval_verify_bound(
3 changes: 2 additions & 1 deletion src/librustc_mir/borrow_check/region_infer/opaque_types.rs
Original file line number Diff line number Diff line change
@@ -141,7 +141,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
{
tcx.fold_regions(&ty, &mut false, |region, _| match *region {
ty::ReVar(vid) => {
let upper_bound = self.universal_upper_bound(vid);
// Find something that we can name
let upper_bound = self.approx_universal_upper_bound(vid);
self.definitions[upper_bound].external_name.unwrap_or(region)
}
_ => region,
16 changes: 16 additions & 0 deletions src/test/ui/async-await/issue-67765-async-diagnostic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// edition:2018
//
// Regression test for issue #67765
// Tests that we point at the proper location when giving
// a lifetime error.
fn main() {}

async fn func<'a>() -> Result<(), &'a str> {
let s = String::new();

let b = &s[..];

Err(b)?; //~ ERROR cannot return value referencing local variable `s`

Ok(())
}
12 changes: 12 additions & 0 deletions src/test/ui/async-await/issue-67765-async-diagnostic.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0515]: cannot return value referencing local variable `s`
--> $DIR/issue-67765-async-diagnostic.rs:13:11
|
LL | let b = &s[..];
| - `s` is borrowed here
LL |
LL | Err(b)?;
| ^ returns a value referencing data owned by the current function

error: aborting due to previous error

For more information about this error, try `rustc --explain E0515`.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
[0].iter().flat_map(|a| [0].iter().map(|_| &a)); //~ ERROR `a` does not live long enough
[0].iter().flat_map(|a| [0].iter().map(|_| &a)); //~ ERROR closure may outlive
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
error[E0597]: `a` does not live long enough
--> $DIR/unnamed-closure-doesnt-life-long-enough-issue-67634.rs:2:49
error[E0373]: closure may outlive the current function, but it borrows `a`, which is owned by the current function
--> $DIR/unnamed-closure-doesnt-life-long-enough-issue-67634.rs:2:44
|
LL | [0].iter().flat_map(|a| [0].iter().map(|_| &a));
| - ^- ...but `a` will be dropped here, when the enclosing closure returns
| | |
| | `a` would have to be valid for `'_`...
| has type `&i32`
| ^^^ - `a` is borrowed here
| |
| may outlive borrowed value `a`
|
= note: functions cannot return a borrow to data owned within the function's scope, functions can only return borrows to data passed as arguments
= note: to learn more, visit <https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#dangling-references>
note: closure is returned here
--> $DIR/unnamed-closure-doesnt-life-long-enough-issue-67634.rs:2:29
|
LL | [0].iter().flat_map(|a| [0].iter().map(|_| &a));
| ^^^^^^^^^^^^^^^^^^^^^^
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));
| ^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0597`.
For more information about this error, try `rustc --explain E0373`.
7 changes: 7 additions & 0 deletions src/test/ui/return-disjoint-regions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// See https://github.com/rust-lang/rust/pull/67911#issuecomment-576023915
fn f<'a, 'b>(x: i32) -> (&'a i32, &'b i32) {
let y = &x;
(y, y) //~ ERROR cannot return
}

fn main() {}
11 changes: 11 additions & 0 deletions src/test/ui/return-disjoint-regions.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0515]: cannot return value referencing function parameter `x`
--> $DIR/return-disjoint-regions.rs:4:5
|
LL | let y = &x;
| -- `x` is borrowed here
LL | (y, y)
| ^^^^^^ returns a value referencing data owned by the current function

error: aborting due to previous error

For more information about this error, try `rustc --explain E0515`.