mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-18 03:25:55 +00:00
37 lines
751 B
Rust
37 lines
751 B
Rust
// run-pass
|
|
// compile-flags: -Zunleash-the-miri-inside-of-you
|
|
|
|
fn double(x: usize) -> usize { x * 2 }
|
|
const fn double_const(x: usize) -> usize { x * 2 }
|
|
|
|
const X: fn(usize) -> usize = double;
|
|
const X_CONST: fn(usize) -> usize = double_const;
|
|
|
|
const fn bar(x: usize) -> usize {
|
|
X(x)
|
|
}
|
|
|
|
const fn bar_const(x: usize) -> usize {
|
|
X_CONST(x)
|
|
}
|
|
|
|
const fn foo(x: fn(usize) -> usize, y: usize) -> usize {
|
|
x(y)
|
|
}
|
|
|
|
fn main() {
|
|
const Y: usize = bar_const(2);
|
|
assert_eq!(Y, 4);
|
|
let y = bar_const(2);
|
|
assert_eq!(y, 4);
|
|
let y = bar(2);
|
|
assert_eq!(y, 4);
|
|
|
|
const Z: usize = foo(double_const, 2);
|
|
assert_eq!(Z, 4);
|
|
let z = foo(double_const, 2);
|
|
assert_eq!(z, 4);
|
|
let z = foo(double, 2);
|
|
assert_eq!(z, 4);
|
|
}
|