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

Search for incompatible universes in borrow errors #60327

Merged
merged 1 commit into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
borrow_region: RegionVid,
outlived_region: RegionVid,
) -> (ConstraintCategory, bool, Span, Option<RegionName>) {
let (category, from_closure, span) =
self.best_blame_constraint(mir, borrow_region, |r| r == outlived_region);
let (category, from_closure, span) = self.best_blame_constraint(
mir,
borrow_region,
|r| self.provides_universal_region(r, borrow_region, outlived_region)
);
let outlived_fr_name =
self.give_region_a_name(infcx, mir, upvars, mir_def_id, outlived_region, &mut 1);
(category, from_closure, span, outlived_fr_name)
Expand Down
26 changes: 26 additions & 0 deletions src/test/ui/nll/local-outlives-static-via-hrtb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Test that we handle the case when a local variable is borrowed for `'static`
// due to an outlives constraint involving a region in an incompatible universe

pub trait Outlives<'this> {}

impl<'this, T> Outlives<'this> for T where T: 'this {}
trait Reference {
type AssociatedType;
}

impl<'a, T: 'a> Reference for &'a T {
type AssociatedType = &'a ();
}

fn assert_static_via_hrtb<G>(_: G) where for<'a> G: Outlives<'a> {}

fn assert_static_via_hrtb_with_assoc_type<T>(_: &'_ T)
where
for<'a> &'a T: Reference<AssociatedType = &'a ()>,
{}

fn main() {
let local = 0;
assert_static_via_hrtb(&local); //~ ERROR `local` does not live long enough
assert_static_via_hrtb_with_assoc_type(&&local); //~ ERROR `local` does not live long enough
}
26 changes: 26 additions & 0 deletions src/test/ui/nll/local-outlives-static-via-hrtb.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error[E0597]: `local` does not live long enough
--> $DIR/local-outlives-static-via-hrtb.rs:24:28
|
LL | assert_static_via_hrtb(&local);
| -----------------------^^^^^^-
| | |
| | borrowed value does not live long enough
| argument requires that `local` is borrowed for `'static`
LL | assert_static_via_hrtb_with_assoc_type(&&local);
LL | }
| - `local` dropped here while still borrowed

error[E0597]: `local` does not live long enough
--> $DIR/local-outlives-static-via-hrtb.rs:25:45
|
LL | assert_static_via_hrtb_with_assoc_type(&&local);
| ----------------------------------------^^^^^^-
| | |
| | borrowed value does not live long enough
| argument requires that `local` is borrowed for `'static`
LL | }
| - `local` dropped here while still borrowed

error: aborting due to 2 previous errors

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