diff options
| author | Basile Desloges <basile.desloges@gmail.com> | 2017-10-21 21:15:28 +0200 |
|---|---|---|
| committer | Basile Desloges <basile.desloges@gmail.com> | 2017-11-13 21:53:10 +0100 |
| commit | cbad2e5720fd251fcd7cbe9648fd7671373a71e7 (patch) | |
| tree | 356da982f58aaab5999e7dd5c3a382dc9ee26670 /src | |
| parent | 37e08a5dcab37aa3120eccadf7e725d0008110ec (diff) | |
| download | rust-cbad2e5720fd251fcd7cbe9648fd7671373a71e7.tar.gz rust-cbad2e5720fd251fcd7cbe9648fd7671373a71e7.zip | |
mir-borrowck: Test for `check_access_permissions()`
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/compile-fail/E0596.rs | 7 | ||||
| -rw-r--r-- | src/test/compile-fail/borrowck/borrowck-access-permissions.rs | 76 |
2 files changed, 82 insertions, 1 deletions
diff --git a/src/test/compile-fail/E0596.rs b/src/test/compile-fail/E0596.rs index 1f1af69d977..0366d4d134a 100644 --- a/src/test/compile-fail/E0596.rs +++ b/src/test/compile-fail/E0596.rs @@ -8,7 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// revisions: ast mir +//[mir]compile-flags: -Z emit-end-regions -Z borrowck-mir + fn main() { let x = 1; - let y = &mut x; //~ ERROR E0596 + let y = &mut x; //[ast]~ ERROR [E0596] + //[mir]~^ ERROR (Ast) [E0596] + //[mir]~| ERROR (Mir) [E0596] } diff --git a/src/test/compile-fail/borrowck/borrowck-access-permissions.rs b/src/test/compile-fail/borrowck/borrowck-access-permissions.rs new file mode 100644 index 00000000000..fbe219102ed --- /dev/null +++ b/src/test/compile-fail/borrowck/borrowck-access-permissions.rs @@ -0,0 +1,76 @@ +// 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 emit-end-regions -Z borrowck-mir + +static static_x : i32 = 1; +static mut static_x_mut : i32 = 1; + +fn main() { + let x = 1; + let mut x_mut = 1; + + { // borrow of local + let _y1 = &mut x; //[ast]~ ERROR [E0596] + //[mir]~^ ERROR (Ast) [E0596] + //[mir]~| ERROR (Mir) [E0596] + let _y2 = &mut x_mut; // No error + } + + { // borrow of static + let _y1 = &mut static_x; //[ast]~ ERROR [E0596] + //[mir]~^ ERROR (Ast) [E0596] + //[mir]~| ERROR (Mir) [E0596] + unsafe { let _y2 = &mut static_x_mut; } // No error + } + + { // borrow of deref to box + let box_x = Box::new(1); + let mut box_x_mut = Box::new(1); + + let _y1 = &mut *box_x; //[ast]~ ERROR [E0596] + //[mir]~^ ERROR (Ast) [E0596] + //[mir]~| ERROR (Mir) [E0596] + let _y2 = &mut *box_x_mut; // No error + } + + { // borrow of deref to reference + let ref_x = &x; + let ref_x_mut = &mut x_mut; + + let _y1 = &mut *ref_x; //[ast]~ ERROR [E0596] + //[mir]~^ ERROR (Ast) [E0596] + //[mir]~| ERROR (Mir) [E0596] + let _y2 = &mut *ref_x_mut; // No error + } + + { // borrow of deref to pointer + let ptr_x : *const _ = &x; + let ptr_mut_x : *mut _ = &mut x_mut; + + unsafe { + let _y1 = &mut *ptr_x; //[ast]~ ERROR [E0596] + //[mir]~^ ERROR (Ast) [E0596] + //[mir]~| ERROR (Mir) [E0596] + let _y2 = &mut *ptr_mut_x; // No error + } + } + + { // borrowing mutably through an immutable reference + struct Foo<'a> { f: &'a mut i32, g: &'a i32 }; + let mut foo = Foo { f: &mut x_mut, g: &x }; + let foo_ref = &foo; + let _y = &mut *foo_ref.f; //[ast]~ ERROR [E0389] + //[mir]~^ ERROR (Ast) [E0389] + //[mir]~| ERROR (Mir) [E0596] + // FIXME: Wrong error in MIR + } +} |
