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