Skip to content

Commit 241ceed

Browse files
committed
Added test for deref projection.
1 parent 681af62 commit 241ceed

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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() {}

0 commit comments

Comments
 (0)