]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/issue-62007-assign-box.rs
Rollup merge of #106644 - alexcrichton:update-wasi-toolchain, r=cuviper
[rust.git] / tests / ui / borrowck / issue-62007-assign-box.rs
1 // run-pass
2
3 // Issue #62007: assigning over a deref projection of a box (in this
4 // case, `*list = n;`) should be able to kill all borrows of `*list`,
5 // so that `*list` can be borrowed on the next iteration through the
6 // loop.
7
8 #![allow(dead_code)]
9
10 struct List<T> {
11     value: T,
12     next: Option<Box<List<T>>>,
13 }
14
15 fn to_refs<T>(mut list: Box<&mut List<T>>) -> Vec<&mut T> {
16     let mut result = vec![];
17     loop {
18         result.push(&mut list.value);
19         if let Some(n) = list.next.as_mut() {
20             *list = n;
21         } else {
22             return result;
23         }
24     }
25 }
26
27 fn main() {}