From 1314ba323b6612d5109344c1d8bf9ae16e1e421f Mon Sep 17 00:00:00 2001 From: Remy Rakic Date: Tue, 3 Dec 2019 14:07:41 +0100 Subject: [PATCH] add subset relations test using polonius It's a relatively simple smoke-test for subset errors, executed outside of the polonius compare-mode. --- src/test/ui/nll/polonius/subset-relations.rs | 30 +++++++++++++++++++ .../ui/nll/polonius/subset-relations.stderr | 14 +++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/test/ui/nll/polonius/subset-relations.rs create mode 100644 src/test/ui/nll/polonius/subset-relations.stderr diff --git a/src/test/ui/nll/polonius/subset-relations.rs b/src/test/ui/nll/polonius/subset-relations.rs new file mode 100644 index 00000000000..3f6f67ebf40 --- /dev/null +++ b/src/test/ui/nll/polonius/subset-relations.rs @@ -0,0 +1,30 @@ +// Checks that Polonius can compute cases of universal regions errors: +// "illegal subset relation errors", cases where analysis finds that +// two free regions outlive each other, without any evidence that this +// relation holds. + +// ignore-compare-mode-nll +// compile-flags: -Z borrowck=mir -Zpolonius + +// returning `y` requires that `'b: 'a`, but it's not known to be true +fn missing_subset<'a, 'b>(x: &'a u32, y: &'b u32) -> &'a u32 { + y //~ ERROR +} + +// `'b: 'a` is explicitly declared +fn valid_subset<'a, 'b: 'a>(x: &'a u32, y: &'b u32) -> &'a u32 { + y +} + +// because of `x`, it is implied that `'b: 'a` holds +fn implied_bounds_subset<'a, 'b>(x: &'a &'b mut u32) -> &'a u32 { + x +} + +// `'b: 'a` is declared, and `'a: 'c` is known via implied bounds: +// `'b: 'c` is therefore known to hold transitively +fn transitively_valid_subset<'a, 'b: 'a, 'c>(x: &'c &'a u32, y: &'b u32) -> &'c u32 { + y +} + +fn main() {} diff --git a/src/test/ui/nll/polonius/subset-relations.stderr b/src/test/ui/nll/polonius/subset-relations.stderr new file mode 100644 index 00000000000..63645106f82 --- /dev/null +++ b/src/test/ui/nll/polonius/subset-relations.stderr @@ -0,0 +1,14 @@ +error: lifetime may not live long enough + --> $DIR/subset-relations.rs:11:5 + | +LL | fn missing_subset<'a, 'b>(x: &'a u32, y: &'b u32) -> &'a u32 { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | y + | ^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` + | + = help: consider adding the following bound: `'b: 'a` + +error: aborting due to previous error + -- 2.44.0