Skip to content

Commit 17b3712

Browse files
committed
Update existing tests to account for stricter, more correct handling of irrefutable patterns
1 parent ed69ef0 commit 17b3712

6 files changed

+48
-41
lines changed

src/test/compile-fail/borrowck-move-out-of-vec-tail.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn main() {
1111
Foo { string: ~"baz" }
1212
];
1313
match x {
14-
[first, ..tail] => {
14+
[_, ..tail] => {
1515
match tail {
1616
[Foo { string: a }, Foo { string: b }] => {
1717
//~^ ERROR cannot move out of dereference of & pointer

src/test/compile-fail/borrowck-vec-pattern-nesting.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,41 @@ fn b() {
1717
}
1818
}
1919

20+
fn c() {
21+
let mut vec = [~1, ~2, ~3];
22+
match vec {
23+
[_a, .._b] => {
24+
//~^ ERROR cannot move out
25+
26+
// Note: `_a` is *moved* here, but `b` is borrowing,
27+
// hence illegal.
28+
//
29+
// See comment in middle/borrowck/gather_loans/mod.rs
30+
// in the case covering these sorts of vectors.
31+
}
32+
_ => {}
33+
}
34+
let a = vec[0]; //~ ERROR use of partially moved value: `vec`
35+
}
36+
37+
fn d() {
38+
let mut vec = [~1, ~2, ~3];
39+
match vec {
40+
[.._a, _b] => {
41+
//~^ ERROR cannot move out
42+
}
43+
_ => {}
44+
}
45+
let a = vec[0]; //~ ERROR use of partially moved value: `vec`
46+
}
47+
48+
fn e() {
49+
let mut vec = [~1, ~2, ~3];
50+
match vec {
51+
[_a, _b, _c] => {}
52+
_ => {}
53+
}
54+
let a = vec[0]; //~ ERROR use of partially moved value: `vec`
55+
}
56+
2057
fn main() {}

src/test/run-pass/borrowck-newtype-issue-2573.rs

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/test/run-pass/borrowck-wg-autoderef-and-autoborrowvec-combined-issue-6272.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828

2929

3030
fn main() {
31-
let a = @mut [3i];
32-
let b = @mut [a];
33-
let c = @mut b;
31+
let a = @mut 3i;
32+
// let b = @mut [a];
33+
// let c = @mut [3];
3434

3535
// this should freeze `a` only
36-
let _x: &mut [int] = c[0];
36+
let _x: &mut int = a;
3737

3838
// hence these writes should not fail:
39-
b[0] = b[0];
40-
c[0] = c[0];
39+
// b[0] = b[0];
40+
// c[0] = c[0];
4141
}

src/test/run-pass/match-pattern-drop.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
enum t { make_t(@int), clam, }
1515

1616
fn foo(s: @int) {
17+
debug!(::std::sys::refcount(s));
1718
let count = ::std::sys::refcount(s);
1819
let x: t = make_t(s); // ref up
20+
assert_eq!(::std::sys::refcount(s), count + 1u);
21+
debug!(::std::sys::refcount(s));
1922

2023
match x {
2124
make_t(y) => {
@@ -38,6 +41,5 @@ pub fn main() {
3841

3942
debug!("%u", ::std::sys::refcount(s));
4043
let count2 = ::std::sys::refcount(s);
41-
let _ = ::std::sys::refcount(s); // don't get bitten by last-use.
4244
assert_eq!(count, count2);
4345
}

src/test/run-pass/vec-tail-matching.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn main() {
99
Foo { string: ~"baz" }
1010
];
1111
match x {
12-
[first, ..tail] => {
12+
[ref first, ..tail] => {
1313
assert!(first.string == ~"foo");
1414
assert_eq!(tail.len(), 2);
1515
assert!(tail[0].string == ~"bar");

0 commit comments

Comments
 (0)