]> git.lizzy.rs Git - rust.git/commitdiff
Migrated `src/test/run-pass/borrowck` to `src/test/ui/run-pass`.
authorFelix S. Klock II <pnkfelix@pnkfx.org>
Mon, 3 Sep 2018 09:06:00 +0000 (11:06 +0200)
committerFelix S. Klock II <pnkfelix@pnkfx.org>
Thu, 6 Sep 2018 11:29:24 +0000 (13:29 +0200)
Just shuffling files here; the needed updates to content come later.

60 files changed:
src/test/run-pass/borrowck/borrowck-assign-to-subfield.rs [deleted file]
src/test/run-pass/borrowck/borrowck-assignment-to-static-mut.rs [deleted file]
src/test/run-pass/borrowck/borrowck-binding-mutbl.rs [deleted file]
src/test/run-pass/borrowck/borrowck-borrow-from-expr-block.rs [deleted file]
src/test/run-pass/borrowck/borrowck-borrow-of-mut-base-ptr-safe.rs [deleted file]
src/test/run-pass/borrowck/borrowck-closures-two-imm.rs [deleted file]
src/test/run-pass/borrowck/borrowck-field-sensitivity.rs [deleted file]
src/test/run-pass/borrowck/borrowck-fixed-length-vecs.rs [deleted file]
src/test/run-pass/borrowck/borrowck-freeze-frozen-mut.rs [deleted file]
src/test/run-pass/borrowck/borrowck-lend-args.rs [deleted file]
src/test/run-pass/borrowck/borrowck-macro-interaction-issue-6304.rs [deleted file]
src/test/run-pass/borrowck/borrowck-move-by-capture-ok.rs [deleted file]
src/test/run-pass/borrowck/borrowck-multiple-borrows-interior-boxes.rs [deleted file]
src/test/run-pass/borrowck/borrowck-mut-uniq.rs [deleted file]
src/test/run-pass/borrowck/borrowck-mut-vec-as-imm-slice.rs [deleted file]
src/test/run-pass/borrowck/borrowck-pat-enum.rs [deleted file]
src/test/run-pass/borrowck/borrowck-pat-reassign-no-binding.rs [deleted file]
src/test/run-pass/borrowck/borrowck-rvalues-mutable.rs [deleted file]
src/test/run-pass/borrowck/borrowck-scope-of-deref-issue-4666.rs [deleted file]
src/test/run-pass/borrowck/borrowck-slice-pattern-element-loan.rs [deleted file]
src/test/run-pass/borrowck/borrowck-static-item-in-fn.rs [deleted file]
src/test/run-pass/borrowck/borrowck-trait-lifetime.rs [deleted file]
src/test/run-pass/borrowck/borrowck-uniq-via-ref.rs [deleted file]
src/test/run-pass/borrowck/borrowck-univariant-enum.rs [deleted file]
src/test/run-pass/borrowck/borrowck-unsafe-static-mutable-borrows.rs [deleted file]
src/test/run-pass/borrowck/borrowck-unused-mut-locals.rs [deleted file]
src/test/run-pass/borrowck/borrowck-use-mut-borrow.rs [deleted file]
src/test/run-pass/borrowck/two-phase-baseline.rs [deleted file]
src/test/run-pass/borrowck/two-phase-bin-ops.rs [deleted file]
src/test/run-pass/borrowck/two-phase-control-flow-split-before-activation.rs [deleted file]
src/test/ui/run-pass/borrowck/borrowck-assign-to-subfield.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-assignment-to-static-mut.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-binding-mutbl.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-borrow-from-expr-block.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-borrow-of-mut-base-ptr-safe.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-closures-two-imm.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-field-sensitivity.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-fixed-length-vecs.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-freeze-frozen-mut.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-lend-args.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-macro-interaction-issue-6304.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-move-by-capture-ok.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-multiple-borrows-interior-boxes.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-mut-uniq.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-mut-vec-as-imm-slice.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-pat-enum.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-pat-reassign-no-binding.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-rvalues-mutable.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-scope-of-deref-issue-4666.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-slice-pattern-element-loan.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-static-item-in-fn.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-trait-lifetime.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-uniq-via-ref.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-univariant-enum.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-unsafe-static-mutable-borrows.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-unused-mut-locals.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/borrowck-use-mut-borrow.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/two-phase-baseline.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/two-phase-bin-ops.rs [new file with mode: 0644]
src/test/ui/run-pass/borrowck/two-phase-control-flow-split-before-activation.rs [new file with mode: 0644]

