]> git.lizzy.rs Git - rust.git/blob - src/test/pretty/block-disambig.rs
auto merge of #18192 : jmesmon/rust/platform-generic, r=alexcrichton
[rust.git] / src / test / pretty / block-disambig.rs
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
11 // A bunch of tests for syntactic forms involving blocks that were
12 // previously ambiguous (e.g. 'if true { } *val;' gets parsed as a
13 // binop)
14
15
16 use std::cell::Cell;
17
18 fn test1() { let val = &0i; { } *val; }
19
20 fn test2() -> int { let val = &0i; { } *val }
21
22 struct S { eax: int }
23
24 fn test3() {
25     let regs = &Cell::new(S {eax: 0});
26     match true { true => { } _ => { } }
27     regs.set(S {eax: 1});
28 }
29
30 fn test4() -> bool { let regs = &true; if true { } *regs || false }
31
32 fn test5() -> (int, int) { { } (0, 1) }
33
34 fn test6() -> bool { { } (true || false) && true }
35
36 fn test7() -> uint {
37     let regs = &0i;
38     match true { true => { } _ => { } }
39     (*regs < 2) as uint
40 }
41
42 fn test8() -> int {
43     let val = &0i;
44     match true {
45         true => { }
46         _    => { }
47     }
48     if *val < 1 {
49         0
50     } else {
51         1
52     }
53 }
54
55 fn test9() {
56     let regs = &Cell::new(0i);
57     match true { true => { } _ => { } } regs.set(regs.get() + 1);
58 }
59
60 fn test10() -> int {
61     let regs = vec!(0i);
62     match true { true => { } _ => { } }
63     regs[0]
64 }
65
66 fn test11() -> Vec<int> { if true { } vec!(1, 2) }