Skip to content

Commit 314aff4

Browse files
committed
---
yaml --- r: 60082 b: refs/heads/master c: 5a1afaf h: refs/heads/master v: v3
1 parent b0f740a commit 314aff4

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 3c4b32cdbe7304e6bd033ff6bb4b23a1f18e8af0
2+
refs/heads/master: 5a1afaf5810048e8c0c6e5160cf0bf8c323113cf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2d28d645422c1617be58c8ca7ad9a457264ca850
55
refs/heads/try: c50a9d5b664478e533ba1d1d353213d70c8ad589
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2012-2013 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+
// Tests that the scope of the pointer returned from `get()` is
12+
// limited to the deref operation itself, and does not infect the
13+
// block as a whole.
14+
15+
struct Box {
16+
x: uint
17+
}
18+
19+
impl Box {
20+
fn get<'a>(&'a self) -> &'a uint {
21+
&self.x
22+
}
23+
fn set(&mut self, x: uint) {
24+
self.x = x;
25+
}
26+
}
27+
28+
fn fun1() {
29+
// in the past, borrow checker behaved differently when
30+
// init and decl of `v` were distinct
31+
let v;
32+
let mut box = Box {x: 0};
33+
box.set(22);
34+
v = *box.get();
35+
box.set(v+1);
36+
assert_eq!(23, *box.get());
37+
}
38+
39+
fn fun2() {
40+
let mut box = Box {x: 0};
41+
box.set(22);
42+
let v = *box.get();
43+
box.set(v+1);
44+
assert_eq!(23, *box.get());
45+
}
46+
47+
pub fn main() {
48+
fun1();
49+
fun2();
50+
}

0 commit comments

Comments
 (0)