Just shuffling files here; the needed updates to content come later.
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// pretty-expanded FIXME #23616
-
-pub fn main() {
- struct A {
- a: isize,
- w: B,
- }
- struct B {
- a: isize
- }
- let mut p = A {
- a: 1,
- w: B {a: 1},
- };
-
- // even though `x` is not declared as a mutable field,
- // `p` as a whole is mutable, so it can be modified.
- p.a = 2;
-
- // this is true for an interior field too
- p.w.a = 2;
-}
+++ /dev/null
-// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// Test taken from #45641 (https://github.com/rust-lang/rust/issues/45641)
-
-// revisions: ast mir
-//[mir]compile-flags: -Z borrowck=mir
-
-static mut Y: u32 = 0;
-
-unsafe fn should_ok() {
- Y = 1;
-}
-
-fn main() {}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-struct F { f: Vec<isize> }
-
-fn impure(_v: &[isize]) {
-}
-
-pub fn main() {
- let mut x = F {f: vec![3]};
-
- match x {
- F {f: ref mut v} => {
- impure(v);
- }
- }
-}
+++ /dev/null
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![feature(box_syntax)]
-
-fn borrow<F>(x: &isize, f: F) where F: FnOnce(&isize) {
- f(x)
-}
-
-fn test1(x: &Box<isize>) {
- borrow(&*(*x).clone(), |p| {
- let x_a = &**x as *const isize;
- assert!((x_a as usize) != (p as *const isize as usize));
- assert_eq!(unsafe{*x_a}, *p);
- })
-}
-
-pub fn main() {
- test1(&box 22);
-}
+++ /dev/null
-// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// Test that freezing an `&mut` pointer while referent is
-// frozen is legal.
-//
-// Example from src/librustc_borrowck/borrowck/README.md
-
-// pretty-expanded FIXME #23616
-
-fn foo<'a>(mut t0: &'a mut isize,
- mut t1: &'a mut isize) {
- let p: &isize = &*t0; // Freezes `*t0`
- let mut t2 = &t0;
- let q: &isize = &**t2; // Freezes `*t0`, but that's ok...
- let r: &isize = &*t0; // ...after all, could do same thing directly.
-}
-
-pub fn main() {
-}
+++ /dev/null
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// Tests that two closures can simultaneously have immutable
-// access to the variable, whether that immutable access be used
-// for direct reads or for taking immutable ref. Also check
-// that the main function can read the variable too while
-// the closures are in scope. Issue #6801.
-
-
-fn a() -> i32 {
- let mut x = 3;
- x += 1;
- let c1 = || x * 4;
- let c2 = || x * 5;
- c1() * c2() * x
-}
-
-fn get(x: &i32) -> i32 {
- *x * 4
-}
-
-fn b() -> i32 {
- let mut x = 3;
- x += 1;
- let c1 = || get(&x);
- let c2 = || get(&x);
- c1() * c2() * x
-}
-
-fn c() -> i32 {
- let mut x = 3;
- x += 1;
- let c1 = || x * 5;
- let c2 = || get(&x);
- c1() * c2() * x
-}
-
-pub fn main() {
- assert_eq!(a(), 1280);
- assert_eq!(b(), 1024);
- assert_eq!(c(), 1280);
-}
+++ /dev/null
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// pretty-expanded FIXME #23616
-
-#![feature(box_syntax)]
-
-struct A { a: isize, b: Box<isize> }
-struct B { a: Box<isize>, b: Box<isize> }
-
-fn move_after_copy() {
- let x = A { a: 1, b: box 2 };
- drop(x.a);
- drop(x.b);
-}
-
-fn move_after_fu_copy() {
- let x = A { a: 1, b: box 2 };
- let _y = A { b: box 3, .. x };
- drop(x.b);
-}
-
-fn fu_move_after_copy() {
- let x = A { a: 1, b: box 2 };
- drop(x.a);
- let _y = A { a: 3, .. x };
-}
-
-fn fu_move_after_fu_copy() {
- let x = A { a: 1, b: box 2 };
- let _y = A { b: box 3, .. x };
- let _z = A { a: 4, .. x };
-}
-
-fn copy_after_move() {
- let x = A { a: 1, b: box 2 };
- drop(x.b);
- drop(x.a);
-}
-
-fn copy_after_fu_move() {
- let x = A { a: 1, b: box 2 };
- let y = A { a: 3, .. x };
- drop(x.a);
-}
-
-fn fu_copy_after_move() {
- let x = A { a: 1, b: box 2 };
- drop(x.b);
- let _y = A { b: box 3, .. x };
-}
-
-fn fu_copy_after_fu_move() {
- let x = A { a: 1, b: box 2 };
- let _y = A { a: 3, .. x };
- let _z = A { b: box 3, .. x };
-}
-
-fn borrow_after_move() {
- let x = A { a: 1, b: box 2 };
- drop(x.b);
- let p = &x.a;
- drop(*p);
-}
-
-fn borrow_after_fu_move() {
- let x = A { a: 1, b: box 2 };
- let _y = A { a: 3, .. x };
- let p = &x.a;
- drop(*p);
-}
-
-fn move_after_borrow() {
- let x = A { a: 1, b: box 2 };
- let p = &x.a;
- drop(x.b);
- drop(*p);
-}
-
-fn fu_move_after_borrow() {
- let x = A { a: 1, b: box 2 };
- let p = &x.a;
- let _y = A { a: 3, .. x };
- drop(*p);
-}
-
-fn mut_borrow_after_mut_borrow() {
- let mut x = A { a: 1, b: box 2 };
- let p = &mut x.a;
- let q = &mut x.b;
- drop(*p);
- drop(**q);
-}
-
-fn move_after_move() {
- let x = B { a: box 1, b: box 2 };
- drop(x.a);
- drop(x.b);
-}
-
-fn move_after_fu_move() {
- let x = B { a: box 1, b: box 2 };
- let y = B { a: box 3, .. x };
- drop(x.a);
-}
-
-fn fu_move_after_move() {
- let x = B { a: box 1, b: box 2 };
- drop(x.a);
- let z = B { a: box 3, .. x };
- drop(z.b);
-}
-
-fn fu_move_after_fu_move() {
- let x = B { a: box 1, b: box 2 };
- let _y = B { b: box 3, .. x };
- let _z = B { a: box 4, .. x };
-}
-
-fn copy_after_assign_after_move() {
- let mut x = A { a: 1, b: box 2 };
- drop(x.b);
- x = A { a: 3, b: box 4 };
- drop(*x.b);
-}
-
-fn copy_after_assign_after_fu_move() {
- let mut x = A { a: 1, b: box 2 };
- let _y = A { a: 3, .. x };
- x = A { a: 3, b: box 4 };
- drop(*x.b);
-}
-
-fn copy_after_field_assign_after_move() {
- let mut x = A { a: 1, b: box 2 };
- drop(x.b);
- x.b = box 3;
- drop(*x.b);
-}
-
-fn copy_after_field_assign_after_fu_move() {
- let mut x = A { a: 1, b: box 2 };
- let _y = A { a: 3, .. x };
- x.b = box 3;
- drop(*x.b);
-}
-
-fn borrow_after_assign_after_move() {
- let mut x = A { a: 1, b: box 2 };
- drop(x.b);
- x = A { a: 3, b: box 4 };
- let p = &x.b;
- drop(**p);
-}
-
-fn borrow_after_assign_after_fu_move() {
- let mut x = A { a: 1, b: box 2 };
- let _y = A { a: 3, .. x };
- x = A { a: 3, b: box 4 };
- let p = &x.b;
- drop(**p);
-}
-
-fn borrow_after_field_assign_after_move() {
- let mut x = A { a: 1, b: box 2 };
- drop(x.b);
- x.b = box 3;
- let p = &x.b;
- drop(**p);
-}
-
-fn borrow_after_field_assign_after_fu_move() {
- let mut x = A { a: 1, b: box 2 };
- let _y = A { a: 3, .. x };
- x.b = box 3;
- let p = &x.b;
- drop(**p);
-}
-
-fn move_after_assign_after_move() {
- let mut x = A { a: 1, b: box 2 };
- let _y = x.b;
- x = A { a: 3, b: box 4 };
- drop(x.b);
-}
-
-fn move_after_assign_after_fu_move() {
- let mut x = A { a: 1, b: box 2 };
- let _y = A { a: 3, .. x };
- x = A { a: 3, b: box 4 };
- drop(x.b);
-}
-
-fn move_after_field_assign_after_move() {
- let mut x = A { a: 1, b: box 2 };
- drop(x.b);
- x.b = box 3;
- drop(x.b);
-}
-
-fn move_after_field_assign_after_fu_move() {
- let mut x = A { a: 1, b: box 2 };
- let _y = A { a: 3, .. x };
- x.b = box 3;
- drop(x.b);
-}
-
-fn copy_after_assign_after_uninit() {
- let mut x: A;
- x = A { a: 1, b: box 2 };
- drop(x.a);
-}
-
-fn borrow_after_assign_after_uninit() {
- let mut x: A;
- x = A { a: 1, b: box 2 };
- let p = &x.a;
- drop(*p);
-}
-
-fn move_after_assign_after_uninit() {
- let mut x: A;
- x = A { a: 1, b: box 2 };
- drop(x.b);
-}
-
-fn main() {
- move_after_copy();
- move_after_fu_copy();
- fu_move_after_copy();
- fu_move_after_fu_copy();
- copy_after_move();
- copy_after_fu_move();
- fu_copy_after_move();
- fu_copy_after_fu_move();
-
- borrow_after_move();
- borrow_after_fu_move();
- move_after_borrow();
- fu_move_after_borrow();
- mut_borrow_after_mut_borrow();
-
- move_after_move();
- move_after_fu_move();
- fu_move_after_move();
- fu_move_after_fu_move();
-
- copy_after_assign_after_move();
- copy_after_assign_after_fu_move();
- copy_after_field_assign_after_move();
- copy_after_field_assign_after_fu_move();
-
- borrow_after_assign_after_move();
- borrow_after_assign_after_fu_move();
- borrow_after_field_assign_after_move();
- borrow_after_field_assign_after_fu_move();
-
- move_after_assign_after_move();
- move_after_assign_after_fu_move();
- move_after_field_assign_after_move();
- move_after_field_assign_after_fu_move();
-
- copy_after_assign_after_uninit();
- borrow_after_assign_after_uninit();
- move_after_assign_after_uninit();
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-
-pub fn main() {
- let x = [22];
- let y = &x[0];
- assert_eq!(*y, 22);
-}
+++ /dev/null
-// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// Test that a `&mut` inside of an `&` is freezable.
-
-
-struct MutSlice<'a, T:'a> {
- data: &'a mut [T]
-}
-
-fn get<'a, T>(ms: &'a MutSlice<'a, T>, index: usize) -> &'a T {
- &ms.data[index]
-}
-
-pub fn main() {
- let mut data = [1, 2, 3];
- {
- let slice = MutSlice { data: &mut data };
- slice.data[0] += 4;
- let index0 = get(&slice, 0);
- let index1 = get(&slice, 1);
- let index2 = get(&slice, 2);
- assert_eq!(*index0, 5);
- assert_eq!(*index1, 2);
- assert_eq!(*index2, 3);
- }
- assert_eq!(data[0], 5);
- assert_eq!(data[1], 2);
- assert_eq!(data[2], 3);
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-
-// pretty-expanded FIXME #23616
-
-fn borrow(_v: &isize) {}
-
-fn borrow_from_arg_imm_ref(v: Box<isize>) {
- borrow(&*v);
-}
-
-fn borrow_from_arg_mut_ref(v: &mut Box<isize>) {
- borrow(&**v);
-}
-
-fn borrow_from_arg_copy(v: Box<isize>) {
- borrow(&*v);
-}
-
-pub fn main() {
-}
+++ /dev/null
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// Check that we do not ICE when compiling this
-// macro, which reuses the expression `$id`
-
-
-#![feature(box_patterns)]
-#![feature(box_syntax)]
-
-struct Foo {
- a: isize
-}
-
-pub enum Bar {
- Bar1, Bar2(isize, Box<Bar>),
-}
-
-impl Foo {
- fn elaborate_stm(&mut self, s: Box<Bar>) -> Box<Bar> {
- macro_rules! declare {
- ($id:expr, $rest:expr) => ({
- self.check_id($id);
- box Bar::Bar2($id, $rest)
- })
- }
- match s {
- box Bar::Bar2(id, rest) => declare!(id, self.elaborate_stm(rest)),
- _ => panic!()
- }
- }
-
- fn check_id(&mut self, s: isize) { panic!() }
-}
-
-pub fn main() { }
+++ /dev/null
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![feature(box_syntax)]
-
-pub fn main() {
- let bar: Box<_> = box 3;
- let h = || -> isize { *bar };
- assert_eq!(h(), 3);
-}
+++ /dev/null
-// 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.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// Test case from #39963.
-
-#![feature(nll)]
-
-#[derive(Clone)]
-struct Foo(Option<Box<Foo>>, Option<Box<Foo>>);
-
-fn test(f: &mut Foo) {
- match *f {
- Foo(Some(ref mut left), Some(ref mut right)) => match **left {
- Foo(Some(ref mut left), Some(ref mut right)) => panic!(),
- _ => panic!(),
- },
- _ => panic!(),
- }
-}
-
-fn main() {
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![feature(box_syntax)]
-
-use std::mem::swap;
-
-#[derive(Debug)]
-struct Ints {sum: Box<isize>, values: Vec<isize> }
-
-fn add_int(x: &mut Ints, v: isize) {
- *x.sum += v;
- let mut values = Vec::new();
- swap(&mut values, &mut x.values);
- values.push(v);
- swap(&mut values, &mut x.values);
-}
-
-fn iter_ints<F>(x: &Ints, mut f: F) -> bool where F: FnMut(&isize) -> bool {
- let l = x.values.len();
- (0..l).all(|i| f(&x.values[i]))
-}
-
-pub fn main() {
- let mut ints: Box<_> = box Ints {sum: box 0, values: Vec::new()};
- add_int(&mut *ints, 22);
- add_int(&mut *ints, 44);
-
- iter_ints(&*ints, |i| {
- println!("isize = {:?}", *i);
- true
- });
-
- println!("ints={:?}", ints);
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-
-
-fn want_slice(v: &[isize]) -> isize {
- let mut sum = 0;
- for i in v { sum += *i; }
- sum
-}
-
-fn has_mut_vec(v: Vec<isize> ) -> isize {
- want_slice(&v)
-}
-
-pub fn main() {
- assert_eq!(has_mut_vec(vec![1, 2, 3]), 6);
-}
+++ /dev/null
-// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// ignore-pretty issue #37199
-
-fn match_ref(v: Option<isize>) -> isize {
- match v {
- Some(ref i) => {
- *i
- }
- None => {0}
- }
-}
-
-fn match_ref_unused(v: Option<isize>) {
- match v {
- Some(_) => {}
- None => {}
- }
-}
-
-fn impure(_i: isize) {
-}
-
-fn match_imm_reg(v: &Option<isize>) {
- match *v {
- Some(ref i) => {impure(*i)} // OK because immutable
- None => {}
- }
-}
-
-fn match_mut_reg(v: &mut Option<isize>) {
- match *v {
- Some(ref i) => {impure(*i)} // OK, frozen
- None => {}
- }
-}
-
-pub fn main() {
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-
-pub fn main() {
- let mut x = None;
- match x {
- None => {
- // It is ok to reassign x here, because there is in
- // fact no outstanding loan of x!
- x = Some(0);
- }
- Some(_) => { }
- }
- assert_eq!(x, Some(0));
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-
-struct Counter {
- value: usize
-}
-
-impl Counter {
- fn new(v: usize) -> Counter {
- Counter {value: v}
- }
-
- fn inc<'a>(&'a mut self) -> &'a mut Counter {
- self.value += 1;
- self
- }
-
- fn get(&self) -> usize {
- self.value
- }
-
- fn get_and_inc(&mut self) -> usize {
- let v = self.value;
- self.value += 1;
- v
- }
-}
-
-pub fn main() {
- let v = Counter::new(22).get_and_inc();
- assert_eq!(v, 22);
-
- let v = Counter::new(22).inc().inc().get();
- assert_eq!(v, 24);
-}
+++ /dev/null
-// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// Tests that the scope of the pointer returned from `get()` is
-// limited to the deref operation itself, and does not infect the
-// block as a whole.
-
-
-struct Box {
- x: usize
-}
-
-impl Box {
- fn get(&self) -> &usize {
- &self.x
- }
- fn set(&mut self, x: usize) {
- self.x = x;
- }
-}
-
-fn fun1() {
- // in the past, borrow checker behaved differently when
- // init and decl of `v` were distinct
- let v;
- let mut a_box = Box {x: 0};
- a_box.set(22);
- v = *a_box.get();
- a_box.set(v+1);
- assert_eq!(23, *a_box.get());
-}
-
-fn fun2() {
- let mut a_box = Box {x: 0};
- a_box.set(22);
- let v = *a_box.get();
- a_box.set(v+1);
- assert_eq!(23, *a_box.get());
-}
-
-pub fn main() {
- fun1();
- fun2();
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-//compile-flags: -Z borrowck=mir
-
-#![feature(slice_patterns)]
-
-fn mut_head_tail<'a, A>(v: &'a mut [A]) -> Option<(&'a mut A, &'a mut [A])> {
- match *v {
- [ref mut head, ref mut tail..] => {
- Some((head, tail))
- }
- [] => None
- }
-}
-
-fn main() {
- let mut v = [1,2,3,4];
- match mut_head_tail(&mut v) {
- None => {},
- Some((h,t)) => {
- *h = 1000;
- t.reverse();
- }
- }
-}
+++ /dev/null
-// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// Regression test for issue #7740
-
-// pretty-expanded FIXME #23616
-
-pub fn main() {
- static A: &'static char = &'A';
-}
+++ /dev/null
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// This test verifies that casting from the same lifetime on a value
-// to the same lifetime on a trait succeeds. See issue #10766.
-
-// pretty-expanded FIXME #23616
-
-#![allow(dead_code)]
-
-use std::marker;
-
-fn main() {
- trait T { fn foo(&self) {} }
-
- fn f<'a, V: T>(v: &'a V) -> &'a T {
- v as &'a T
- }
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-
-// pretty-expanded FIXME #23616
-
-struct Rec {
- f: Box<isize>,
-}
-
-struct Outer {
- f: Inner
-}
-
-struct Inner {
- g: Innermost
-}
-
-struct Innermost {
- h: Box<isize>,
-}
-
-fn borrow(_v: &isize) {}
-
-fn box_mut(v: &mut Box<isize>) {
- borrow(&**v); // OK: &mut -> &imm
-}
-
-fn box_mut_rec(v: &mut Rec) {
- borrow(&*v.f); // OK: &mut -> &imm
-}
-
-fn box_mut_recs(v: &mut Outer) {
- borrow(&*v.f.g.h); // OK: &mut -> &imm
-}
-
-fn box_imm(v: &Box<isize>) {
- borrow(&**v); // OK
-}
-
-fn box_imm_rec(v: &Rec) {
- borrow(&*v.f); // OK
-}
-
-fn box_imm_recs(v: &Outer) {
- borrow(&*v.f.g.h); // OK
-}
-
-pub fn main() {
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-
-
-use std::cell::Cell;
-
-#[derive(Copy, Clone)]
-enum newtype {
- newvar(isize)
-}
-
-pub fn main() {
-
- // Test that borrowck treats enums with a single variant
- // specially.
-
- let x = &Cell::new(5);
- let y = &Cell::new(newtype::newvar(3));
- let z = match y.get() {
- newtype::newvar(b) => {
- x.set(x.get() + 1);
- x.get() * b
- }
- };
- assert_eq!(z, 18);
-}
+++ /dev/null
-// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// revisions: ast mir
-//[mir]compile-flags: -Z borrowck=mir
-
-// Test file taken from issue 45129 (https://github.com/rust-lang/rust/issues/45129)
-
-struct Foo { x: [usize; 2] }
-
-static mut SFOO: Foo = Foo { x: [23, 32] };
-
-impl Foo {
- fn x(&mut self) -> &mut usize { &mut self.x[0] }
-}
-
-fn main() {
- unsafe {
- let sfoo: *mut Foo = &mut SFOO;
- let x = (*sfoo).x();
- (*sfoo).x[1] += 1;
- *x += 1;
- }
-}
+++ /dev/null
-// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![feature(nll)]
-#![deny(unused_mut)]
-
-#[derive(Debug)]
-struct A {}
-
-fn init_a() -> A {
- A {}
-}
-
-#[derive(Debug)]
-struct B<'a> {
- ed: &'a mut A,
-}
-
-fn init_b<'a>(ed: &'a mut A) -> B<'a> {
- B { ed }
-}
-
-#[derive(Debug)]
-struct C<'a> {
- pd: &'a mut B<'a>,
-}
-
-fn init_c<'a>(pd: &'a mut B<'a>) -> C<'a> {
- C { pd }
-}
-
-#[derive(Debug)]
-struct D<'a> {
- sd: &'a mut C<'a>,
-}
-
-fn init_d<'a>(sd: &'a mut C<'a>) -> D<'a> {
- D { sd }
-}
-
-fn main() {
- let mut a = init_a();
- let mut b = init_b(&mut a);
- let mut c = init_c(&mut b);
-
- let d = init_d(&mut c);
-
- println!("{:?}", d)
-}
+++ /dev/null
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// pretty-expanded FIXME #23616
-
-#![feature(box_syntax)]
-
-struct A { a: isize, b: Box<isize> }
-
-fn field_copy_after_field_borrow() {
- let mut x = A { a: 1, b: box 2 };
- let p = &mut x.b;
- drop(x.a);
- **p = 3;
-}
-
-fn fu_field_copy_after_field_borrow() {
- let mut x = A { a: 1, b: box 2 };
- let p = &mut x.b;
- let y = A { b: box 3, .. x };
- drop(y);
- **p = 4;
-}
-
-fn field_deref_after_field_borrow() {
- let mut x = A { a: 1, b: box 2 };
- let p = &mut x.a;
- drop(*x.b);
- *p = 3;
-}
-
-fn field_move_after_field_borrow() {
- let mut x = A { a: 1, b: box 2 };
- let p = &mut x.a;
- drop(x.b);
- *p = 3;
-}
-
-fn fu_field_move_after_field_borrow() {
- let mut x = A { a: 1, b: box 2 };
- let p = &mut x.a;
- let y = A { a: 3, .. x };
- drop(y);
- *p = 4;
-}
-
-fn main() {
- field_copy_after_field_borrow();
- fu_field_copy_after_field_borrow();
- field_deref_after_field_borrow();
- field_move_after_field_borrow();
- fu_field_move_after_field_borrow();
-}
+++ /dev/null
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// compile-flags: -Z borrowck=mir -Z two-phase-borrows
-
-// This is the "goto example" for why we want two phase borrows.
-
-fn main() {
- let mut v = vec![0, 1, 2];
- v.push(v.len());
- assert_eq!(v, [0, 1, 2, 3]);
-}
+++ /dev/null
-// 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.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// revisions: lxl nll
-
-#![cfg_attr(nll, feature(nll))]
-
-use std::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign};
-use std::ops::{BitAndAssign, BitOrAssign, BitXorAssign, ShlAssign, ShrAssign};
-
-struct A(i32);
-
-macro_rules! trivial_binop {
- ($Trait:ident, $m:ident) => {
- impl $Trait<i32> for A { fn $m(&mut self, rhs: i32) { self.0 = rhs; } }
- }
-}
-
-trivial_binop!(AddAssign, add_assign);
-trivial_binop!(SubAssign, sub_assign);
-trivial_binop!(MulAssign, mul_assign);
-trivial_binop!(DivAssign, div_assign);
-trivial_binop!(RemAssign, rem_assign);
-trivial_binop!(BitAndAssign, bitand_assign);
-trivial_binop!(BitOrAssign, bitor_assign);
-trivial_binop!(BitXorAssign, bitxor_assign);
-trivial_binop!(ShlAssign, shl_assign);
-trivial_binop!(ShrAssign, shr_assign);
-
-fn main() {
- let mut a = A(10);
- a += a.0;
- a -= a.0;
- a *= a.0;
- a /= a.0;
- a &= a.0;
- a |= a.0;
- a ^= a.0;
- a <<= a.0;
- a >>= a.0;
-}
+++ /dev/null
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// revisions: lxl nll
-//[lxl]compile-flags: -Z borrowck=mir -Z two-phase-borrows
-
-#![cfg_attr(nll, feature(nll))]
-
-fn main() {
- let mut a = 0;
- let mut b = 0;
- let p = if maybe() {
- &mut a
- } else {
- &mut b
- };
- use_(p);
-}
-
-fn maybe() -> bool { false }
-fn use_<T>(_: T) { }
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// pretty-expanded FIXME #23616
+
+pub fn main() {
+ struct A {
+ a: isize,
+ w: B,
+ }
+ struct B {
+ a: isize
+ }
+ let mut p = A {
+ a: 1,
+ w: B {a: 1},
+ };
+
+ // even though `x` is not declared as a mutable field,
+ // `p` as a whole is mutable, so it can be modified.
+ p.a = 2;
+
+ // this is true for an interior field too
+ p.w.a = 2;
+}
--- /dev/null
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test taken from #45641 (https://github.com/rust-lang/rust/issues/45641)
+
+// revisions: ast mir
+//[mir]compile-flags: -Z borrowck=mir
+
+static mut Y: u32 = 0;
+
+unsafe fn should_ok() {
+ Y = 1;
+}
+
+fn main() {}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+struct F { f: Vec<isize> }
+
+fn impure(_v: &[isize]) {
+}
+
+pub fn main() {
+ let mut x = F {f: vec![3]};
+
+ match x {
+ F {f: ref mut v} => {
+ impure(v);
+ }
+ }
+}
--- /dev/null
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(box_syntax)]
+
+fn borrow<F>(x: &isize, f: F) where F: FnOnce(&isize) {
+ f(x)
+}
+
+fn test1(x: &Box<isize>) {
+ borrow(&*(*x).clone(), |p| {
+ let x_a = &**x as *const isize;
+ assert!((x_a as usize) != (p as *const isize as usize));
+ assert_eq!(unsafe{*x_a}, *p);
+ })
+}
+
+pub fn main() {
+ test1(&box 22);
+}
--- /dev/null
+// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test that freezing an `&mut` pointer while referent is
+// frozen is legal.
+//
+// Example from src/librustc_borrowck/borrowck/README.md
+
+// pretty-expanded FIXME #23616
+
+fn foo<'a>(mut t0: &'a mut isize,
+ mut t1: &'a mut isize) {
+ let p: &isize = &*t0; // Freezes `*t0`
+ let mut t2 = &t0;
+ let q: &isize = &**t2; // Freezes `*t0`, but that's ok...
+ let r: &isize = &*t0; // ...after all, could do same thing directly.
+}
+
+pub fn main() {
+}
--- /dev/null
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Tests that two closures can simultaneously have immutable
+// access to the variable, whether that immutable access be used
+// for direct reads or for taking immutable ref. Also check
+// that the main function can read the variable too while
+// the closures are in scope. Issue #6801.
+
+
+fn a() -> i32 {
+ let mut x = 3;
+ x += 1;
+ let c1 = || x * 4;
+ let c2 = || x * 5;
+ c1() * c2() * x
+}
+
+fn get(x: &i32) -> i32 {
+ *x * 4
+}
+
+fn b() -> i32 {
+ let mut x = 3;
+ x += 1;
+ let c1 = || get(&x);
+ let c2 = || get(&x);
+ c1() * c2() * x
+}
+
+fn c() -> i32 {
+ let mut x = 3;
+ x += 1;
+ let c1 = || x * 5;
+ let c2 = || get(&x);
+ c1() * c2() * x
+}
+
+pub fn main() {
+ assert_eq!(a(), 1280);
+ assert_eq!(b(), 1024);
+ assert_eq!(c(), 1280);
+}
--- /dev/null
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// pretty-expanded FIXME #23616
+
+#![feature(box_syntax)]
+
+struct A { a: isize, b: Box<isize> }
+struct B { a: Box<isize>, b: Box<isize> }
+
+fn move_after_copy() {
+ let x = A { a: 1, b: box 2 };
+ drop(x.a);
+ drop(x.b);
+}
+
+fn move_after_fu_copy() {
+ let x = A { a: 1, b: box 2 };
+ let _y = A { b: box 3, .. x };
+ drop(x.b);
+}
+
+fn fu_move_after_copy() {
+ let x = A { a: 1, b: box 2 };
+ drop(x.a);
+ let _y = A { a: 3, .. x };
+}
+
+fn fu_move_after_fu_copy() {
+ let x = A { a: 1, b: box 2 };
+ let _y = A { b: box 3, .. x };
+ let _z = A { a: 4, .. x };
+}
+
+fn copy_after_move() {
+ let x = A { a: 1, b: box 2 };
+ drop(x.b);
+ drop(x.a);
+}
+
+fn copy_after_fu_move() {
+ let x = A { a: 1, b: box 2 };
+ let y = A { a: 3, .. x };
+ drop(x.a);
+}
+
+fn fu_copy_after_move() {
+ let x = A { a: 1, b: box 2 };
+ drop(x.b);
+ let _y = A { b: box 3, .. x };
+}
+
+fn fu_copy_after_fu_move() {
+ let x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ let _z = A { b: box 3, .. x };
+}
+
+fn borrow_after_move() {
+ let x = A { a: 1, b: box 2 };
+ drop(x.b);
+ let p = &x.a;
+ drop(*p);
+}
+
+fn borrow_after_fu_move() {
+ let x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ let p = &x.a;
+ drop(*p);
+}
+
+fn move_after_borrow() {
+ let x = A { a: 1, b: box 2 };
+ let p = &x.a;
+ drop(x.b);
+ drop(*p);
+}
+
+fn fu_move_after_borrow() {
+ let x = A { a: 1, b: box 2 };
+ let p = &x.a;
+ let _y = A { a: 3, .. x };
+ drop(*p);
+}
+
+fn mut_borrow_after_mut_borrow() {
+ let mut x = A { a: 1, b: box 2 };
+ let p = &mut x.a;
+ let q = &mut x.b;
+ drop(*p);
+ drop(**q);
+}
+
+fn move_after_move() {
+ let x = B { a: box 1, b: box 2 };
+ drop(x.a);
+ drop(x.b);
+}
+
+fn move_after_fu_move() {
+ let x = B { a: box 1, b: box 2 };
+ let y = B { a: box 3, .. x };
+ drop(x.a);
+}
+
+fn fu_move_after_move() {
+ let x = B { a: box 1, b: box 2 };
+ drop(x.a);
+ let z = B { a: box 3, .. x };
+ drop(z.b);
+}
+
+fn fu_move_after_fu_move() {
+ let x = B { a: box 1, b: box 2 };
+ let _y = B { b: box 3, .. x };
+ let _z = B { a: box 4, .. x };
+}
+
+fn copy_after_assign_after_move() {
+ let mut x = A { a: 1, b: box 2 };
+ drop(x.b);
+ x = A { a: 3, b: box 4 };
+ drop(*x.b);
+}
+
+fn copy_after_assign_after_fu_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ x = A { a: 3, b: box 4 };
+ drop(*x.b);
+}
+
+fn copy_after_field_assign_after_move() {
+ let mut x = A { a: 1, b: box 2 };
+ drop(x.b);
+ x.b = box 3;
+ drop(*x.b);
+}
+
+fn copy_after_field_assign_after_fu_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ x.b = box 3;
+ drop(*x.b);
+}
+
+fn borrow_after_assign_after_move() {
+ let mut x = A { a: 1, b: box 2 };
+ drop(x.b);
+ x = A { a: 3, b: box 4 };
+ let p = &x.b;
+ drop(**p);
+}
+
+fn borrow_after_assign_after_fu_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ x = A { a: 3, b: box 4 };
+ let p = &x.b;
+ drop(**p);
+}
+
+fn borrow_after_field_assign_after_move() {
+ let mut x = A { a: 1, b: box 2 };
+ drop(x.b);
+ x.b = box 3;
+ let p = &x.b;
+ drop(**p);
+}
+
+fn borrow_after_field_assign_after_fu_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ x.b = box 3;
+ let p = &x.b;
+ drop(**p);
+}
+
+fn move_after_assign_after_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = x.b;
+ x = A { a: 3, b: box 4 };
+ drop(x.b);
+}
+
+fn move_after_assign_after_fu_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ x = A { a: 3, b: box 4 };
+ drop(x.b);
+}
+
+fn move_after_field_assign_after_move() {
+ let mut x = A { a: 1, b: box 2 };
+ drop(x.b);
+ x.b = box 3;
+ drop(x.b);
+}
+
+fn move_after_field_assign_after_fu_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ x.b = box 3;
+ drop(x.b);
+}
+
+fn copy_after_assign_after_uninit() {
+ let mut x: A;
+ x = A { a: 1, b: box 2 };
+ drop(x.a);
+}
+
+fn borrow_after_assign_after_uninit() {
+ let mut x: A;
+ x = A { a: 1, b: box 2 };
+ let p = &x.a;
+ drop(*p);
+}
+
+fn move_after_assign_after_uninit() {
+ let mut x: A;
+ x = A { a: 1, b: box 2 };
+ drop(x.b);
+}
+
+fn main() {
+ move_after_copy();
+ move_after_fu_copy();
+ fu_move_after_copy();
+ fu_move_after_fu_copy();
+ copy_after_move();
+ copy_after_fu_move();
+ fu_copy_after_move();
+ fu_copy_after_fu_move();
+
+ borrow_after_move();
+ borrow_after_fu_move();
+ move_after_borrow();
+ fu_move_after_borrow();
+ mut_borrow_after_mut_borrow();
+
+ move_after_move();
+ move_after_fu_move();
+ fu_move_after_move();
+ fu_move_after_fu_move();
+
+ copy_after_assign_after_move();
+ copy_after_assign_after_fu_move();
+ copy_after_field_assign_after_move();
+ copy_after_field_assign_after_fu_move();
+
+ borrow_after_assign_after_move();
+ borrow_after_assign_after_fu_move();
+ borrow_after_field_assign_after_move();
+ borrow_after_field_assign_after_fu_move();
+
+ move_after_assign_after_move();
+ move_after_assign_after_fu_move();
+ move_after_field_assign_after_move();
+ move_after_field_assign_after_fu_move();
+
+ copy_after_assign_after_uninit();
+ borrow_after_assign_after_uninit();
+ move_after_assign_after_uninit();
+}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+
+pub fn main() {
+ let x = [22];
+ let y = &x[0];
+ assert_eq!(*y, 22);
+}
--- /dev/null
+// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test that a `&mut` inside of an `&` is freezable.
+
+
+struct MutSlice<'a, T:'a> {
+ data: &'a mut [T]
+}
+
+fn get<'a, T>(ms: &'a MutSlice<'a, T>, index: usize) -> &'a T {
+ &ms.data[index]
+}
+
+pub fn main() {
+ let mut data = [1, 2, 3];
+ {
+ let slice = MutSlice { data: &mut data };
+ slice.data[0] += 4;
+ let index0 = get(&slice, 0);
+ let index1 = get(&slice, 1);
+ let index2 = get(&slice, 2);
+ assert_eq!(*index0, 5);
+ assert_eq!(*index1, 2);
+ assert_eq!(*index2, 3);
+ }
+ assert_eq!(data[0], 5);
+ assert_eq!(data[1], 2);
+ assert_eq!(data[2], 3);
+}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+
+// pretty-expanded FIXME #23616
+
+fn borrow(_v: &isize) {}
+
+fn borrow_from_arg_imm_ref(v: Box<isize>) {
+ borrow(&*v);
+}
+
+fn borrow_from_arg_mut_ref(v: &mut Box<isize>) {
+ borrow(&**v);
+}
+
+fn borrow_from_arg_copy(v: Box<isize>) {
+ borrow(&*v);
+}
+
+pub fn main() {
+}
--- /dev/null
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Check that we do not ICE when compiling this
+// macro, which reuses the expression `$id`
+
+
+#![feature(box_patterns)]
+#![feature(box_syntax)]
+
+struct Foo {
+ a: isize
+}
+
+pub enum Bar {
+ Bar1, Bar2(isize, Box<Bar>),
+}
+
+impl Foo {
+ fn elaborate_stm(&mut self, s: Box<Bar>) -> Box<Bar> {
+ macro_rules! declare {
+ ($id:expr, $rest:expr) => ({
+ self.check_id($id);
+ box Bar::Bar2($id, $rest)
+ })
+ }
+ match s {
+ box Bar::Bar2(id, rest) => declare!(id, self.elaborate_stm(rest)),
+ _ => panic!()
+ }
+ }
+
+ fn check_id(&mut self, s: isize) { panic!() }
+}
+
+pub fn main() { }
--- /dev/null
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(box_syntax)]
+
+pub fn main() {
+ let bar: Box<_> = box 3;
+ let h = || -> isize { *bar };
+ assert_eq!(h(), 3);
+}
--- /dev/null
+// 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.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test case from #39963.
+
+#![feature(nll)]
+
+#[derive(Clone)]
+struct Foo(Option<Box<Foo>>, Option<Box<Foo>>);
+
+fn test(f: &mut Foo) {
+ match *f {
+ Foo(Some(ref mut left), Some(ref mut right)) => match **left {
+ Foo(Some(ref mut left), Some(ref mut right)) => panic!(),
+ _ => panic!(),
+ },
+ _ => panic!(),
+ }
+}
+
+fn main() {
+}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(box_syntax)]
+
+use std::mem::swap;
+
+#[derive(Debug)]
+struct Ints {sum: Box<isize>, values: Vec<isize> }
+
+fn add_int(x: &mut Ints, v: isize) {
+ *x.sum += v;
+ let mut values = Vec::new();
+ swap(&mut values, &mut x.values);
+ values.push(v);
+ swap(&mut values, &mut x.values);
+}
+
+fn iter_ints<F>(x: &Ints, mut f: F) -> bool where F: FnMut(&isize) -> bool {
+ let l = x.values.len();
+ (0..l).all(|i| f(&x.values[i]))
+}
+
+pub fn main() {
+ let mut ints: Box<_> = box Ints {sum: box 0, values: Vec::new()};
+ add_int(&mut *ints, 22);
+ add_int(&mut *ints, 44);
+
+ iter_ints(&*ints, |i| {
+ println!("isize = {:?}", *i);
+ true
+ });
+
+ println!("ints={:?}", ints);
+}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+
+
+fn want_slice(v: &[isize]) -> isize {
+ let mut sum = 0;
+ for i in v { sum += *i; }
+ sum
+}
+
+fn has_mut_vec(v: Vec<isize> ) -> isize {
+ want_slice(&v)
+}
+
+pub fn main() {
+ assert_eq!(has_mut_vec(vec![1, 2, 3]), 6);
+}
--- /dev/null
+// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// ignore-pretty issue #37199
+
+fn match_ref(v: Option<isize>) -> isize {
+ match v {
+ Some(ref i) => {
+ *i
+ }
+ None => {0}
+ }
+}
+
+fn match_ref_unused(v: Option<isize>) {
+ match v {
+ Some(_) => {}
+ None => {}
+ }
+}
+
+fn impure(_i: isize) {
+}
+
+fn match_imm_reg(v: &Option<isize>) {
+ match *v {
+ Some(ref i) => {impure(*i)} // OK because immutable
+ None => {}
+ }
+}
+
+fn match_mut_reg(v: &mut Option<isize>) {
+ match *v {
+ Some(ref i) => {impure(*i)} // OK, frozen
+ None => {}
+ }
+}
+
+pub fn main() {
+}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+
+pub fn main() {
+ let mut x = None;
+ match x {
+ None => {
+ // It is ok to reassign x here, because there is in
+ // fact no outstanding loan of x!
+ x = Some(0);
+ }
+ Some(_) => { }
+ }
+ assert_eq!(x, Some(0));
+}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+
+struct Counter {
+ value: usize
+}
+
+impl Counter {
+ fn new(v: usize) -> Counter {
+ Counter {value: v}
+ }
+
+ fn inc<'a>(&'a mut self) -> &'a mut Counter {
+ self.value += 1;
+ self
+ }
+
+ fn get(&self) -> usize {
+ self.value
+ }
+
+ fn get_and_inc(&mut self) -> usize {
+ let v = self.value;
+ self.value += 1;
+ v
+ }
+}
+
+pub fn main() {
+ let v = Counter::new(22).get_and_inc();
+ assert_eq!(v, 22);
+
+ let v = Counter::new(22).inc().inc().get();
+ assert_eq!(v, 24);
+}
--- /dev/null
+// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Tests that the scope of the pointer returned from `get()` is
+// limited to the deref operation itself, and does not infect the
+// block as a whole.
+
+
+struct Box {
+ x: usize
+}
+
+impl Box {
+ fn get(&self) -> &usize {
+ &self.x
+ }
+ fn set(&mut self, x: usize) {
+ self.x = x;
+ }
+}
+
+fn fun1() {
+ // in the past, borrow checker behaved differently when
+ // init and decl of `v` were distinct
+ let v;
+ let mut a_box = Box {x: 0};
+ a_box.set(22);
+ v = *a_box.get();
+ a_box.set(v+1);
+ assert_eq!(23, *a_box.get());
+}
+
+fn fun2() {
+ let mut a_box = Box {x: 0};
+ a_box.set(22);
+ let v = *a_box.get();
+ a_box.set(v+1);
+ assert_eq!(23, *a_box.get());
+}
+
+pub fn main() {
+ fun1();
+ fun2();
+}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//compile-flags: -Z borrowck=mir
+
+#![feature(slice_patterns)]
+
+fn mut_head_tail<'a, A>(v: &'a mut [A]) -> Option<(&'a mut A, &'a mut [A])> {
+ match *v {
+ [ref mut head, ref mut tail..] => {
+ Some((head, tail))
+ }
+ [] => None
+ }
+}
+
+fn main() {
+ let mut v = [1,2,3,4];
+ match mut_head_tail(&mut v) {
+ None => {},
+ Some((h,t)) => {
+ *h = 1000;
+ t.reverse();
+ }
+ }
+}
--- /dev/null
+// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Regression test for issue #7740
+
+// pretty-expanded FIXME #23616
+
+pub fn main() {
+ static A: &'static char = &'A';
+}
--- /dev/null
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// This test verifies that casting from the same lifetime on a value
+// to the same lifetime on a trait succeeds. See issue #10766.
+
+// pretty-expanded FIXME #23616
+
+#![allow(dead_code)]
+
+use std::marker;
+
+fn main() {
+ trait T { fn foo(&self) {} }
+
+ fn f<'a, V: T>(v: &'a V) -> &'a T {
+ v as &'a T
+ }
+}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+
+// pretty-expanded FIXME #23616
+
+struct Rec {
+ f: Box<isize>,
+}
+
+struct Outer {
+ f: Inner
+}
+
+struct Inner {
+ g: Innermost
+}
+
+struct Innermost {
+ h: Box<isize>,
+}
+
+fn borrow(_v: &isize) {}
+
+fn box_mut(v: &mut Box<isize>) {
+ borrow(&**v); // OK: &mut -> &imm
+}
+
+fn box_mut_rec(v: &mut Rec) {
+ borrow(&*v.f); // OK: &mut -> &imm
+}
+
+fn box_mut_recs(v: &mut Outer) {
+ borrow(&*v.f.g.h); // OK: &mut -> &imm
+}
+
+fn box_imm(v: &Box<isize>) {
+ borrow(&**v); // OK
+}
+
+fn box_imm_rec(v: &Rec) {
+ borrow(&*v.f); // OK
+}
+
+fn box_imm_recs(v: &Outer) {
+ borrow(&*v.f.g.h); // OK
+}
+
+pub fn main() {
+}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+
+
+use std::cell::Cell;
+
+#[derive(Copy, Clone)]
+enum newtype {
+ newvar(isize)
+}
+
+pub fn main() {
+
+ // Test that borrowck treats enums with a single variant
+ // specially.
+
+ let x = &Cell::new(5);
+ let y = &Cell::new(newtype::newvar(3));
+ let z = match y.get() {
+ newtype::newvar(b) => {
+ x.set(x.get() + 1);
+ x.get() * b
+ }
+ };
+ assert_eq!(z, 18);
+}
--- /dev/null
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// revisions: ast mir
+//[mir]compile-flags: -Z borrowck=mir
+
+// Test file taken from issue 45129 (https://github.com/rust-lang/rust/issues/45129)
+
+struct Foo { x: [usize; 2] }
+
+static mut SFOO: Foo = Foo { x: [23, 32] };
+
+impl Foo {
+ fn x(&mut self) -> &mut usize { &mut self.x[0] }
+}
+
+fn main() {
+ unsafe {
+ let sfoo: *mut Foo = &mut SFOO;
+ let x = (*sfoo).x();
+ (*sfoo).x[1] += 1;
+ *x += 1;
+ }
+}
--- /dev/null
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(nll)]
+#![deny(unused_mut)]
+
+#[derive(Debug)]
+struct A {}
+
+fn init_a() -> A {
+ A {}
+}
+
+#[derive(Debug)]
+struct B<'a> {
+ ed: &'a mut A,
+}
+
+fn init_b<'a>(ed: &'a mut A) -> B<'a> {
+ B { ed }
+}
+
+#[derive(Debug)]
+struct C<'a> {
+ pd: &'a mut B<'a>,
+}
+
+fn init_c<'a>(pd: &'a mut B<'a>) -> C<'a> {
+ C { pd }
+}
+
+#[derive(Debug)]
+struct D<'a> {
+ sd: &'a mut C<'a>,
+}
+
+fn init_d<'a>(sd: &'a mut C<'a>) -> D<'a> {
+ D { sd }
+}
+
+fn main() {
+ let mut a = init_a();
+ let mut b = init_b(&mut a);
+ let mut c = init_c(&mut b);
+
+ let d = init_d(&mut c);
+
+ println!("{:?}", d)
+}
--- /dev/null
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// pretty-expanded FIXME #23616
+
+#![feature(box_syntax)]
+
+struct A { a: isize, b: Box<isize> }
+
+fn field_copy_after_field_borrow() {
+ let mut x = A { a: 1, b: box 2 };
+ let p = &mut x.b;
+ drop(x.a);
+ **p = 3;
+}
+
+fn fu_field_copy_after_field_borrow() {
+ let mut x = A { a: 1, b: box 2 };
+ let p = &mut x.b;
+ let y = A { b: box 3, .. x };
+ drop(y);
+ **p = 4;
+}
+
+fn field_deref_after_field_borrow() {
+ let mut x = A { a: 1, b: box 2 };
+ let p = &mut x.a;
+ drop(*x.b);
+ *p = 3;
+}
+
+fn field_move_after_field_borrow() {
+ let mut x = A { a: 1, b: box 2 };
+ let p = &mut x.a;
+ drop(x.b);
+ *p = 3;
+}
+
+fn fu_field_move_after_field_borrow() {
+ let mut x = A { a: 1, b: box 2 };
+ let p = &mut x.a;
+ let y = A { a: 3, .. x };
+ drop(y);
+ *p = 4;
+}
+
+fn main() {
+ field_copy_after_field_borrow();
+ fu_field_copy_after_field_borrow();
+ field_deref_after_field_borrow();
+ field_move_after_field_borrow();
+ fu_field_move_after_field_borrow();
+}
--- /dev/null
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags: -Z borrowck=mir -Z two-phase-borrows
+
+// This is the "goto example" for why we want two phase borrows.
+
+fn main() {
+ let mut v = vec![0, 1, 2];
+ v.push(v.len());
+ assert_eq!(v, [0, 1, 2, 3]);
+}
--- /dev/null
+// 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.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// revisions: lxl nll
+
+#![cfg_attr(nll, feature(nll))]
+
+use std::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign};
+use std::ops::{BitAndAssign, BitOrAssign, BitXorAssign, ShlAssign, ShrAssign};
+
+struct A(i32);
+
+macro_rules! trivial_binop {
+ ($Trait:ident, $m:ident) => {
+ impl $Trait<i32> for A { fn $m(&mut self, rhs: i32) { self.0 = rhs; } }
+ }
+}
+
+trivial_binop!(AddAssign, add_assign);
+trivial_binop!(SubAssign, sub_assign);
+trivial_binop!(MulAssign, mul_assign);
+trivial_binop!(DivAssign, div_assign);
+trivial_binop!(RemAssign, rem_assign);
+trivial_binop!(BitAndAssign, bitand_assign);
+trivial_binop!(BitOrAssign, bitor_assign);
+trivial_binop!(BitXorAssign, bitxor_assign);
+trivial_binop!(ShlAssign, shl_assign);
+trivial_binop!(ShrAssign, shr_assign);
+
+fn main() {
+ let mut a = A(10);
+ a += a.0;
+ a -= a.0;
+ a *= a.0;
+ a /= a.0;
+ a &= a.0;
+ a |= a.0;
+ a ^= a.0;
+ a <<= a.0;
+ a >>= a.0;
+}
--- /dev/null
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// revisions: lxl nll
+//[lxl]compile-flags: -Z borrowck=mir -Z two-phase-borrows
+
+#![cfg_attr(nll, feature(nll))]
+
+fn main() {
+ let mut a = 0;
+ let mut b = 0;
+ let p = if maybe() {
+ &mut a
+ } else {
+ &mut b
+ };
+ use_(p);
+}
+
+fn maybe() -> bool { false }
+fn use_<T>(_: T) { }