]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/issue-62007-assign-differing-fields.rs
Rollup merge of #103644 - catlee:catlee/option-question-mark-docs, r=workingjubilee
[rust.git] / src / test / ui / nll / issue-62007-assign-differing-fields.rs
1 // Double-check we didn't go too far with our resolution to issue
2 // #62007: assigning over a field projection (`list.1 = n;` in this
3 // case) should kill only borrows of `list.1`; `list.0` can *not*
4 // necessarily be borrowed on the next iteration through the loop.
5
6 #![allow(dead_code)]
7
8 struct List<T> {
9     value: T,
10     next: Option<Box<List<T>>>,
11 }
12
13 fn to_refs<'a, T>(mut list: (&'a mut List<T>, &'a mut List<T>)) -> Vec<&'a mut T> {
14     let mut result = vec![];
15     loop {
16         result.push(&mut (list.0).value); //~ ERROR cannot borrow `list.0.value` as mutable
17         if let Some(n) = (list.0).next.as_mut() { //~ ERROR cannot borrow `list.0.next` as mutable
18             list.1 = n;
19         } else {
20             return result;
21         }
22     }
23 }
24
25 fn main() {}