Skip to content

Commit 15d38bf

Browse files
committed
---
yaml --- r: 31688 b: refs/heads/dist-snap c: dbef6e5 h: refs/heads/master v: v3
1 parent 00aaffc commit 15d38bf

14 files changed

+61
-47
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
10-
refs/heads/dist-snap: 5f1987c6c48fe8d194310a3629f04405f08710f0
10+
refs/heads/dist-snap: dbef6e593dfb1b164c6750ee99ca2b80c249c4f5
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/dist-snap/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,7 @@ Empty argument lists can be omitted from `do` expressions.
17571757

17581758
Most iteration in Rust is done with `for` loops. Like `do`,
17591759
`for` is a nice syntax for doing control flow with closures.
1760-
Additionally, within a `for` loop, `break`, `again`, and `return`
1760+
Additionally, within a `for` loop, `break`, `again`, and `retern`
17611761
work just as they do with `while` and `loop`.
17621762

17631763
Consider again our `each` function, this time improved to

branches/dist-snap/src/rustc/middle/typeck/check/alt.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) {
166166
// ref x | ref const x | ref mut x
167167
// then the type of x is &M T where M is the mutability
168168
// and T is the expected type
169-
let region_var = fcx.infcx.next_region_var_nb();
169+
let region_var =
170+
fcx.infcx.next_region_var({lb: some(pcx.block_region),
171+
ub: none});
170172
let mt = {ty: expected, mutbl: mutbl};
171173
let region_ty = ty::mk_rptr(tcx, region_var, mt);
172174
demand::eqtype(fcx, pat.span, region_ty, typ);

branches/dist-snap/src/rustc/middle/typeck/check/regionck.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import syntax::print::pprust;
2222
import infer::{resolve_type, resolve_all, force_all,
2323
resolve_rvar, force_rvar, fres};
2424
import middle::kind::check_owned;
25+
import middle::pat_util::pat_bindings;
2526

2627
enum rcx { rcx_({fcx: @fn_ctxt, mut errors_reported: uint}) }
2728
type rvt = visit::vt<@rcx>;
@@ -80,7 +81,6 @@ fn regionck_visitor() -> rvt {
8081
visit_stmt: visit_stmt,
8182
visit_expr: visit_expr,
8283
visit_block: visit_block,
83-
visit_pat: visit_pat,
8484
visit_local: visit_local
8585
with *visit::default_visitor()})
8686
}
@@ -90,8 +90,26 @@ fn visit_item(_item: @ast::item, &&_rcx: @rcx, _v: rvt) {
9090
}
9191

9292
fn visit_local(l: @ast::local, &&rcx: @rcx, v: rvt) {
93+
// Check to make sure that the regions in all local variables are
94+
// within scope.
95+
//
96+
// Note: we do this here rather than in visit_pat because we do
97+
// not wish to constrain the regions in *patterns* in quite the
98+
// same way. `visit_node()` guarantees that the region encloses
99+
// the node in question, which ultimately constraints the regions
100+
// in patterns to enclose the match expression as a whole. But we
101+
// want them to enclose the *arm*. However, regions in patterns
102+
// must either derive from the discriminant or a ref pattern: in
103+
// the case of the discriminant, the regions will be constrained
104+
// when the type of the discriminant is checked. In the case of a
105+
// ref pattern, the variable is created with a suitable lower
106+
// bound.
93107
let e = rcx.errors_reported;
94108
v.visit_pat(l.node.pat, rcx, v);
109+
let def_map = rcx.fcx.ccx.tcx.def_map;
110+
do pat_bindings(def_map, l.node.pat) |_bm, id, sp, _path| {
111+
visit_node(id, sp, rcx);
112+
}
95113
if e != rcx.errors_reported {
96114
return; // if decl has errors, skip initializer expr
97115
}
@@ -102,20 +120,6 @@ fn visit_local(l: @ast::local, &&rcx: @rcx, v: rvt) {
102120
}
103121
}
104122

