Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NLL test for mutating &mut references #47609

Merged
merged 2 commits into from
Jan 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}