rust/tests/pass/calls.rs

44 lines
817 B
Rust
Raw Normal View History

fn call() -> i32 {
fn increment(x: i32) -> i32 {
x + 1
}
increment(1)
}
2016-03-12 21:32:24 -06:00
fn factorial_recursive() -> i64 {
fn fact(n: i64) -> i64 {
if n == 0 { 1 } else { n * fact(n - 1) }
}
fact(10)
}
2016-03-12 21:32:24 -06:00
2016-03-13 19:33:26 -05:00
fn call_generic() -> (i16, bool) {
fn id<T>(t: T) -> T {
t
}
2016-03-13 19:33:26 -05:00
(id(42), id(true))
}
2016-03-12 21:32:24 -06:00
// Test calling a very simple function from the standard library.
fn cross_crate_fn_call() -> i64 {
if 1i32.is_positive() { 1 } else { 0 }
}
2016-03-15 01:45:25 -05:00
const fn foo(i: i64) -> i64 {
*&i + 1
}
2016-06-02 10:36:05 -05:00
fn const_fn_call() -> i64 {
let x = 5 + foo(5);
assert_eq!(x, 11);
x
}
2016-04-22 07:38:46 -05:00
fn main() {
assert_eq!(call(), 2);
assert_eq!(factorial_recursive(), 3628800);
2016-05-09 22:01:12 -05:00
assert_eq!(call_generic(), (42, true));
2016-04-22 07:38:46 -05:00
assert_eq!(cross_crate_fn_call(), 1);
assert_eq!(const_fn_call(), 11);
2016-04-22 07:38:46 -05:00
}