]>
Commit | Line | Data |
---|---|---|
223e47cc LB |
1 | // Copyright 2012 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
e9174d1e SL |
11 | // compile-flags: --crate-type=lib |
12 | ||
223e47cc LB |
13 | // A bunch of tests for syntactic forms involving blocks that were |
14 | // previously ambiguous (e.g. 'if true { } *val;' gets parsed as a | |
15 | // binop) | |
16 | ||
223e47cc | 17 | |
1a4d82fc JJ |
18 | use std::cell::Cell; |
19 | ||
85aaf69f | 20 | fn test1() { let val = &0; { } *val; } |
1a4d82fc | 21 | |
c34b1796 | 22 | fn test2() -> isize { let val = &0; { } *val } |
223e47cc | 23 | |
c34b1796 AL |
24 | #[derive(Copy, Clone)] |
25 | struct S { eax: isize } | |
223e47cc LB |
26 | |
27 | fn test3() { | |
1a4d82fc | 28 | let regs = &Cell::new(S {eax: 0}); |
223e47cc | 29 | match true { true => { } _ => { } } |
1a4d82fc | 30 | regs.set(S {eax: 1}); |
223e47cc LB |
31 | } |
32 | ||
1a4d82fc | 33 | fn test4() -> bool { let regs = &true; if true { } *regs || false } |
223e47cc | 34 | |
c34b1796 | 35 | fn test5() -> (isize, isize) { { } (0, 1) } |
223e47cc LB |
36 | |
37 | fn test6() -> bool { { } (true || false) && true } | |
38 | ||
c34b1796 | 39 | fn test7() -> usize { |
85aaf69f | 40 | let regs = &0; |
223e47cc | 41 | match true { true => { } _ => { } } |
c34b1796 | 42 | (*regs < 2) as usize |
223e47cc LB |
43 | } |
44 | ||
c34b1796 | 45 | fn test8() -> isize { |
85aaf69f | 46 | let val = &0; |
223e47cc LB |
47 | match true { |
48 | true => { } | |
49 | _ => { } | |
50 | } | |
51 | if *val < 1 { | |
52 | 0 | |
53 | } else { | |
54 | 1 | |
55 | } | |
56 | } | |
57 | ||
1a4d82fc | 58 | fn test9() { |
85aaf69f | 59 | let regs = &Cell::new(0); |
1a4d82fc JJ |
60 | match true { true => { } _ => { } } regs.set(regs.get() + 1); |
61 | } | |
223e47cc | 62 | |
c34b1796 | 63 | fn test10() -> isize { |
c30ab7b3 | 64 | let regs = vec![0]; |
223e47cc | 65 | match true { true => { } _ => { } } |
1a4d82fc | 66 | regs[0] |
223e47cc LB |
67 | } |
68 | ||
c30ab7b3 | 69 | fn test11() -> Vec<isize> { if true { } vec![1, 2] } |