105-
fn visit_pat(p: @ast::pat, &&rcx: @rcx, v: rvt) {
106-
let fcx = rcx.fcx;
107-
match p.node {
108-
ast::pat_ident(_, path, _)
109-
if !pat_util::pat_is_variant(fcx.ccx.tcx.def_map, p) => {
110-
debug!{"visit_pat binding=%s", *path.idents[0]};
111-
visit_node(p.id, p.span, rcx);
112-
}
113-
_ => ()
114-
}
115-
116-
visit::visit_pat(p, rcx, v);
117-
}
118-
119123
fn visit_block(b: ast::blk, &&rcx: @rcx, v: rvt) {
120124
visit::visit_block(b, rcx, v);
121125
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
fn impure(_v: ~[int]) {
1+
fn impure(_v: &[int]) {
22
}
33

44
fn main() {
55
let x = {mut f: ~[3]};
66

77
match x {
8-
{f: v} => {
9-
impure(v); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
8+
{f: ref mut v} => {
9+
impure(*v); //~ ERROR illegal borrow unless pure
1010
//~^ NOTE impure due to access to impure function
1111
}
1212
}
13-
}
13+
}

branches/dist-snap/src/test/compile-fail/borrowck-issue-2657-1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fn main() {
22
let x = some(~1);
33
match x { //~ NOTE loan of immutable local variable granted here
4-
some(y) => {
4+
some(ref y) => {
55
let _a <- x; //~ ERROR moving out of immutable local variable prohibited due to outstanding loan
66
}
77
_ => {}

branches/dist-snap/src/test/compile-fail/borrowck-issue-2657-2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
fn main() {
22
let x = some(~1);
33
match x {
4-
some(y) => {
5-
let _b <- y; //~ ERROR moving out of pattern binding
4+
some(ref y) => {
5+
let _b <- *y; //~ ERROR moving out of dereference of immutable & pointer
66
}
77
_ => {}
88
}

branches/dist-snap/src/test/compile-fail/borrowck-no-cycle-in-exchange-heap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ fn main() {
66
let x = ~node({mut a: ~empty});
77
// Create a cycle!
88
match check *x { //~ NOTE loan of immutable local variable granted here
9-
node(y) => {
9+
node(ref y) => {
1010
y.a <- x; //~ ERROR moving out of immutable local variable prohibited due to outstanding loan
1111
}
1212
};
13-
}
13+
}

branches/dist-snap/src/test/compile-fail/borrowck-pat-enum-in-box.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
fn match_imm_box(v: &const @option<int>) -> int {
22
match *v {
3-
@some(i) => {i}
3+
@some(ref i) => {*i}
44
@none => {0}
55
}
66
}
77

88
fn match_const_box(v: &const @const option<int>) -> int {
99
match *v {
10-
@some(i) => { i } // ok because this is pure
10+
@some(ref i) => { *i } // ok because this is pure
1111
@none => {0}
1212
}
1313
}
@@ -16,8 +16,8 @@ pure fn pure_process(_i: int) {}
1616

1717
fn match_const_box_and_do_pure_things(v: &const @const option<int>) {
1818
match *v {
19-
@some(i) => {
20-
pure_process(i)
19+
@some(ref i) => {
20+
pure_process(*i)
2121
}
2222
@none => {}
2323
}
@@ -27,8 +27,8 @@ fn process(_i: int) {}
2727

2828
fn match_const_box_and_do_bad_things(v: &const @const option<int>) {
2929
match *v {
30-
@some(i) => { //~ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
31-
process(i) //~ NOTE impure due to access to impure function
30+
@some(ref i) => { //~ ERROR illegal borrow unless pure
31+
process(*i) //~ NOTE impure due to access to impure function
3232
}
3333
@none => {}
3434
}

branches/dist-snap/src/test/compile-fail/borrowck-pat-enum.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fn match_ref(&&v: option<int>) -> int {
22
match v {
3-
some(i) => {
4-
i
3+
some(ref i) => {
4+
*i
55
}
66
none => {0}
77
}
@@ -16,7 +16,7 @@ fn match_ref_unused(&&v: option<int>) {
1616

1717
fn match_const_reg(v: &const option<int>) -> int {
1818
match *v {
19-
some(i) => {i} // OK because this is pure
19+
some(ref i) => {*i} // OK because this is pure
2020
none => {0}
2121
}
2222
}
@@ -33,15 +33,15 @@ fn match_const_reg_unused(v: &const option<int>) {
3333

3434
fn match_const_reg_impure(v: &const option<int>) {
3535
match *v {
36-
some(i) => {impure(i)} //~ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
36+
some(ref i) => {impure(*i)} //~ ERROR illegal borrow unless pure
3737
//~^ NOTE impure due to access to impure function
3838
none => {}
3939
}
4040
}
4141

4242
fn match_imm_reg(v: &option<int>) {
4343
match *v {
44-
some(i) => {impure(i)} // OK because immutable
44+
some(ref i) => {impure(*i)} // OK because immutable
4545
none => {}
4646
}
4747
}

branches/dist-snap/src/test/compile-fail/borrowck-pat-reassign-binding.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ fn main() {
44
let mut x: option<int> = none;
55
match x { //~ NOTE loan of mutable local variable granted here
66
none => {}
7-
some(i) => {
7+
some(ref i) => {
88
// Not ok: i is an outstanding ptr into x.
9-
x = some(i+1); //~ ERROR assigning to mutable local variable prohibited due to outstanding loan
9+
x = some(*i+1); //~ ERROR assigning to mutable local variable prohibited due to outstanding loan
1010
}
1111
}
1212
copy x; // just to prevent liveness warnings

branches/dist-snap/src/test/compile-fail/borrowck-pat-reassign-sometimes-binding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn main() {
88
// fact no outstanding loan of x!
99
x = some(0);
1010
}
11-
some(i) => {
11+
some(ref i) => {
1212
x = some(1); //~ ERROR assigning to mutable local variable prohibited due to outstanding loan
1313
}
1414
}

branches/dist-snap/src/test/compile-fail/borrowck-unchecked-with-borrow.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ fn impure(_i: int) {}
33
// check that unchecked alone does not override borrowck:
44
fn foo(v: &const option<int>) {
55
match *v {
6-
some(i) => {
7-
//~^ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
6+
some(ref i) => {
7+
//~^ ERROR illegal borrow unless pure
88
unchecked {
9-
impure(i); //~ NOTE impure due to access to impure function
9+
impure(*i); //~ NOTE impure due to access to impure function
1010
}
1111
}
1212
none => {
@@ -16,9 +16,9 @@ fn foo(v: &const option<int>) {
1616

1717
fn bar(v: &const option<int>) {
1818
match *v {
19-
some(i) => {
19+
some(ref i) => {
2020
unsafe {
21-
impure(i);
21+
impure(*i);
2222
}
2323
}
2424
none => {
@@ -27,4 +27,4 @@ fn bar(v: &const option<int>) {
2727
}
2828

2929
fn main() {
30-
}
30+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
let mut v = some(22);
3+
match v {
4+
none => {}
5+
some(ref mut p) => { *p += 1; }
6+
}
7+
assert v == some(23);
8+
}

0 commit comments

Comments
 (0)