Skip to content

Commit

Permalink
Rollup merge of rust-lang#47609 - ritiek:test-mutating-references, r=…
Browse files Browse the repository at this point in the history
…nikomatsakis

NLL test for mutating &mut references

As mentioned in rust-lang#46361.

cc @nikomatsakis?
  • Loading branch information
GuillaumeGomez committed Jan 25, 2018
2 parents 147f5ce + 06d123d commit 2afd21d
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -8,17 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z borrowck=mir -Z nll

// This example comes from the NLL RFC.
#![feature(nll)]

struct List<T> {
value: T,
next: Option<Box<List<T>>>,
}

fn to_refs<T>(list: &mut List<T>) -> Vec<&mut T> {
let mut list = list;
fn to_refs<T>(mut list: &mut List<T>) -> Vec<&mut T> {
let mut result = vec![];
loop {
result.push(&mut list.value);
Expand All @@ -31,4 +28,7 @@ fn to_refs<T>(list: &mut List<T>) -> Vec<&mut T> {
}

fn main() {
let mut list = List { value: 1, next: None };
let vec = to_refs(&mut list);
assert_eq!(vec![&mut 1], vec);
}

0 comments on commit 2afd21d

Please sign in to comment.