]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/weird-exprs.rs
1eb34f9df255100a5892b6a51a94880a74669473
[rust.git] / src / test / run-pass / weird-exprs.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 #![feature(managed_boxes)]
12
13 use std::cell::Cell;
14 use std::mem::swap;
15 use std::gc::{Gc, GC};
16
17 // Just a grab bag of stuff that you wouldn't want to actually write.
18
19 fn strange() -> bool { let _x: bool = return true; }
20
21 fn funny() {
22     fn f(_x: ()) { }
23     f(return);
24 }
25
26 fn what() {
27     fn the(x: Gc<Cell<bool>>) {
28         return while !x.get() { x.set(true); };
29     }
30     let i = box(GC) Cell::new(false);
31     let dont = {||the(i)};
32     dont();
33     assert!((i.get()));
34 }
35
36 fn zombiejesus() {
37     loop {
38         while (return) {
39             if (return) {
40                 match (return) {
41                     1 => {
42                         if (return) {
43                             return
44                         } else {
45                             return
46                         }
47                     }
48                     _ => { return }
49                 };
50             } else if (return) {
51                 return;
52             }
53         }
54         if (return) { break; }
55     }
56 }
57
58 fn notsure() {
59     let mut _x;
60     let mut _y = (_x = 0) == (_x = 0);
61     let mut _z = (_x = 0) < (_x = 0);
62     let _a = (_x += 0) == (_x = 0);
63     let _b = swap(&mut _y, &mut _z) == swap(&mut _y, &mut _z);
64 }
65
66 fn canttouchthis() -> uint {
67     fn p() -> bool { true }
68     let _a = (assert!((true)) == (assert!(p())));
69     let _c = (assert!((p())) == ());
70     let _b: bool = (println!("{}", 0) == (return 0u));
71 }
72
73 fn angrydome() {
74     loop { if break { } }
75     let mut i = 0;
76     loop { i += 1; if i == 1 { match (continue) { 1 => { }, _ => fail!("wat") } }
77       break; }
78 }
79
80 fn evil_lincoln() { let _evil = println!("lincoln"); }
81
82 pub fn main() {
83     strange();
84     funny();
85     what();
86     zombiejesus();
87     notsure();
88     canttouchthis();
89     angrydome();
90     evil_lincoln();
91 }