From 92ef0c4bffeae68689f5e3f8173c4ad309518409 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 9 Nov 2018 00:10:19 +0100 Subject: [PATCH] Make test robust to NLL, in sense of ensuring borrows extend to something approximating lexical scope. --- .../ui/borrowck/borrowck-box-insensitivity.rs | 23 +++++++++++-------- .../borrowck-box-insensitivity.stderr | 8 +++---- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/test/ui/borrowck/borrowck-box-insensitivity.rs b/src/test/ui/borrowck/borrowck-box-insensitivity.rs index eabb8d7bca3f..5efc414da773 100644 --- a/src/test/ui/borrowck/borrowck-box-insensitivity.rs +++ b/src/test/ui/borrowck/borrowck-box-insensitivity.rs @@ -63,36 +63,36 @@ fn move_after_borrow() { let _y = a.y; //~^ ERROR cannot move //~| move out of + use_imm(_x); } - fn copy_after_mut_borrow() { let mut a: Box<_> = box A { x: box 0, y: 1 }; let _x = &mut a.x; let _y = a.y; //~ ERROR cannot use + use_mut(_x); } - fn move_after_mut_borrow() { let mut a: Box<_> = box B { x: box 0, y: box 1 }; let _x = &mut a.x; let _y = a.y; //~^ ERROR cannot move //~| move out of + use_mut(_x); } - fn borrow_after_mut_borrow() { let mut a: Box<_> = box A { x: box 0, y: 1 }; let _x = &mut a.x; let _y = &a.y; //~ ERROR cannot borrow //~^ immutable borrow occurs here (via `a.y`) + use_mut(_x); } - fn mut_borrow_after_borrow() { let mut a: Box<_> = box A { x: box 0, y: 1 }; let _x = &a.x; let _y = &mut a.y; //~ ERROR cannot borrow //~^ mutable borrow occurs here (via `a.y`) + use_imm(_x); } - fn copy_after_move_nested() { let a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 }; let _x = a.x.x; @@ -124,38 +124,38 @@ fn move_after_borrow_nested() { let _y = a.y; //~^ ERROR cannot move //~| move out of + use_imm(_x); } - fn copy_after_mut_borrow_nested() { let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 }; let _x = &mut a.x.x; let _y = a.y; //~ ERROR cannot use + use_mut(_x); } - fn move_after_mut_borrow_nested() { let mut a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 }; let _x = &mut a.x.x; let _y = a.y; //~^ ERROR cannot move //~| move out of + use_mut(_x); } - fn borrow_after_mut_borrow_nested() { let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 }; let _x = &mut a.x.x; //~^ mutable borrow occurs here let _y = &a.y; //~ ERROR cannot borrow //~^ immutable borrow occurs here + use_mut(_x); } - fn mut_borrow_after_borrow_nested() { let mut a: Box<_> = box C { x: box A { x: box 0, y: 1 }, y: 2 }; let _x = &a.x.x; //~^ immutable borrow occurs here let _y = &mut a.y; //~ ERROR cannot borrow //~^ mutable borrow occurs here + use_imm(_x); } - #[rustc_error] fn main() { copy_after_move(); @@ -180,3 +180,6 @@ fn main() { borrow_after_mut_borrow_nested(); mut_borrow_after_borrow_nested(); } + +fn use_mut(_: &mut T) { } +fn use_imm(_: &T) { } diff --git a/src/test/ui/borrowck/borrowck-box-insensitivity.stderr b/src/test/ui/borrowck/borrowck-box-insensitivity.stderr index 5bf1fc081786..b84bae748eef 100644 --- a/src/test/ui/borrowck/borrowck-box-insensitivity.stderr +++ b/src/test/ui/borrowck/borrowck-box-insensitivity.stderr @@ -62,7 +62,7 @@ LL | let _x = &mut a.x; | --- mutable borrow occurs here (via `a.x`) LL | let _y = &a.y; //~ ERROR cannot borrow | ^^^ immutable borrow occurs here (via `a.y`) -LL | //~^ immutable borrow occurs here (via `a.y`) +... LL | } | - mutable borrow ends here @@ -73,7 +73,7 @@ LL | let _x = &a.x; | --- immutable borrow occurs here (via `a.x`) LL | let _y = &mut a.y; //~ ERROR cannot borrow | ^^^ mutable borrow occurs here (via `a.y`) -LL | //~^ mutable borrow occurs here (via `a.y`) +... LL | } | - immutable borrow ends here @@ -143,7 +143,7 @@ LL | let _x = &mut a.x.x; LL | //~^ mutable borrow occurs here LL | let _y = &a.y; //~ ERROR cannot borrow | ^^^ immutable borrow occurs here -LL | //~^ immutable borrow occurs here +... LL | } | - mutable borrow ends here @@ -155,7 +155,7 @@ LL | let _x = &a.x.x; LL | //~^ immutable borrow occurs here LL | let _y = &mut a.y; //~ ERROR cannot borrow | ^^^ mutable borrow occurs here -LL | //~^ mutable borrow occurs here +... LL | } | - immutable borrow ends here