Convert alt to match. Stop parsing alt
This commit is contained in:
parent
d3a9bb1bd4
commit
ecaf9e39c9
359 changed files with 2938 additions and 2915 deletions
|
|
@ -1,6 +1,6 @@
|
|||
fn main() {
|
||||
|
||||
alt 0 {
|
||||
match 0 {
|
||||
0 => {
|
||||
} + 5 //~ ERROR unexpected token: `+`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
fn my_fail() -> ! { fail; }
|
||||
|
||||
fn main() {
|
||||
alt true { false => { my_fail(); } true => { } }
|
||||
match true { false => { my_fail(); } true => { } }
|
||||
|
||||
log(debug, x); //~ ERROR unresolved name: x
|
||||
let x: int;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ fn main() {
|
|||
}
|
||||
|
||||
fn foo(c: color) {
|
||||
alt c {
|
||||
match c {
|
||||
rgb(_, _, _) => { }
|
||||
cmyk(_, _, _, _) => { }
|
||||
no_color(_) => { }
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ fn main() {
|
|||
}
|
||||
|
||||
fn foo(c: color) {
|
||||
alt c {
|
||||
match c {
|
||||
rgb(_, _) => { }
|
||||
//~^ ERROR this pattern has 2 fields, but the corresponding variant has 3 fields
|
||||
cmyk(_, _, _, _) => { }
|
||||
|
|
|
|||
|
|
@ -5,27 +5,27 @@
|
|||
//error-pattern: unreachable
|
||||
|
||||
fn main() {
|
||||
alt check 5u {
|
||||
match check 5u {
|
||||
1u to 10u => { }
|
||||
5u to 6u => { }
|
||||
};
|
||||
|
||||
alt check 5u {
|
||||
match check 5u {
|
||||
3u to 6u => { }
|
||||
4u to 6u => { }
|
||||
};
|
||||
|
||||
alt check 5u {
|
||||
match check 5u {
|
||||
4u to 6u => { }
|
||||
4u to 6u => { }
|
||||
};
|
||||
|
||||
alt check 'c' {
|
||||
match check 'c' {
|
||||
'A' to 'z' => {}
|
||||
'a' to 'z' => {}
|
||||
};
|
||||
|
||||
alt check 1.0 {
|
||||
match check 1.0 {
|
||||
0.01 to 6.5 => {}
|
||||
0.02 => {}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,16 +3,16 @@
|
|||
//error-pattern: mismatched types
|
||||
|
||||
fn main() {
|
||||
alt 5u {
|
||||
match 5u {
|
||||
6u to 1u => { }
|
||||
_ => { }
|
||||
};
|
||||
|
||||
alt "wow" {
|
||||
match "wow" {
|
||||
"bar" to "foo" => { }
|
||||
};
|
||||
|
||||
alt 5u {
|
||||
match 5u {
|
||||
'c' to 100u => { }
|
||||
_ => { }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,5 +3,5 @@
|
|||
enum a { A, }
|
||||
enum b { B, }
|
||||
|
||||
fn main() { let x: a = A; alt x { B => { } } }
|
||||
fn main() { let x: a = A; match x { B => { } } }
|
||||
|
||||
|
|
|
|||
|
|
@ -3,5 +3,5 @@
|
|||
enum a { A(int), }
|
||||
enum b { B(int), }
|
||||
|
||||
fn main() { let x: a = A(0); alt x { B(y) => { } } }
|
||||
fn main() { let x: a = A(0); match x { B(y) => { } } }
|
||||
|
||||
|
|
|
|||
|
|
@ -2,5 +2,5 @@
|
|||
|
||||
fn main() {
|
||||
let int x = 5;
|
||||
alt x;
|
||||
match x;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
// error-pattern:did not expect a record with a field `q`
|
||||
|
||||
fn main() { alt {x: 1, y: 2} { {x: x, q: q} => { } } }
|
||||
fn main() { match {x: 1, y: 2} { {x: x, q: q} => { } } }
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
// error-pattern:expected a record with 2 fields, found one with 1
|
||||
|
||||
fn main() { alt {x: 1, y: 2} { {x: x} => { } } }
|
||||
fn main() { match {x: 1, y: 2} { {x: x} => { } } }
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ enum color { rgb(int, int, int), rgba(int, int, int, int), }
|
|||
|
||||
fn main() {
|
||||
let red: color = rgb(255, 0, 0);
|
||||
alt red {
|
||||
match red {
|
||||
rgb(r, g, b) => { debug!{"rgb"}; }
|
||||
hsl(h, s, l) => { debug!{"hsl"}; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ fn impure(_v: ~[int]) {
|
|||
fn main() {
|
||||
let x = {mut f: ~[3]};
|
||||
|
||||
alt x {
|
||||
match x {
|
||||
{f: v} => {
|
||||
impure(v); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
|
||||
//~^ NOTE impure due to access to impure function
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
fn main() {
|
||||
let x = some(~1);
|
||||
alt x { //~ NOTE loan of immutable local variable granted here
|
||||
match x { //~ NOTE loan of immutable local variable granted here
|
||||
some(y) => {
|
||||
let _a <- x; //~ ERROR moving out of immutable local variable prohibited due to outstanding loan
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
fn main() {
|
||||
let x = some(~1);
|
||||
alt x {
|
||||
match x {
|
||||
some(y) => {
|
||||
let _b <- y; //~ ERROR moving out of pattern binding
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ enum cycle {
|
|||
fn main() {
|
||||
let x = ~node({mut a: ~empty});
|
||||
// Create a cycle!
|
||||
alt check *x { //~ NOTE loan of immutable local variable granted here
|
||||
match check *x { //~ NOTE loan of immutable local variable granted here
|
||||
node(y) => {
|
||||
y.a <- x; //~ ERROR moving out of immutable local variable prohibited due to outstanding loan
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
fn match_imm_box(v: &const @option<int>) -> int {
|
||||
alt *v {
|
||||
match *v {
|
||||
@some(i) => {i}
|
||||
@none => {0}
|
||||
}
|
||||
}
|
||||
|
||||
fn match_const_box(v: &const @const option<int>) -> int {
|
||||
alt *v {
|
||||
match *v {
|
||||
@some(i) => { i } // ok because this is pure
|
||||
@none => {0}
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ fn match_const_box(v: &const @const option<int>) -> int {
|
|||
pure fn pure_process(_i: int) {}
|
||||
|
||||
fn match_const_box_and_do_pure_things(v: &const @const option<int>) {
|
||||
alt *v {
|
||||
match *v {
|
||||
@some(i) => {
|
||||
pure_process(i)
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ fn match_const_box_and_do_pure_things(v: &const @const option<int>) {
|
|||
fn process(_i: int) {}
|
||||
|
||||
fn match_const_box_and_do_bad_things(v: &const @const option<int>) {
|
||||
alt *v {
|
||||
match *v {
|
||||
@some(i) => { //~ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
|
||||
process(i) //~ NOTE impure due to access to impure function
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
fn match_ref(&&v: option<int>) -> int {
|
||||
alt v {
|
||||
match v {
|
||||
some(i) => {
|
||||
i
|
||||
}
|
||||
|
|
@ -8,14 +8,14 @@ fn match_ref(&&v: option<int>) -> int {
|
|||
}
|
||||
|
||||
fn match_ref_unused(&&v: option<int>) {
|
||||
alt v {
|
||||
match v {
|
||||
some(_) => {}
|
||||
none => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn match_const_reg(v: &const option<int>) -> int {
|
||||
alt *v {
|
||||
match *v {
|
||||
some(i) => {i} // OK because this is pure
|
||||
none => {0}
|
||||
}
|
||||
|
|
@ -25,14 +25,14 @@ fn impure(_i: int) {
|
|||
}
|
||||
|
||||
fn match_const_reg_unused(v: &const option<int>) {
|
||||
alt *v {
|
||||
match *v {
|
||||
some(_) => {impure(0)} // OK because nothing is captured
|
||||
none => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn match_const_reg_impure(v: &const option<int>) {
|
||||
alt *v {
|
||||
match *v {
|
||||
some(i) => {impure(i)} //~ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
|
||||
//~^ NOTE impure due to access to impure function
|
||||
none => {}
|
||||
|
|
@ -40,7 +40,7 @@ fn match_const_reg_impure(v: &const option<int>) {
|
|||
}
|
||||
|
||||
fn match_imm_reg(v: &option<int>) {
|
||||
alt *v {
|
||||
match *v {
|
||||
some(i) => {impure(i)} // OK because immutable
|
||||
none => {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
fn main() {
|
||||
let mut x: option<int> = none;
|
||||
alt x { //~ NOTE loan of mutable local variable granted here
|
||||
match x { //~ NOTE loan of mutable local variable granted here
|
||||
none => {}
|
||||
some(i) => {
|
||||
// Not ok: i is an outstanding ptr into x.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
fn main() {
|
||||
let mut x = none;
|
||||
alt x { //~ NOTE loan of mutable local variable granted here
|
||||
match x { //~ NOTE loan of mutable local variable granted here
|
||||
none => {
|
||||
// It is ok to reassign x here, because there is in
|
||||
// fact no outstanding loan of x!
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ fn impure(_i: int) {}
|
|||
|
||||
// check that unchecked alone does not override borrowck:
|
||||
fn foo(v: &const option<int>) {
|
||||
alt *v {
|
||||
match *v {
|
||||
some(i) => {
|
||||
//~^ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
|
||||
unchecked {
|
||||
|
|
@ -15,7 +15,7 @@ fn foo(v: &const option<int>) {
|
|||
}
|
||||
|
||||
fn bar(v: &const option<int>) {
|
||||
alt *v {
|
||||
match *v {
|
||||
some(i) => {
|
||||
unsafe {
|
||||
impure(i);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// error-pattern:cannot be dereferenced
|
||||
fn main() {
|
||||
alt *1 {
|
||||
match *1 {
|
||||
_ => { fail; }
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ mod foo {
|
|||
const b : t = 1u8;
|
||||
|
||||
fn bar(v: t) -> bool {
|
||||
alt v {
|
||||
match v {
|
||||
a => { return true; }
|
||||
b => { return false; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
fn foo(a: option<uint>, b: option<uint>) {
|
||||
alt (a,b) { //~ ERROR: non-exhaustive patterns: none not covered
|
||||
match (a,b) { //~ ERROR: non-exhaustive patterns: none not covered
|
||||
(some(a), some(b)) if a == b => { }
|
||||
(some(_), none) |
|
||||
(none, some(_)) => { }
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
xfailed for now (see Issue #2354)
|
||||
*/
|
||||
fn foo() { //~ ERROR this open brace is not closed
|
||||
alt some(x) {
|
||||
match some(x) {
|
||||
some(y) { fail; }
|
||||
none { fail; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ mod bar {
|
|||
|
||||
fn main() {
|
||||
import bar::{alpha, charlie};
|
||||
alt alpha {
|
||||
match alpha {
|
||||
alpha | beta => {} //~ ERROR: inconsistent number of bindings
|
||||
charlie => {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
enum foo { alpha, beta(int) }
|
||||
|
||||
fn main() {
|
||||
alt alpha {
|
||||
match alpha {
|
||||
alpha | beta(i) => {} //~ ERROR inconsistent number of bindings
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,17 +8,17 @@ enum k { m(int, int) }
|
|||
fn main()
|
||||
{
|
||||
|
||||
let _z = alt g(1, 2) {
|
||||
let _z = match g(1, 2) {
|
||||
g(x, x) => { log(debug, x + x); }
|
||||
//~^ ERROR Identifier x is bound more than once in the same pattern
|
||||
};
|
||||
|
||||
let _z = alt i(l(1, 2), m(3, 4)) {
|
||||
let _z = match i(l(1, 2), m(3, 4)) {
|
||||
i(l(x, _), m(_, x)) //~ ERROR Identifier x is bound more than once in the same pattern
|
||||
=> { log(error, x + x); }
|
||||
};
|
||||
|
||||
let _z = alt (1, 2) {
|
||||
let _z = match (1, 2) {
|
||||
(x, x) => { x } //~ ERROR Identifier x is bound more than once in the same pattern
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
// error-pattern: not all control paths return a value
|
||||
|
||||
fn f() -> int {
|
||||
// Make sure typestate doesn't interpreturn this alt expression
|
||||
// Make sure typestate doesn't interpreturn this match expression
|
||||
// as the function result
|
||||
alt check true { true => { } };
|
||||
match check true { true => { } };
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ fn f3b() {
|
|||
}
|
||||
|
||||
fn f4() {
|
||||
alt some(3) {
|
||||
match some(3) {
|
||||
some(i) => {
|
||||
}
|
||||
none => {}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ enum u { c, d }
|
|||
|
||||
fn main() {
|
||||
let x = a(c);
|
||||
alt x {
|
||||
match x {
|
||||
a(d) => { fail ~"hello"; }
|
||||
b => { fail ~"goodbye"; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,25 +2,25 @@ enum t { a, b, }
|
|||
|
||||
fn main() {
|
||||
let x = a;
|
||||
alt x { b => { } } //~ ERROR non-exhaustive patterns
|
||||
alt true { //~ ERROR non-exhaustive patterns
|
||||
match x { b => { } } //~ ERROR non-exhaustive patterns
|
||||
match true { //~ ERROR non-exhaustive patterns
|
||||
true => {}
|
||||
}
|
||||
alt @some(10) { //~ ERROR non-exhaustive patterns
|
||||
match @some(10) { //~ ERROR non-exhaustive patterns
|
||||
@none => {}
|
||||
}
|
||||
alt (2, 3, 4) { //~ ERROR non-exhaustive patterns
|
||||
match (2, 3, 4) { //~ ERROR non-exhaustive patterns
|
||||
(_, _, 4) => {}
|
||||
}
|
||||
alt (a, a) { //~ ERROR non-exhaustive patterns
|
||||
match (a, a) { //~ ERROR non-exhaustive patterns
|
||||
(a, b) => {}
|
||||
(b, a) => {}
|
||||
}
|
||||
alt a { //~ ERROR b not covered
|
||||
match a { //~ ERROR b not covered
|
||||
a => {}
|
||||
}
|
||||
// This is exhaustive, though the algorithm got it wrong at one point
|
||||
alt (a, b) {
|
||||
match (a, b) {
|
||||
(a, _) => {}
|
||||
(_, a) => {}
|
||||
(b, b) => {}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// error-pattern:mismatched types
|
||||
// From Issue #778
|
||||
enum clam<T> { a(T), }
|
||||
fn main() { let c; c = a(c); alt c { a::<int>(_) => { } } }
|
||||
fn main() { let c; c = a(c); match c { a::<int>(_) => { } } }
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
enum blah { a(int, int, uint), b(int, int), }
|
||||
|
||||
fn main() { alt a(1, 1, 2u) { a(_, x, y) | b(x, y) => { } } }
|
||||
fn main() { match a(1, 1, 2u) { a(_, x, y) | b(x, y) => { } } }
|
||||
|
|
|
|||
|
|
@ -8,6 +8,6 @@ import option::some;
|
|||
|
||||
enum bar { t1((), option<~[int]>), t2, }
|
||||
|
||||
fn foo(t: bar) -> int { alt t { t1(_, some(x)) => { return x * 3; } _ => { fail; } } }
|
||||
fn foo(t: bar) -> int { match t { t1(_, some(x)) => { return x * 3; } _ => { fail; } } }
|
||||
|
||||
fn main() { }
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import option::some;
|
|||
enum bar { t1((), option<~[int]>), t2, }
|
||||
|
||||
fn foo(t: bar) {
|
||||
alt t {
|
||||
match t {
|
||||
t1(_, some::<int>(x)) => {
|
||||
log(debug, x);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,14 +11,14 @@ fn build() {
|
|||
}
|
||||
|
||||
fn compute(x: &ast) -> uint {
|
||||
alt *x {
|
||||
match *x {
|
||||
num(x) => { x }
|
||||
add(x, y) => { compute(x) + compute(y) }
|
||||
}
|
||||
}
|
||||
|
||||
fn map_nums(x: &ast, f: fn(uint) -> uint) -> &ast {
|
||||
alt *x {
|
||||
match *x {
|
||||
num(x) => {
|
||||
return &num(f(x)); //~ ERROR illegal borrow
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// error-pattern:found `let` in restricted position
|
||||
|
||||
fn main() {
|
||||
alt true {
|
||||
match true {
|
||||
{let} { }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
enum foo { a(@foo, int), b(uint), }
|
||||
|
||||
fn main() { alt b(1u) { b(_) | a(@_, 1) => { } a(_, 1) => { } } }
|
||||
fn main() { match b(1u) { b(_) | a(@_, 1) => { } a(_, 1) => { } } }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue