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