mir-borrowck: Update tests

This commit is contained in:
Basile Desloges 2017-11-22 18:15:56 +01:00
parent 34f56c44a9
commit 1cd9d74a2d
7 changed files with 39 additions and 16 deletions

View file

@ -15,5 +15,5 @@ static NUM: i32 = 18;
fn main() {
NUM = 20; //[ast]~ ERROR E0594
//[mir]~^ ERROR cannot assign to immutable static item
//[mir]~^ ERROR cannot assign to immutable item `NUM`
}

View file

@ -16,5 +16,5 @@ static foo: isize = 5;
fn main() {
// assigning to various global constants
foo = 6; //[ast]~ ERROR cannot assign to immutable static item
//[mir]~^ ERROR cannot assign to immutable static item `foo`
//[mir]~^ ERROR cannot assign to immutable item `foo`
}

View file

@ -14,6 +14,9 @@
// Also includes tests of the errors reported when the Box in question
// is immutable (#14270).
// revisions: ast mir
//[mir]compile-flags: -Z borrowck=mir
#![feature(box_syntax)]
struct A { a: isize }
@ -23,7 +26,8 @@ fn indirect_write_to_imm_box() {
let mut x: isize = 1;
let y: Box<_> = box &mut x;
let p = &y;
***p = 2; //~ ERROR cannot assign to data in a `&` reference
***p = 2; //[ast]~ ERROR cannot assign to data in a `&` reference
//[mir]~^ ERROR cannot assign to immutable item `***p`
drop(p);
}
@ -32,7 +36,8 @@ fn borrow_in_var_from_var() {
let mut y: Box<_> = box &mut x;
let p = &y;
let q = &***p;
**y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
**y = 2; //[ast]~ ERROR cannot assign to `**y` because it is borrowed
//[mir]~^ ERROR cannot assign to `**y` because it is borrowed
drop(p);
drop(q);
}
@ -42,7 +47,8 @@ fn borrow_in_var_from_var_via_imm_box() {
let y: Box<_> = box &mut x;
let p = &y;
let q = &***p;
**y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
**y = 2; //[ast]~ ERROR cannot assign to `**y` because it is borrowed
//[mir]~^ ERROR cannot assign to `**y` because it is borrowed
drop(p);
drop(q);
}
@ -52,7 +58,8 @@ fn borrow_in_var_from_field() {
let mut y: Box<_> = box &mut x.a;
let p = &y;
let q = &***p;
**y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
**y = 2; //[ast]~ ERROR cannot assign to `**y` because it is borrowed
//[mir]~^ ERROR cannot assign to `**y` because it is borrowed
drop(p);
drop(q);
}
@ -62,7 +69,8 @@ fn borrow_in_var_from_field_via_imm_box() {
let y: Box<_> = box &mut x.a;
let p = &y;
let q = &***p;
**y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
**y = 2; //[ast]~ ERROR cannot assign to `**y` because it is borrowed
//[mir]~^ ERROR cannot assign to `**y` because it is borrowed
drop(p);
drop(q);
}
@ -72,7 +80,8 @@ fn borrow_in_field_from_var() {
let mut y = B { a: box &mut x };
let p = &y.a;
let q = &***p;
**y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
**y.a = 2; //[ast]~ ERROR cannot assign to `**y.a` because it is borrowed
//[mir]~^ ERROR cannot assign to `**y.a` because it is borrowed
drop(p);
drop(q);
}
@ -82,7 +91,8 @@ fn borrow_in_field_from_var_via_imm_box() {
let y = B { a: box &mut x };
let p = &y.a;
let q = &***p;
**y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
**y.a = 2; //[ast]~ ERROR cannot assign to `**y.a` because it is borrowed
//[mir]~^ ERROR cannot assign to `**y.a` because it is borrowed
drop(p);
drop(q);
}
@ -92,7 +102,8 @@ fn borrow_in_field_from_field() {
let mut y = B { a: box &mut x.a };
let p = &y.a;
let q = &***p;
**y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
**y.a = 2; //[ast]~ ERROR cannot assign to `**y.a` because it is borrowed
//[mir]~^ ERROR cannot assign to `**y.a` because it is borrowed
drop(p);
drop(q);
}
@ -102,7 +113,8 @@ fn borrow_in_field_from_field_via_imm_box() {
let y = B { a: box &mut x.a };
let p = &y.a;
let q = &***p;
**y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
**y.a = 2; //[ast]~ ERROR cannot assign to `**y.a` because it is borrowed
//[mir]~^ ERROR cannot assign to `**y.a` because it is borrowed
drop(p);
drop(q);
}

View file

@ -70,5 +70,5 @@ fn main() {
};
s[2] = 20;
//[ast]~^ ERROR cannot assign to immutable indexed content
// FIXME Error for MIR
//[mir]~^^ ERROR cannot assign to immutable item
}

View file

@ -8,6 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-tidy-linelength
// revisions: ast mir
//[mir]compile-flags: -Z borrowck=mir
#![feature(unboxed_closures)]
use std::io::Read;
@ -17,9 +21,11 @@ fn to_fn_once<A,F:FnOnce<A>>(f: F) -> F { f }
fn main() {
let x = 1;
to_fn_once(move|| { x = 2; });
//~^ ERROR: cannot assign to immutable captured outer variable
//[ast]~^ ERROR: cannot assign to immutable captured outer variable
//[mir]~^^ ERROR: cannot assign to immutable item `x`
let s = std::io::stdin();
to_fn_once(move|| { s.read_to_end(&mut Vec::new()); });
//~^ ERROR: cannot borrow immutable captured outer variable
//[ast]~^ ERROR: cannot borrow immutable captured outer variable
//[mir]~^^ ERROR: cannot borrow immutable item `s` as mutable
}

View file

@ -20,6 +20,7 @@ fn main() {
let _iter = TrieMapIterator{node: &a};
_iter.node = & //[ast]~ ERROR cannot assign to immutable field `_iter.node`
//[mir]~^ ERROR cannot assign to immutable field `_iter.node` (Ast)
// FIXME Error for MIR
// MIR doesn't generate an error because the code isn't reachable. This is OK
// because the test is here to check that the compiler doesn't ICE (cf. #5500).
panic!()
}

View file

@ -8,6 +8,9 @@
// 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 that a by-ref `FnMut` closure gets an error when it tries to
// mutate a value.
@ -19,6 +22,7 @@ fn main() {
let mut counter = 0;
call(|| {
counter += 1;
//~^ ERROR cannot assign to data in a captured outer variable in an `Fn` closure
//[ast]~^ ERROR cannot assign to data in a captured outer variable in an `Fn` closure
//[mir]~^^ ERROR cannot assign to immutable item `counter`
});
}