rust/src/test/ui/feature-gates/feature-gate-min_const_fn.rs

36 lines
777 B
Rust
Raw Normal View History

// Test use of min_const_fn without feature gate.
2018-10-05 08:17:16 +00:00
const fn foo() -> usize { 0 } // stabilized
trait Foo {
const fn foo() -> u32; //~ ERROR const fn is unstable
//~| ERROR trait fns cannot be declared const
const fn bar() -> u32 { 0 } //~ ERROR const fn is unstable
//~| ERROR trait fns cannot be declared const
}
impl Foo {
2018-10-05 08:17:16 +00:00
const fn baz() -> u32 { 0 } // stabilized
}
impl Foo for u32 {
2018-10-05 08:17:16 +00:00
const fn foo() -> u32 { 0 } //~ ERROR trait fns cannot be declared const
}
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()] = [];
}