rust/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.rs
Rémy Rakic b99fe2b720 mark polonius=next's NLL imprecisions as known-bugs
- 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.
2025-08-08 15:15:09 +00:00

45 lines
1.1 KiB
Rust

#![crate_type = "lib"]
// An example from #63908 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: #63908
//@ [polonius] known-bug: #63908
//@ [polonius] compile-flags: -Z polonius=next
//@ [legacy] check-pass
//@ [legacy] compile-flags: -Z polonius=legacy
struct Node<T> {
value: T,
next: Option<Box<Self>>,
}
type List<T> = Option<Box<Node<T>>>;
fn remove_last_node_recursive<T>(node_ref: &mut List<T>) {
let next_ref = &mut node_ref.as_mut().unwrap().next;
if next_ref.is_some() {
remove_last_node_recursive(next_ref);
} else {
*node_ref = None;
}
}
// NLLs and polonius alpha fail here
fn remove_last_node_iterative<T>(mut node_ref: &mut List<T>) {
loop {
let next_ref = &mut node_ref.as_mut().unwrap().next;
if next_ref.is_some() {
node_ref = next_ref;
} else {
break;
}
}
*node_ref = None;
}