2018-08-22 13:56:37 +00:00
|
|
|
// Test use of min_const_fn without feature gate.
|
|
|
|
|
2018-10-05 08:17:16 +00:00
|
|
|
const fn foo() -> usize { 0 } // stabilized
|
2018-08-22 13:56:37 +00:00
|
|
|
|
|
|
|
trait Foo {
|
2021-04-25 09:02:08 +00:00
|
|
|
const fn foo() -> u32; //~ ERROR functions in traits cannot be declared const
|
|
|
|
const fn bar() -> u32 { 0 } //~ ERROR functions in traits cannot be declared const
|
2018-08-22 13:56:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Foo for u32 {
|
2024-01-01 23:26:50 +00:00
|
|
|
const fn foo() -> u32 { 0 } //~ ERROR functions in trait impls cannot be declared const
|
2018-08-22 13:56:37 +00:00
|
|
|
}
|
|
|
|
|
2019-01-02 14:14:24 +00:00
|
|
|
trait Bar {}
|
|
|
|
|
|
|
|
impl dyn Bar {
|
|
|
|
const fn baz() -> u32 { 0 } // stabilized
|
|
|
|
}
|
|
|
|
|
2018-08-22 13:56:37 +00:00
|
|
|
static FOO: usize = foo();
|
|
|
|
const BAR: usize = foo();
|
|
|
|
|
|
|
|
macro_rules! constant {
|
|
|
|
($n:ident: $t:ty = $v:expr) => {
|
|
|
|
const $n: $t = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
constant! {
|
|
|
|
BAZ: usize = foo()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let x: [usize; foo()] = [];
|
|
|
|
}
|