2019-09-20 18:39:13 +02:00
|
|
|
// run-pass
|
2019-09-21 16:09:38 +02:00
|
|
|
// compile-flags: -Zunleash-the-miri-inside-of-you
|
2019-09-20 18:39:13 +02:00
|
|
|
|
2019-09-21 16:09:38 +02:00
|
|
|
fn double(x: usize) -> usize { x * 2 }
|
|
|
|
const fn double_const(x: usize) -> usize { x * 2 }
|
|
|
|
|
2019-09-20 18:39:13 +02:00
|
|
|
const X: fn(usize) -> usize = double;
|
2019-11-06 00:00:00 +00:00
|
|
|
const X_CONST: fn(usize) -> usize = double_const;
|
2019-09-20 18:39:13 +02:00
|
|
|
|
2020-05-03 14:23:08 +02:00
|
|
|
const fn bar(x: usize) -> usize {
|
2020-04-29 09:53:22 +02:00
|
|
|
X(x)
|
2019-09-20 18:39:13 +02:00
|
|
|
}
|
|
|
|
|
2020-05-03 14:23:08 +02:00
|
|
|
const fn bar_const(x: usize) -> usize {
|
2020-04-29 09:53:22 +02:00
|
|
|
X_CONST(x)
|
2019-09-21 16:09:38 +02:00
|
|
|
}
|
|
|
|
|
2020-05-03 14:23:08 +02:00
|
|
|
const fn foo(x: fn(usize) -> usize, y: usize) -> usize {
|
2020-04-29 09:53:22 +02:00
|
|
|
x(y)
|
2019-09-20 18:39:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2019-09-21 16:09:38 +02:00
|
|
|
const Y: usize = bar_const(2);
|
2019-09-20 18:39:13 +02:00
|
|
|
assert_eq!(Y, 4);
|
2019-09-21 16:09:38 +02:00
|
|
|
let y = bar_const(2);
|
|
|
|
assert_eq!(y, 4);
|
|
|
|
let y = bar(2);
|
|
|
|
assert_eq!(y, 4);
|
|
|
|
|
|
|
|
const Z: usize = foo(double_const, 2);
|
2019-09-20 18:39:13 +02:00
|
|
|
assert_eq!(Z, 4);
|
2019-09-21 16:09:38 +02:00
|
|
|
let z = foo(double_const, 2);
|
|
|
|
assert_eq!(z, 4);
|
|
|
|
let z = foo(double, 2);
|
|
|
|
assert_eq!(z, 4);
|
2019-09-20 18:39:13 +02:00
|
|
|
}
|