test: Remove all borrow check write guard tests
This commit is contained in:
parent
b6e516859a
commit
179c054631
|
@ -1,5 +0,0 @@
|
|||
fn main() {
|
||||
let mut b = ~3;
|
||||
let _x = &mut *b;
|
||||
let _y = &mut *b; //~ ERROR cannot borrow
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
fn main() {
|
||||
let mut a = ~3;
|
||||
let mut b = &mut a;
|
||||
let _c = &mut *b;
|
||||
let mut d = /*move*/ a; //~ ERROR cannot move out
|
||||
*d += 1;
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
fn main() {
|
||||
let mut b = ~3;
|
||||
let _x = &mut *b;
|
||||
let mut y = /*move*/ b; //~ ERROR cannot move out
|
||||
*y += 1;
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
fn foo(x: &mut int) {
|
||||
let mut a = 3;
|
||||
let mut _y = &mut *x;
|
||||
let _z = &mut *_y;
|
||||
_y = &mut a; //~ ERROR cannot assign
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
// error-pattern:borrowed
|
||||
|
||||
// Issue #6272. Tests that freezing correctly accounts for all the
|
||||
// implicit derefs that can occur and freezes the innermost box. See
|
||||
// the companion test
|
||||
//
|
||||
// run-pass/borrowck-wg-autoderef-and-autoborrowvec-combined-issue-6272.rs
|
||||
//
|
||||
// for a detailed explanation of what is going on here.
|
||||
|
||||
#[feature(managed_boxes)];
|
||||
|
||||
fn main() {
|
||||
let a = @mut [3i];
|
||||
let b = @mut [a];
|
||||
let c = @mut b;
|
||||
|
||||
// this should freeze `a` only
|
||||
let _x: &mut [int] = c[0];
|
||||
|
||||
// hence this should fail
|
||||
a[0] = a[0];
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
// error-pattern:borrowed
|
||||
|
||||
// Test that write guards trigger when there is a write to a field
|
||||
// of a frozen structure.
|
||||
|
||||
#[feature(managed_boxes)];
|
||||
|
||||
struct S {
|
||||
x: int
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = @mut S { x: 3 };
|
||||
let _y: &S = x;
|
||||
let z = x;
|
||||
z.x = 5;
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
// error-pattern:borrowed
|
||||
|
||||
// Test that write guards trigger when there is a write to a directly
|
||||
// frozen @mut box.
|
||||
|
||||
#[feature(managed_boxes)];
|
||||
|
||||
fn main() {
|
||||
let x = @mut 3;
|
||||
let _y: &mut int = x;
|
||||
let z = x;
|
||||
*z = 5;
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
#[feature(managed_boxes)];
|
||||
|
||||
// error-pattern:borrowed
|
||||
|
||||
trait Foo {
|
||||
fn foo(&self, @mut int);
|
||||
}
|
||||
|
||||
impl Foo for int {
|
||||
fn foo(&self, x: @mut int) {
|
||||
*x += *self;
|
||||
}
|
||||
}
|
||||
|
||||
fn it_takes_two(_f: &Foo, _g: &mut Foo) {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = @mut 3_i;
|
||||
let y = x as @mut Foo;
|
||||
let z = y;
|
||||
|
||||
it_takes_two(y, z);
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
#[feature(managed_boxes)];
|
||||
|
||||
// error-pattern:borrowed
|
||||
|
||||
trait Foo {
|
||||
fn foo(&self, @mut int);
|
||||
}
|
||||
|
||||
impl Foo for int {
|
||||
fn foo(&self, x: @mut int) {
|
||||
*x += *self;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = @mut 3_i;
|
||||
let y = x as @mut Foo;
|
||||
|
||||
// The call to `y.foo(...)` should freeze `y` (and thus also `x`,
|
||||
// since `x === y`). It is thus an error when `foo` tries to
|
||||
// mutate `x`.
|
||||
y.foo(x);
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
#[feature(managed_boxes)];
|
||||
|
||||
// error-pattern:borrowed
|
||||
|
||||
// Test that write guards trigger when mut box is frozen
|
||||
// as part of argument coercion.
|
||||
|
||||
fn f(_x: &int, y: @mut int) {
|
||||
*y = 2;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = @mut 3;
|
||||
f(x, x);
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
#[feature(managed_boxes)];
|
||||
|
||||
// error-pattern:borrowed
|
||||
|
||||
// Test that if you imm borrow then mut borrow it fails.
|
||||
|
||||
fn add1(a:@mut int)
|
||||
{
|
||||
add2(a); // already frozen
|
||||
}
|
||||
|
||||
fn add2(_:&mut int)
|
||||
{
|
||||
}
|
||||
|
||||
pub fn main()
|
||||
{
|
||||
let a = @mut 3;
|
||||
let _b = &*a; // freezes a
|
||||
add1(a);
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
#[feature(managed_boxes)];
|
||||
|
||||
// error-pattern:borrowed
|
||||
|
||||
// Test that if you mut borrow then imm borrow it fails.
|
||||
|
||||
fn add1(a:@mut int)
|
||||
{
|
||||
add2(a); // already frozen
|
||||
}
|
||||
|
||||
fn add2(_:&int)
|
||||
{
|
||||
}
|
||||
|
||||
pub fn main()
|
||||
{
|
||||
let a = @mut 3;
|
||||
let _b = &mut *a; // freezes a
|
||||
add1(a);
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
// error-pattern:borrowed
|
||||
|
||||
// Test that write guards trigger when there is a coercion to
|
||||
// a slice on the receiver of a method.
|
||||
|
||||
#[feature(managed_boxes)];
|
||||
|
||||
trait MyMutSlice {
|
||||
fn my_mut_slice(self) -> Self;
|
||||
}
|
||||
|
||||
impl<'a, T> MyMutSlice for &'a mut [T] {
|
||||
fn my_mut_slice(self) -> &'a mut [T] {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
trait MySlice {
|
||||
fn my_slice(self) -> Self;
|
||||
}
|
||||
|
||||
impl<'a, T> MySlice for &'a [T] {
|
||||
fn my_slice(self) -> &'a [T] {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
fn add(x:&mut [int], y:&[int])
|
||||
{
|
||||
x[0] = x[0] + y[0];
|
||||
}
|
||||
|
||||
pub fn main()
|
||||
{
|
||||
let z = @mut [1,2,3];
|
||||
let z2 = z;
|
||||
add(z.my_mut_slice(), z2.my_slice());
|
||||
println!("{}", z[0]);
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
// error-pattern:borrowed
|
||||
|
||||
// Test that write guards trigger when arguments are coerced to slices.
|
||||
|
||||
#[feature(managed_boxes)];
|
||||
|
||||
fn add(x:&mut [int], y:&[int])
|
||||
{
|
||||
x[0] = x[0] + y[0];
|
||||
}
|
||||
|
||||
pub fn main()
|
||||
{
|
||||
let z = @mut [1,2,3];
|
||||
let z2 = z;
|
||||
add(z, z2);
|
||||
println!("{}", z[0]);
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
// error-pattern:borrowed
|
||||
|
||||
// Test that write guards trigger when we are indexing into
|
||||
// an @mut vector.
|
||||
|
||||
#[feature(managed_boxes)];
|
||||
|
||||
fn add(x:&mut int, y:&int)
|
||||
{
|
||||
*x = *x + *y;
|
||||
}
|
||||
|
||||
pub fn main()
|
||||
{
|
||||
let z = @mut [1,2,3];
|
||||
let z2 = z;
|
||||
add(&mut z[0], &z2[0]);
|
||||
println!("{}", z[0]);
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
// error-pattern:borrowed
|
||||
|
||||
// Test that arguments trigger when there are *two mutable* borrows
|
||||
// of indices.
|
||||
|
||||
#[feature(managed_boxes)];
|
||||
|
||||
fn add(x:&mut int, y:&mut int)
|
||||
{
|
||||
*x = *x + *y;
|
||||
}
|
||||
|
||||
pub fn main()
|
||||
{
|
||||
let z = @mut [1,2,3];
|
||||
let z2 = z;
|
||||
add(&mut z[0], &mut z2[0]);
|
||||
println!("{}", z[0]);
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
// Issue #6272. Tests that freezing correctly accounts for all the
|
||||
// implicit derefs that can occur.
|
||||
//
|
||||
// In this particular case, the expression:
|
||||
//
|
||||
// let x: &mut [int] = c[0];
|
||||
//
|
||||
// is seen by borrowck as this sequence of derefs
|
||||
// and pointer offsets:
|
||||
//
|
||||
// &*((**c)[0])
|
||||
//
|
||||
// or, written using `x.*` for `*x` (so that everything
|
||||
// is a postfix operation):
|
||||
//
|
||||
// &c.*.*.[0].*
|
||||
// ^ ^
|
||||
// | |
|
||||
// b a
|
||||
//
|
||||
// Here I also indicated where the evaluation yields the boxes `a` and
|
||||
// `b`. It is important then that we only freeze the innermost box
|
||||
// (`a`), and not the other ones (`b`, `c`).
|
||||
//
|
||||
// Also see the companion test:
|
||||
//
|
||||
// run-fail/borrowck-wg-autoderef-and-autoborrowvec-combined-fail-issue-6272.rs
|
||||
|
||||
#[feature(managed_boxes)];
|
||||
|
||||
pub fn main() {
|
||||
let a = @mut 3i;
|
||||
let b = @mut [a];
|
||||
let c = @mut [3];
|
||||
|
||||
// this should freeze `a` only
|
||||
let _x: &mut int = a;
|
||||
|
||||
// hence these writes should not fail:
|
||||
b[0] = b[0];
|
||||
c[0] = c[0];
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
struct Cat;
|
||||
|
||||
fn bar(_: &Cat) {
|
||||
}
|
||||
|
||||
fn foo(cat: &mut Cat) {
|
||||
bar(&*cat);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let mut mimi = ~Cat;
|
||||
foo(mimi);
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
struct Wizard {
|
||||
spells: ~[&'static str]
|
||||
}
|
||||
|
||||
impl Wizard {
|
||||
pub fn cast(&mut self) {
|
||||
for &spell in self.spells.iter() {
|
||||
println(spell);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let mut harry = Wizard {
|
||||
spells: ~[ "expelliarmus", "expecto patronum", "incendio" ]
|
||||
};
|
||||
harry.cast();
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
fn g(x: &Option<int>) {
|
||||
println(x.unwrap().to_str());
|
||||
}
|
||||
|
||||
fn f(x: &mut Option<int>) {
|
||||
g(&*x);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let mut x = ~Some(3);
|
||||
f(x);
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
#[feature(managed_boxes)];
|
||||
|
||||
fn f(x: &int) {
|
||||
println(x.to_str());
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let x = @mut 3;
|
||||
f(x);
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
// Test that we can borrow the same @mut box twice, so long as both are imm.
|
||||
|
||||
#[feature(managed_boxes)];
|
||||
|
||||
fn add(x:&int, y:&int)
|
||||
{
|
||||
*x + *y;
|
||||
}
|
||||
|
||||
pub fn main()
|
||||
{
|
||||
let z = @mut [1,2,3];
|
||||
let z2 = z;
|
||||
add(&z[0], &z2[0]);
|
||||
println!("{}", z[0]);
|
||||
}
|
Loading…
Reference in New Issue