]> git.lizzy.rs Git - rust.git/blob - src/test/pretty/block-disambig.rs
8e4427d9dd4e9f8e5cdb72d1e536245ba036d00f
[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 #[feature(managed_boxes)];
16
17 use std::cell::Cell;
18
19 fn test1() { let val = @0; { } *val; }
20
21 fn test2() -> int { let val = @0; { } *val }
22
23 struct S { eax: int }
24
25 fn test3() {
26     let regs = @Cell::new(S {eax: 0});
27     match true { true => { } _ => { } }
28     regs.set(S {eax: 1});
29 }
30
31 fn test4() -> bool { let regs = @true; if true { } *regs || false }
32
33 fn test5() -> (int, int) { { } (0, 1) }
34
35 fn test6() -> bool { { } (true || false) && true }
36
37 fn test7() -> uint {
38     let regs = @0;
39     match true { true => { } _ => { } }
40     (*regs < 2) as uint
41 }
42
43 fn test8() -> int {
44     let val = @0;
45     match true {
46         true => { }
47         _    => { }
48     }
49     if *val < 1 {
50         0
51     } else {
52         1
53     }
54 }
55
56 fn test9() {
57     let regs = @Cell::new(0);
58     match true { true => { } _ => { } } regs.set(regs.get() + 1);
59 }
60
61 fn test10() -> int {
62     let regs = @vec!(0);
63     match true { true => { } _ => { } }
64     (*regs)[0]
65 }
66
67 fn test11() -> Vec<int> { if true { } vec!(1, 2) }