Merge branch 'vec-exh' of https://github.com/stepancheg/rust into rollup
This commit is contained in:
commit
5e1ca23a65
11 changed files with 88 additions and 18 deletions
|
|
@ -6,7 +6,7 @@ struct Foo {
|
|||
}
|
||||
|
||||
pub fn main() {
|
||||
let x = [
|
||||
let x = ~[
|
||||
Foo { string: ~"foo" },
|
||||
Foo { string: ~"bar" },
|
||||
Foo { string: ~"baz" }
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
fn a() -> &[int] {
|
||||
let vec = [1, 2, 3, 4];
|
||||
let vec = ~[1, 2, 3, 4];
|
||||
let tail = match vec {
|
||||
[_, ..tail] => tail, //~ ERROR does not live long enough
|
||||
_ => fail!("a")
|
||||
|
|
@ -8,7 +8,7 @@ fn a() -> &[int] {
|
|||
}
|
||||
|
||||
fn b() -> &[int] {
|
||||
let vec = [1, 2, 3, 4];
|
||||
let vec = ~[1, 2, 3, 4];
|
||||
let init = match vec {
|
||||
[..init, _] => init, //~ ERROR does not live long enough
|
||||
_ => fail!("b")
|
||||
|
|
@ -17,7 +17,7 @@ fn b() -> &[int] {
|
|||
}
|
||||
|
||||
fn c() -> &[int] {
|
||||
let vec = [1, 2, 3, 4];
|
||||
let vec = ~[1, 2, 3, 4];
|
||||
let slice = match vec {
|
||||
[_, ..slice, _] => slice, //~ ERROR does not live long enough
|
||||
_ => fail!("c")
|
||||
|
|
|
|||
|
|
@ -1,24 +1,24 @@
|
|||
fn a() {
|
||||
let mut vec = [~1, ~2, ~3];
|
||||
let mut vec = ~[~1, ~2, ~3];
|
||||
match vec {
|
||||
[~ref _a] => {
|
||||
vec[0] = ~4; //~ ERROR cannot assign to `vec[]` because it is borrowed
|
||||
vec[0] = ~4; //~ ERROR cannot assign to `(*vec)[]` because it is borrowed
|
||||
}
|
||||
_ => fail!("foo")
|
||||
}
|
||||
}
|
||||
|
||||
fn b() {
|
||||
let mut vec = [~1, ~2, ~3];
|
||||
let mut vec = ~[~1, ~2, ~3];
|
||||
match vec {
|
||||
[.._b] => {
|
||||
vec[0] = ~4; //~ ERROR cannot assign to `vec[]` because it is borrowed
|
||||
vec[0] = ~4; //~ ERROR cannot assign to `(*vec)[]` because it is borrowed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn c() {
|
||||
let mut vec = [~1, ~2, ~3];
|
||||
let mut vec = ~[~1, ~2, ~3];
|
||||
match vec {
|
||||
[_a, .._b] => {
|
||||
//~^ ERROR cannot move out
|
||||
|
|
@ -35,7 +35,7 @@ fn c() {
|
|||
}
|
||||
|
||||
fn d() {
|
||||
let mut vec = [~1, ~2, ~3];
|
||||
let mut vec = ~[~1, ~2, ~3];
|
||||
match vec {
|
||||
[.._a, _b] => {
|
||||
//~^ ERROR cannot move out
|
||||
|
|
@ -46,7 +46,7 @@ fn d() {
|
|||
}
|
||||
|
||||
fn e() {
|
||||
let mut vec = [~1, ~2, ~3];
|
||||
let mut vec = ~[~1, ~2, ~3];
|
||||
match vec {
|
||||
[_a, _b, _c] => {}
|
||||
_ => {}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
fn a() -> &int {
|
||||
let vec = [1, 2, 3, 4];
|
||||
let vec = ~[1, 2, 3, 4];
|
||||
let tail = match vec {
|
||||
[_a, ..tail] => &tail[0], //~ ERROR borrowed value does not live long enough
|
||||
_ => fail!("foo")
|
||||
|
|
|
|||
16
src/test/compile-fail/match-vec-fixed.rs
Normal file
16
src/test/compile-fail/match-vec-fixed.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
fn a() {
|
||||
let v = [1, 2, 3];
|
||||
match v {
|
||||
[_, _, _] => {}
|
||||
[_, _, _] => {} //~ ERROR unreachable pattern
|
||||
}
|
||||
match v {
|
||||
[_, 1, _] => {}
|
||||
[_, 1, _] => {} //~ ERROR unreachable pattern
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
a();
|
||||
}
|
||||
|
|
@ -6,13 +6,13 @@ fn main() {
|
|||
_ => ()
|
||||
}
|
||||
|
||||
match [~"foo", ~"bar", ~"baz"] {
|
||||
match ~[~"foo", ~"bar", ~"baz"] {
|
||||
[a, _, _, .._] => { println(a); }
|
||||
[~"foo", ~"bar", ~"baz", ~"foo", ~"bar"] => { } //~ ERROR unreachable pattern
|
||||
_ => { }
|
||||
}
|
||||
|
||||
match ['a', 'b', 'c'] {
|
||||
match ~['a', 'b', 'c'] {
|
||||
['a', 'b', 'c', .._tail] => {}
|
||||
['a', 'b', 'c'] => {} //~ ERROR unreachable pattern
|
||||
_ => {}
|
||||
|
|
|
|||
28
src/test/run-pass/vec-matching-fixed.rs
Normal file
28
src/test/run-pass/vec-matching-fixed.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
fn a() {
|
||||
let x = [1, 2, 3];
|
||||
match x {
|
||||
[1, 2, 4] => ::std::util::unreachable(),
|
||||
[0, 2, 3, .._] => ::std::util::unreachable(),
|
||||
[0, .._, 3] => ::std::util::unreachable(),
|
||||
[0, .._] => ::std::util::unreachable(),
|
||||
[1, 2, 3] => (),
|
||||
[_, _, _] => ::std::util::unreachable(),
|
||||
}
|
||||
match x {
|
||||
[.._] => (),
|
||||
}
|
||||
match x {
|
||||
[_, _, _, .._] => (),
|
||||
}
|
||||
match x {
|
||||
[a, b, c] => {
|
||||
assert_eq!(1, a);
|
||||
assert_eq!(2, b);
|
||||
assert_eq!(3, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
a();
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
fn a() {
|
||||
let x = [1];
|
||||
let x = ~[1];
|
||||
match x {
|
||||
[_, _, _, _, _, .._] => ::std::util::unreachable(),
|
||||
[.._, _, _, _, _] => ::std::util::unreachable(),
|
||||
|
|
@ -13,7 +13,7 @@ fn a() {
|
|||
}
|
||||
|
||||
fn b() {
|
||||
let x = [1, 2, 3];
|
||||
let x = ~[1, 2, 3];
|
||||
match x {
|
||||
[a, b, ..c] => {
|
||||
assert_eq!(a, 1);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ struct Foo {
|
|||
}
|
||||
|
||||
pub fn main() {
|
||||
let x = [
|
||||
let x = ~[
|
||||
Foo { string: ~"foo" },
|
||||
Foo { string: ~"bar" },
|
||||
Foo { string: ~"baz" }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue