2012-12-10 17:32:48 -08:00
|
|
|
// 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.
|
|
|
|
|
2011-06-16 11:56:34 -07:00
|
|
|
// error-pattern:Number is odd
|
2013-03-22 11:23:21 -07:00
|
|
|
fn even(x: uint) -> bool {
|
2011-07-27 14:19:39 +02:00
|
|
|
if x < 2u {
|
2012-08-01 17:30:05 -07:00
|
|
|
return false;
|
|
|
|
} else if x == 2u { return true; } else { return even(x - 2u); }
|
2011-06-16 11:56:34 -07:00
|
|
|
}
|
|
|
|
|
2011-12-22 14:42:52 -08:00
|
|
|
fn foo(x: uint) {
|
2012-07-13 18:43:52 -07:00
|
|
|
if even(x) {
|
2013-07-17 03:08:08 +10:00
|
|
|
info!(x);
|
2011-12-22 14:42:52 -08:00
|
|
|
} else {
|
2013-05-06 00:18:51 +02:00
|
|
|
fail!("Number is odd");
|
2011-12-22 14:42:52 -08:00
|
|
|
}
|
|
|
|
}
|
2011-06-16 11:56:34 -07:00
|
|
|
|
2011-08-19 15:16:48 -07:00
|
|
|
fn main() { foo(3u); }
|