Skip to content

Commit dbb6519

Browse files
committed
NLL test for mutating &mut references
1 parent b71cbd8 commit dbb6519

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(nll)]
12+
13+
struct List<T> {
14+
value: T,
15+
next: Option<Box<List<T>>>,
16+
}
17+
18+
fn to_refs<T>(mut list: &mut List<T>) -> Vec<&mut T> {
19+
let mut result = vec![];
20+
loop {
21+
result.push(&mut list.value);
22+
if let Some(n) = list.next.as_mut() {
23+
list = n;
24+
} else {
25+
return result;
26+
}
27+
}
28+
}
29+
30+
fn main() {
31+
let mut list = List { value: 1, next: None };
32+
let vec = to_refs(&mut list);
33+
assert_eq!(vec![&mut 1], vec);
34+
}

0 commit comments

Comments
 (0)