blob: c5571f131da3b739a61bbdefbaba7ed026b7ec5d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
// An example (from @steffahn) of reachability as an approximation of liveness where the polonius
// alpha analysis shows the same imprecision as NLLs, unlike the datalog implementation.
//@ ignore-compare-mode-polonius (explicit revisions)
//@ revisions: nll polonius legacy
//@ [polonius] compile-flags: -Z polonius=next
//@ [legacy] check-pass
//@ [legacy] compile-flags: -Z polonius=legacy
use std::cell::Cell;
struct Invariant<'l>(Cell<&'l ()>);
fn create_invariant<'l>() -> Invariant<'l> {
Invariant(Cell::new(&()))
}
fn use_it<'a, 'b>(choice: bool) -> Result<Invariant<'a>, Invariant<'b>> {
let returned_value = create_invariant();
if choice { Ok(returned_value) } else { Err(returned_value) }
//[nll]~^ ERROR lifetime may not live long enough
//[nll]~| ERROR lifetime may not live long enough
//[polonius]~^^^ ERROR lifetime may not live long enough
//[polonius]~| ERROR lifetime may not live long enough
}
fn use_it_but_its_the_same_region<'a: 'b, 'b: 'a>(
choice: bool,
) -> Result<Invariant<'a>, Invariant<'b>> {
let returned_value = create_invariant();
if choice { Ok(returned_value) } else { Err(returned_value) }
}
fn main() {}
|