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