os-rust/src/test/run-pass/weird-exprs.rs

86 lines
2.1 KiB
Rust
Raw Normal View History

// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::util;
2013-05-06 00:42:54 -04:00
// Just a grab bag of stuff that you wouldn't want to actually write.
2012-08-01 17:30:05 -07:00
fn strange() -> bool { let _x: bool = return true; }
fn funny() {
fn f(_x: ()) { }
2012-08-01 17:30:05 -07:00
f(return);
}
fn what() {
2012-08-01 17:30:05 -07:00
fn the(x: @mut bool) { return while !*x { *x = true; }; }
2012-03-26 18:35:18 -07:00
let i = @mut false;
2012-06-19 19:34:01 -07:00
let dont = {||the(i)};
dont();
2013-03-28 18:39:09 -07:00
assert!((*i));
}
fn zombiejesus() {
loop {
2012-08-01 17:30:05 -07:00
while (return) {
if (return) {
2012-08-06 12:34:08 -07:00
match (return) {
2012-08-03 19:59:04 -07:00
1 => {
2012-08-01 17:30:05 -07:00
if (return) {
return
} else {
2012-08-01 17:30:05 -07:00
return
}
}
2012-08-03 19:59:04 -07:00
_ => { return }
};
2012-08-01 17:30:05 -07:00
} else if (return) {
return;
}
}
2012-08-01 17:30:05 -07:00
if (return) { break; }
}
}
fn notsure() {
let mut _x;
let mut _y = (_x = 0) == (_x = 0);
2013-02-15 02:44:18 -08:00
let mut _z = (_x = 0) < (_x = 0);
let _a = (_x += 0) == (_x = 0);
2013-05-06 00:42:54 -04:00
let _b = util::swap(&mut _y, &mut _z) == util::swap(&mut _y, &mut _z);
}
fn canttouchthis() -> uint {
fn p() -> bool { true }
2013-03-28 18:39:09 -07:00
let _a = (assert!((true)) == (assert!(p())));
let _c = (assert!((p())) == ());
let _b: bool = (info!("{}", 0) == (return 0u));
}
fn angrydome() {
loop { if break { } }
let mut i = 0;
loop { i += 1; if i == 1 { match (continue) { 1 => { }, _ => fail!("wat") } }
2012-08-23 14:44:58 -07:00
break; }
}
fn evil_lincoln() { let _evil = info!("lincoln"); }
pub fn main() {
strange();
funny();
what();
zombiejesus();
notsure();
canttouchthis();
angrydome();
evil_lincoln();
}