diff --git a/src/test/run-pass/borrowck/borrowck-assign-to-subfield.rs b/src/test/run-pass/borrowck/borrowck-assign-to-subfield.rs
deleted file mode 100644 (file)
index ee74a05..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-// 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;
-}
diff --git a/src/test/run-pass/borrowck/borrowck-assignment-to-static-mut.rs b/src/test/run-pass/borrowck/borrowck-assignment-to-static-mut.rs
deleted file mode 100644 (file)
index 302a7b9..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-// 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() {}
diff --git a/src/test/run-pass/borrowck/borrowck-binding-mutbl.rs b/src/test/run-pass/borrowck/borrowck-binding-mutbl.rs
deleted file mode 100644 (file)
index b6c2a3a..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-// 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);
-      }
-    }
-}
diff --git a/src/test/run-pass/borrowck/borrowck-borrow-from-expr-block.rs b/src/test/run-pass/borrowck/borrowck-borrow-from-expr-block.rs
deleted file mode 100644 (file)
index 1d72305..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-// 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);
-}
diff --git a/src/test/run-pass/borrowck/borrowck-borrow-of-mut-base-ptr-safe.rs b/src/test/run-pass/borrowck/borrowck-borrow-of-mut-base-ptr-safe.rs
deleted file mode 100644 (file)
index b716a1a..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-// 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() {
-}
diff --git a/src/test/run-pass/borrowck/borrowck-closures-two-imm.rs b/src/test/run-pass/borrowck/borrowck-closures-two-imm.rs
deleted file mode 100644 (file)
index 5b15c8f..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-// 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);
-}
diff --git a/src/test/run-pass/borrowck/borrowck-field-sensitivity.rs b/src/test/run-pass/borrowck/borrowck-field-sensitivity.rs
deleted file mode 100644 (file)
index a465c9c..0000000
+++ /dev/null
@@ -1,273 +0,0 @@
-// 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();
-}
diff --git a/src/test/run-pass/borrowck/borrowck-fixed-length-vecs.rs b/src/test/run-pass/borrowck/borrowck-fixed-length-vecs.rs
deleted file mode 100644 (file)
index 0e33351..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-// 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);
-}
diff --git a/src/test/run-pass/borrowck/borrowck-freeze-frozen-mut.rs b/src/test/run-pass/borrowck/borrowck-freeze-frozen-mut.rs
deleted file mode 100644 (file)
index 380bd39..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-// 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);
-}
diff --git a/src/test/run-pass/borrowck/borrowck-lend-args.rs b/src/test/run-pass/borrowck/borrowck-lend-args.rs
deleted file mode 100644 (file)
index f1f0274..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-// 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() {
-}
diff --git a/src/test/run-pass/borrowck/borrowck-macro-interaction-issue-6304.rs b/src/test/run-pass/borrowck/borrowck-macro-interaction-issue-6304.rs
deleted file mode 100644 (file)
index fb30c85..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-// 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() { }
diff --git a/src/test/run-pass/borrowck/borrowck-move-by-capture-ok.rs b/src/test/run-pass/borrowck/borrowck-move-by-capture-ok.rs
deleted file mode 100644 (file)
index c364586..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-// 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);
-}
diff --git a/src/test/run-pass/borrowck/borrowck-multiple-borrows-interior-boxes.rs b/src/test/run-pass/borrowck/borrowck-multiple-borrows-interior-boxes.rs
deleted file mode 100644 (file)
index f57a7bd..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-// 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() {
-}
diff --git a/src/test/run-pass/borrowck/borrowck-mut-uniq.rs b/src/test/run-pass/borrowck/borrowck-mut-uniq.rs
deleted file mode 100644 (file)
index ec868bc..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-// 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);
-}
diff --git a/src/test/run-pass/borrowck/borrowck-mut-vec-as-imm-slice.rs b/src/test/run-pass/borrowck/borrowck-mut-vec-as-imm-slice.rs
deleted file mode 100644 (file)
index 4699f37..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-// 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);
-}
diff --git a/src/test/run-pass/borrowck/borrowck-pat-enum.rs b/src/test/run-pass/borrowck/borrowck-pat-enum.rs
deleted file mode 100644 (file)
index 8de45e4..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-// 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() {
-}
diff --git a/src/test/run-pass/borrowck/borrowck-pat-reassign-no-binding.rs b/src/test/run-pass/borrowck/borrowck-pat-reassign-no-binding.rs
deleted file mode 100644 (file)
index e0a5db6..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-// 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));
-}
diff --git a/src/test/run-pass/borrowck/borrowck-rvalues-mutable.rs b/src/test/run-pass/borrowck/borrowck-rvalues-mutable.rs
deleted file mode 100644 (file)
index 93cb0cb..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-// 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);
-}
diff --git a/src/test/run-pass/borrowck/borrowck-scope-of-deref-issue-4666.rs b/src/test/run-pass/borrowck/borrowck-scope-of-deref-issue-4666.rs
deleted file mode 100644 (file)
index 59a5fea..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-// 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();
-}
diff --git a/src/test/run-pass/borrowck/borrowck-slice-pattern-element-loan.rs b/src/test/run-pass/borrowck/borrowck-slice-pattern-element-loan.rs
deleted file mode 100644 (file)
index 48d1610..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-// 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();
-        }
-    }
-}
diff --git a/src/test/run-pass/borrowck/borrowck-static-item-in-fn.rs b/src/test/run-pass/borrowck/borrowck-static-item-in-fn.rs
deleted file mode 100644 (file)
index d51d0b1..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-// 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';
-}
diff --git a/src/test/run-pass/borrowck/borrowck-trait-lifetime.rs b/src/test/run-pass/borrowck/borrowck-trait-lifetime.rs
deleted file mode 100644 (file)
index 0bfa8f4..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-// 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
-    }
-}
diff --git a/src/test/run-pass/borrowck/borrowck-uniq-via-ref.rs b/src/test/run-pass/borrowck/borrowck-uniq-via-ref.rs
deleted file mode 100644 (file)
index 0ec8759..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-// 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() {
-}
diff --git a/src/test/run-pass/borrowck/borrowck-univariant-enum.rs b/src/test/run-pass/borrowck/borrowck-univariant-enum.rs
deleted file mode 100644 (file)
index 2e8ddb0..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-// 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);
-}
diff --git a/src/test/run-pass/borrowck/borrowck-unsafe-static-mutable-borrows.rs b/src/test/run-pass/borrowck/borrowck-unsafe-static-mutable-borrows.rs
deleted file mode 100644 (file)
index de411d3..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-// 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;
-    }
-}
diff --git a/src/test/run-pass/borrowck/borrowck-unused-mut-locals.rs b/src/test/run-pass/borrowck/borrowck-unused-mut-locals.rs
deleted file mode 100644 (file)
index 7f1b6ed..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-// 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)
-}
diff --git a/src/test/run-pass/borrowck/borrowck-use-mut-borrow.rs b/src/test/run-pass/borrowck/borrowck-use-mut-borrow.rs
deleted file mode 100644 (file)
index 8c94df6..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-// 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();
-}
diff --git a/src/test/run-pass/borrowck/two-phase-baseline.rs b/src/test/run-pass/borrowck/two-phase-baseline.rs
deleted file mode 100644 (file)
index ca15591..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-// 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]);
-}
diff --git a/src/test/run-pass/borrowck/two-phase-bin-ops.rs b/src/test/run-pass/borrowck/two-phase-bin-ops.rs
deleted file mode 100644 (file)
index 1b2529d..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-// 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;
-}
diff --git a/src/test/run-pass/borrowck/two-phase-control-flow-split-before-activation.rs b/src/test/run-pass/borrowck/two-phase-control-flow-split-before-activation.rs
deleted file mode 100644 (file)
index 35a5422..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-// 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) { }
diff --git a/src/test/ui/run-pass/borrowck/borrowck-assign-to-subfield.rs b/src/test/ui/run-pass/borrowck/borrowck-assign-to-subfield.rs
new file mode 100644 (file)
index 0000000..ee74a05
--- /dev/null
@@ -0,0 +1,32 @@
+// 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;
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-assignment-to-static-mut.rs b/src/test/ui/run-pass/borrowck/borrowck-assignment-to-static-mut.rs
new file mode 100644 (file)
index 0000000..302a7b9
--- /dev/null
@@ -0,0 +1,22 @@
+// 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() {}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-binding-mutbl.rs b/src/test/ui/run-pass/borrowck/borrowck-binding-mutbl.rs
new file mode 100644 (file)
index 0000000..b6c2a3a
--- /dev/null
@@ -0,0 +1,24 @@
+// 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);
+      }
+    }
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-borrow-from-expr-block.rs b/src/test/ui/run-pass/borrowck/borrowck-borrow-from-expr-block.rs
new file mode 100644 (file)
index 0000000..1d72305
--- /dev/null
@@ -0,0 +1,27 @@
+// 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);
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-borrow-of-mut-base-ptr-safe.rs b/src/test/ui/run-pass/borrowck/borrowck-borrow-of-mut-base-ptr-safe.rs
new file mode 100644 (file)
index 0000000..b716a1a
--- /dev/null
@@ -0,0 +1,27 @@
+// 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() {
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-closures-two-imm.rs b/src/test/ui/run-pass/borrowck/borrowck-closures-two-imm.rs
new file mode 100644 (file)
index 0000000..5b15c8f
--- /dev/null
@@ -0,0 +1,50 @@
+// 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);
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-field-sensitivity.rs b/src/test/ui/run-pass/borrowck/borrowck-field-sensitivity.rs
new file mode 100644 (file)
index 0000000..a465c9c
--- /dev/null
@@ -0,0 +1,273 @@
+// 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();
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-fixed-length-vecs.rs b/src/test/ui/run-pass/borrowck/borrowck-fixed-length-vecs.rs
new file mode 100644 (file)
index 0000000..0e33351
--- /dev/null
@@ -0,0 +1,16 @@
+// 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);
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-freeze-frozen-mut.rs b/src/test/ui/run-pass/borrowck/borrowck-freeze-frozen-mut.rs
new file mode 100644 (file)
index 0000000..380bd39
--- /dev/null
@@ -0,0 +1,37 @@
+// 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);
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-lend-args.rs b/src/test/ui/run-pass/borrowck/borrowck-lend-args.rs
new file mode 100644 (file)
index 0000000..f1f0274
--- /dev/null
@@ -0,0 +1,29 @@
+// 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() {
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-macro-interaction-issue-6304.rs b/src/test/ui/run-pass/borrowck/borrowck-macro-interaction-issue-6304.rs
new file mode 100644 (file)
index 0000000..fb30c85
--- /dev/null
@@ -0,0 +1,43 @@
+// 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() { }
diff --git a/src/test/ui/run-pass/borrowck/borrowck-move-by-capture-ok.rs b/src/test/ui/run-pass/borrowck/borrowck-move-by-capture-ok.rs
new file mode 100644 (file)
index 0000000..c364586
--- /dev/null
@@ -0,0 +1,17 @@
+// 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);
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-multiple-borrows-interior-boxes.rs b/src/test/ui/run-pass/borrowck/borrowck-multiple-borrows-interior-boxes.rs
new file mode 100644 (file)
index 0000000..f57a7bd
--- /dev/null
@@ -0,0 +1,29 @@
+// 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() {
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-mut-uniq.rs b/src/test/ui/run-pass/borrowck/borrowck-mut-uniq.rs
new file mode 100644 (file)
index 0000000..ec868bc
--- /dev/null
@@ -0,0 +1,42 @@
+// 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);
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-mut-vec-as-imm-slice.rs b/src/test/ui/run-pass/borrowck/borrowck-mut-vec-as-imm-slice.rs
new file mode 100644 (file)
index 0000000..4699f37
--- /dev/null
@@ -0,0 +1,25 @@
+// 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);
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-pat-enum.rs b/src/test/ui/run-pass/borrowck/borrowck-pat-enum.rs
new file mode 100644 (file)
index 0000000..8de45e4
--- /dev/null
@@ -0,0 +1,47 @@
+// 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() {
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-pat-reassign-no-binding.rs b/src/test/ui/run-pass/borrowck/borrowck-pat-reassign-no-binding.rs
new file mode 100644 (file)
index 0000000..e0a5db6
--- /dev/null
@@ -0,0 +1,23 @@
+// 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));
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-rvalues-mutable.rs b/src/test/ui/run-pass/borrowck/borrowck-rvalues-mutable.rs
new file mode 100644 (file)
index 0000000..93cb0cb
--- /dev/null
@@ -0,0 +1,43 @@
+// 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);
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-scope-of-deref-issue-4666.rs b/src/test/ui/run-pass/borrowck/borrowck-scope-of-deref-issue-4666.rs
new file mode 100644 (file)
index 0000000..59a5fea
--- /dev/null
@@ -0,0 +1,51 @@
+// 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();
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-slice-pattern-element-loan.rs b/src/test/ui/run-pass/borrowck/borrowck-slice-pattern-element-loan.rs
new file mode 100644 (file)
index 0000000..48d1610
--- /dev/null
@@ -0,0 +1,33 @@
+// 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();
+        }
+    }
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-static-item-in-fn.rs b/src/test/ui/run-pass/borrowck/borrowck-static-item-in-fn.rs
new file mode 100644 (file)
index 0000000..d51d0b1
--- /dev/null
@@ -0,0 +1,17 @@
+// 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';
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-trait-lifetime.rs b/src/test/ui/run-pass/borrowck/borrowck-trait-lifetime.rs
new file mode 100644 (file)
index 0000000..0bfa8f4
--- /dev/null
@@ -0,0 +1,26 @@
+// 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
+    }
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-uniq-via-ref.rs b/src/test/ui/run-pass/borrowck/borrowck-uniq-via-ref.rs
new file mode 100644 (file)
index 0000000..0ec8759
--- /dev/null
@@ -0,0 +1,57 @@
+// 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() {
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-univariant-enum.rs b/src/test/ui/run-pass/borrowck/borrowck-univariant-enum.rs
new file mode 100644 (file)
index 0000000..2e8ddb0
--- /dev/null
@@ -0,0 +1,34 @@
+// 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);
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-unsafe-static-mutable-borrows.rs b/src/test/ui/run-pass/borrowck/borrowck-unsafe-static-mutable-borrows.rs
new file mode 100644 (file)
index 0000000..de411d3
--- /dev/null
@@ -0,0 +1,31 @@
+// 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;
+    }
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-unused-mut-locals.rs b/src/test/ui/run-pass/borrowck/borrowck-unused-mut-locals.rs
new file mode 100644 (file)
index 0000000..7f1b6ed
--- /dev/null
@@ -0,0 +1,56 @@
+// 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)
+}
diff --git a/src/test/ui/run-pass/borrowck/borrowck-use-mut-borrow.rs b/src/test/ui/run-pass/borrowck/borrowck-use-mut-borrow.rs
new file mode 100644 (file)
index 0000000..8c94df6
--- /dev/null
@@ -0,0 +1,60 @@
+// 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();
+}
diff --git a/src/test/ui/run-pass/borrowck/two-phase-baseline.rs b/src/test/ui/run-pass/borrowck/two-phase-baseline.rs
new file mode 100644 (file)
index 0000000..ca15591
--- /dev/null
@@ -0,0 +1,19 @@
+// 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]);
+}
diff --git a/src/test/ui/run-pass/borrowck/two-phase-bin-ops.rs b/src/test/ui/run-pass/borrowck/two-phase-bin-ops.rs
new file mode 100644 (file)
index 0000000..1b2529d
--- /dev/null
@@ -0,0 +1,48 @@
+// 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;
+}
diff --git a/src/test/ui/run-pass/borrowck/two-phase-control-flow-split-before-activation.rs b/src/test/ui/run-pass/borrowck/two-phase-control-flow-split-before-activation.rs
new file mode 100644 (file)
index 0000000..35a5422
--- /dev/null
@@ -0,0 +1,28 @@
+// 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) { }