-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/test/compile-fail/alt-vec-illegal-tail-element-loan.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
fn a() -> &int { | ||
let vec = [1, 2, 3, 4]; | ||
let tail = match vec { | ||
[a, ..tail] => &tail[0], //~ ERROR illegal borrow | ||
_ => fail ~"foo" | ||
}; | ||
move tail | ||
} | ||
|
||
fn main() { | ||
let fifth = a(); | ||
io::println(fmt!("%d", *fifth)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
fn main() { | ||
let a = [mut 1, 2, 3, 4]; | ||
let _ = match a { | ||
[1, 2, ..move tail] => tail, | ||
_ => core::util::unreachable() | ||
}; | ||
a[0] = 0; //~ ERROR: use of moved variable | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
fn main() { | ||
let x = @[1, 2, 3]; | ||
match x { | ||
[2, .._] => core::util::unreachable(), | ||
[1, ..tail] => { | ||
assert tail == [2, 3]; | ||
} | ||
[_] => core::util::unreachable(), | ||
[] => core::util::unreachable() | ||
} | ||
|
||
let y = (~[(1, true), (2, false)], 0.5); | ||
match y { | ||
([_, _, _], 0.5) => core::util::unreachable(), | ||
([(1, a), (b, false), ..tail], _) => { | ||
assert a == true; | ||
assert b == 2; | ||
assert tail.is_empty(); | ||
} | ||
([..tail], _) => core::util::unreachable() | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/run-pass/vec-matching-legal-tail-element-borrow.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
fn main() { | ||
let x = &[1, 2, 3, 4, 5]; | ||
if !x.is_empty() { | ||
let el = match x { | ||
[1, ..ref tail] => &tail[0], | ||
_ => core::util::unreachable() | ||
}; | ||
io::println(fmt!("%d", *el)); | ||
} | ||
} |