Skip to content

Commit 617e914

Browse files
committed
---
yaml --- r: 15831 b: refs/heads/try c: 63210ec h: refs/heads/master i: 15829: 90d67b2 15827: 1429139 15823: 5deb217 v: v3
1 parent d736f4c commit 617e914

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 5c8069d817d5be3dc577dce6ab59ebfd89d19843
5+
refs/heads/try: 63210ecddb74fb601a17314c6866685d74fa89dc
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/rustc/middle/borrowck.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,17 +1481,17 @@ impl preserve_methods for preserve_ctxt {
14811481
// Unsafe pointers are the user's problem
14821482
ok(())
14831483
}
1484-
cat_deref(_, derefs, gc_ptr) {
1484+
cat_deref(base, derefs, gc_ptr) {
14851485
// GC'd pointers of type @MT: always stable because we can inc
14861486
// the ref count or keep a GC root as necessary. We need to
14871487
// insert this id into the root_map, however.
14881488
alt self.opt_scope_id {
14891489
some(scope_id) {
14901490
#debug["Inserting root map entry for %s: \
14911491
node %d:%u -> scope %d",
1492-
self.bccx.cmt_to_repr(cmt), cmt.id,
1492+
self.bccx.cmt_to_repr(cmt), base.id,
14931493
derefs, scope_id];
1494-
let rk = {id: cmt.id, derefs: derefs};
1494+
let rk = {id: base.id, derefs: derefs};
14951495
self.bccx.root_map.insert(rk, scope_id);
14961496
ok(())
14971497
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
3+
Tests that borrowing always produces a pointer confined to the
4+
innermost scope. In this case, the variable `a` gets inferred
5+
to the lifetime of the `if` statement because it is assigned
6+
a borrow of `y` which takes place within the `if`.
7+
8+
Note: If this constraint were lifted (as I contemplated at one point),
9+
it complicates the preservation mechanics in trans, though not
10+
irreperably. I'm partially including this test so that if these
11+
semantics do change we'll remember to test this scenario.
12+
13+
*/
14+
15+
fn testfn(cond: bool) {
16+
let mut x = @3;
17+
let mut y = @4;
18+
19+
let mut a = &*x;
20+
//!^ ERROR reference is not valid outside of its lifetime
21+
22+
let mut exp = 3;
23+
if cond {
24+
a = &*y;
25+
26+
exp = 4;
27+
}
28+
29+
x = @5;
30+
y = @6;
31+
assert *a == exp;
32+
}
33+
34+
fn main() {
35+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// compile-flags:--borrowck=err
2+
// exec-env:RUST_POISON_ON_FREE=1
3+
4+
fn testfn(cond: bool) {
5+
let mut x = @3;
6+
let mut y = @4;
7+
8+
// borrow x and y
9+
let mut r_x = &*x;
10+
let mut r_y = &*y;
11+
let mut r = r_x, exp = 3;
12+
13+
if cond {
14+
r = r_y;
15+
exp = 4;
16+
}
17+
18+
#debug["*r = %d, exp = %d", *r, exp];
19+
assert *r == exp;
20+
21+
x = @5;
22+
y = @6;
23+
24+
#debug["*r = %d, exp = %d", *r, exp];
25+
assert *r == exp;
26+
}
27+
28+
fn main() {
29+
testfn(true);
30+
testfn(false);
31+
}

0 commit comments

Comments
 (0)