Skip to content

Commit ae985de

Browse files
author
Cameron Zwarich
committed
---
yaml --- r: 152520 b: refs/heads/try2 c: 5878b5e h: refs/heads/master v: v3
1 parent b23b675 commit ae985de

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: d7de4e9affac24c6e96ae068954480bfa763908c
8+
refs/heads/try2: 5878b5edb0036312ffee12fc730e69d57df31a66
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
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)