mirror of
https://github.com/rust-lang/rust.git
synced 2025-12-03 05:38:28 +00:00
- linked-list cursor-like patterns - issue-46589 These are known-bugs for the polonius alpha, where they show the same imprecision as NLLs, but are supported by the old datalog implementation.
46 lines
1.1 KiB
Rust
46 lines
1.1 KiB
Rust
#![crate_type = "lib"]
|
|
|
|
// An example from #57165 of the linked-list cursor-like pattern of #46859/#48001, 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
|
|
//@ [nll] known-bug: #57165
|
|
//@ [polonius] known-bug: #57165
|
|
//@ [polonius] compile-flags: -Z polonius=next
|
|
//@ [legacy] check-pass
|
|
//@ [legacy] compile-flags: -Z polonius=legacy
|
|
|
|
struct X {
|
|
next: Option<Box<X>>,
|
|
}
|
|
|
|
fn no_control_flow() {
|
|
let mut b = Some(Box::new(X { next: None }));
|
|
let mut p = &mut b;
|
|
while let Some(now) = p {
|
|
p = &mut now.next;
|
|
}
|
|
}
|
|
|
|
// NLLs and polonius alpha fail here
|
|
fn conditional() {
|
|
let mut b = Some(Box::new(X { next: None }));
|
|
let mut p = &mut b;
|
|
while let Some(now) = p {
|
|
if true {
|
|
p = &mut now.next;
|
|
}
|
|
}
|
|
}
|
|
|
|
fn conditional_with_indirection() {
|
|
let mut b = Some(Box::new(X { next: None }));
|
|
let mut p = &mut b;
|
|
while let Some(now) = p {
|
|
if true {
|
|
p = &mut p.as_mut().unwrap().next;
|
|
}
|
|
}
|
|
}
|