Skip to content

Commit 1314ba3

Browse files
committed
add subset relations test using polonius
It's a relatively simple smoke-test for subset errors, executed outside of the polonius compare-mode.
1 parent e2230a4 commit 1314ba3

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Checks that Polonius can compute cases of universal regions errors:
2+
// "illegal subset relation errors", cases where analysis finds that
3+
// two free regions outlive each other, without any evidence that this
4+
// relation holds.
5+
6+
// ignore-compare-mode-nll
7+
// compile-flags: -Z borrowck=mir -Zpolonius
8+
9+
// returning `y` requires that `'b: 'a`, but it's not known to be true
10+
fn missing_subset<'a, 'b>(x: &'a u32, y: &'b u32) -> &'a u32 {
11+
y //~ ERROR
12+
}
13+
14+
// `'b: 'a` is explicitly declared
15+
fn valid_subset<'a, 'b: 'a>(x: &'a u32, y: &'b u32) -> &'a u32 {
16+
y
17+
}
18+
19+
// because of `x`, it is implied that `'b: 'a` holds
20+
fn implied_bounds_subset<'a, 'b>(x: &'a &'b mut u32) -> &'a u32 {
21+
x
22+
}
23+
24+
// `'b: 'a` is declared, and `'a: 'c` is known via implied bounds:
25+
// `'b: 'c` is therefore known to hold transitively
26+
fn transitively_valid_subset<'a, 'b: 'a, 'c>(x: &'c &'a u32, y: &'b u32) -> &'c u32 {
27+
y
28+
}
29+
30+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/subset-relations.rs:11:5
3+
|
4+
LL | fn missing_subset<'a, 'b>(x: &'a u32, y: &'b u32) -> &'a u32 {
5+
| -- -- lifetime `'b` defined here
6+
| |
7+
| lifetime `'a` defined here
8+
LL | y
9+
| ^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b`
10+
|
11+
= help: consider adding the following bound: `'b: 'a`
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)