diff options
| author | bors <bors@rust-lang.org> | 2017-11-06 23:30:57 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-11-06 23:30:57 +0000 |
| commit | 785643a5eb6727d788b218e10ce60219b1c3c27f (patch) | |
| tree | c2e071a6e9a6d1e5ded1ce781dace6eda4d4dc14 /src/test/ui | |
| parent | bd0e45a323f85a1940d997ac237023c00670da67 (diff) | |
| parent | 7b4282e02bdff3b91c4a317af94ce18149044830 (diff) | |
| download | rust-785643a5eb6727d788b218e10ce60219b1c3c27f.tar.gz rust-785643a5eb6727d788b218e10ce60219b1c3c27f.zip | |
Auto merge of #45668 - nikomatsakis:nll-free-region, r=arielb1
extend NLL with preliminary support for free regions on functions This PR extends https://github.com/rust-lang/rust/pull/45538 with support for free regions. This is pretty preliminary and will no doubt want to change in various ways, particularly as we add support for closures, but it's enough to get the basic idea in place: - We now create specific regions to represent each named lifetime declared on the function. - Region values can contain references to these regions (represented for now as a `BTreeSet<RegionIndex>`). - If we wind up trying to infer that `'a: 'b` must hold, but no such relationship was declared, we report an error. It also does a number of drive-by refactorings. r? @arielb1 cc @spastorino
Diffstat (limited to 'src/test/ui')
| -rw-r--r-- | src/test/ui/nll/named-region-basic.rs | 22 | ||||
| -rw-r--r-- | src/test/ui/nll/named-region-basic.stderr | 29 |
2 files changed, 51 insertions, 0 deletions
diff --git a/src/test/ui/nll/named-region-basic.rs b/src/test/ui/nll/named-region-basic.rs new file mode 100644 index 00000000000..539c2017ea6 --- /dev/null +++ b/src/test/ui/nll/named-region-basic.rs @@ -0,0 +1,22 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Basic test for free regions in the NLL code. This test ought to +// report an error due to a reborrowing constraint. Right now, we get +// a variety of errors from the older, AST-based machinery (notably +// borrowck), and then we get the NLL error at the end. + +// compile-flags:-Znll + +fn foo<'a, 'b>(x: &'a u32, y: &'b u32) -> &'b u32 { + &*x +} + +fn main() { } diff --git a/src/test/ui/nll/named-region-basic.stderr b/src/test/ui/nll/named-region-basic.stderr new file mode 100644 index 00000000000..42b2aea01f0 --- /dev/null +++ b/src/test/ui/nll/named-region-basic.stderr @@ -0,0 +1,29 @@ +warning: not reporting region error due to -Znll + --> $DIR/named-region-basic.rs:19:5 + | +19 | &*x + | ^^^ + +error[E0597]: `*x` does not live long enough + --> $DIR/named-region-basic.rs:19:6 + | +19 | &*x + | ^^ does not live long enough + | + = note: borrowed value must be valid for the static lifetime... +note: ...but borrowed value is only valid for the lifetime 'a as defined on the function body at 18:1 + --> $DIR/named-region-basic.rs:18:1 + | +18 | / fn foo<'a, 'b>(x: &'a u32, y: &'b u32) -> &'b u32 { +19 | | &*x +20 | | } + | |_^ + +error: free region `'a` does not outlive `'b` + --> $DIR/named-region-basic.rs:19:5 + | +19 | &*x + | ^^^ + +error: aborting due to 2 previous errors + |
