Skip to content

Commit 6edd33e

Browse files
author
Cameron Zwarich
committed
---
yaml --- r: 118453 b: refs/heads/try c: 5878b5e h: refs/heads/master i: 118451: c7a791c v: v3
1 parent eb90e19 commit 6edd33e

File tree

3 files changed

+151
-1
lines changed

3 files changed

+151
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 3770c42a4959cbabc73da52abc7e3db96657974e
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: d6736a1440d42f6af967a8a20ab8d73522112b72
5-
refs/heads/try: d7de4e9affac24c6e96ae068954480bfa763908c
5+
refs/heads/try: 5878b5edb0036312ffee12fc730e69d57df31a66
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct A { a: int, b: int }
12+
struct B { a: int, b: Box<int> }
13+
14+
fn var_copy_after_var_borrow() {
15+
let mut x: int = 1;
16+
let p = &mut x;
17+
drop(x); //~ ERROR cannot use `x` because it was mutably borrowed
18+
*p = 2;
19+
}
20+
21+
fn var_copy_after_field_borrow() {
22+
let mut x = A { a: 1, b: 2 };
23+
let p = &mut x.a;
24+
drop(x); //~ ERROR cannot use `x` because it was mutably borrowed
25+
*p = 3;
26+
}
27+
28+
fn field_copy_after_var_borrow() {
29+
let mut x = A { a: 1, b: 2 };
30+
let p = &mut x;
31+
drop(x.a); //~ ERROR cannot use `x.a` because it was mutably borrowed
32+
p.a = 3;
33+
}
34+
35+
fn field_copy_after_field_borrow() {
36+
let mut x = A { a: 1, b: 2 };
37+
let p = &mut x.a;
38+
drop(x.a); //~ ERROR cannot use `x.a` because it was mutably borrowed
39+
*p = 3;
40+
}
41+
42+
fn fu_field_copy_after_var_borrow() {
43+
let mut x = A { a: 1, b: 2 };
44+
let p = &mut x;
45+
let y = A { b: 3, .. x }; //~ ERROR cannot use `x.a` because it was mutably borrowed
46+
drop(y);
47+
p.a = 4;
48+
}
49+
50+
fn fu_field_copy_after_field_borrow() {
51+
let mut x = A { a: 1, b: 2 };
52+
let p = &mut x.a;
53+
let y = A { b: 3, .. x }; //~ ERROR cannot use `x.a` because it was mutably borrowed
54+
drop(y);
55+
*p = 4;
56+
}
57+
58+
fn var_deref_after_var_borrow() {
59+
let mut x: Box<int> = box 1;
60+
let p = &mut x;
61+
drop(*x); //~ ERROR cannot use `*x` because it was mutably borrowed
62+
**p = 2;
63+
}
64+
65+
fn field_deref_after_var_borrow() {
66+
let mut x = B { a: 1, b: box 2 };
67+
let p = &mut x;
68+
drop(*x.b); //~ ERROR cannot use `*x.b` because it was mutably borrowed
69+
p.a = 3;
70+
}
71+
72+
fn field_deref_after_field_borrow() {
73+
let mut x = B { a: 1, b: box 2 };
74+
let p = &mut x.b;
75+
drop(*x.b); //~ ERROR cannot use `*x.b` because it was mutably borrowed
76+
**p = 3;
77+
}
78+
79+
fn main() {
80+
var_copy_after_var_borrow();
81+
var_copy_after_field_borrow();
82+
83+
field_copy_after_var_borrow();
84+
field_copy_after_field_borrow();
85+
86+
fu_field_copy_after_var_borrow();
87+
fu_field_copy_after_field_borrow();
88+
89+
var_deref_after_var_borrow();
90+
field_deref_after_var_borrow();
91+
field_deref_after_field_borrow();
92+
}
93+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct A { a: int, b: Box<int> }
12+
13+
fn field_copy_after_field_borrow() {
14+
let mut x = A { a: 1, b: box 2 };
15+
let p = &mut x.b;
16+
drop(x.a);
17+
**p = 3;
18+
}
19+
20+
fn fu_field_copy_after_field_borrow() {
21+
let mut x = A { a: 1, b: box 2 };
22+
let p = &mut x.b;
23+
let y = A { b: box 3, .. x };
24+
drop(y);
25+
**p = 4;
26+
}
27+
28+
fn field_deref_after_field_borrow() {
29+
let mut x = A { a: 1, b: box 2 };
30+
let p = &mut x.a;
31+
drop(*x.b);
32+
*p = 3;
33+
}
34+
35+
fn field_move_after_field_borrow() {
36+
let mut x = A { a: 1, b: box 2 };
37+
let p = &mut x.a;
38+
drop(x.b);
39+
*p = 3;
40+
}
41+
42+
fn fu_field_move_after_field_borrow() {
43+
let mut x = A { a: 1, b: box 2 };
44+
let p = &mut x.a;
45+
let y = A { a: 3, .. x };
46+
drop(y);
47+
*p = 4;
48+
}
49+
50+
fn main() {
51+
field_copy_after_field_borrow();
52+
fu_field_copy_after_field_borrow();
53+
field_deref_after_field_borrow();
54+
field_move_after_field_borrow();
55+
fu_field_move_after_field_borrow();
56+
}
57+

0 commit comments

Comments
 (0)