mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-17 19:14:16 +00:00
36 lines
707 B
Rust
36 lines
707 B
Rust
// Test use of min_const_fn without feature gate.
|
|
|
|
const fn foo() -> usize { 0 } // stabilized
|
|
|
|
trait Foo {
|
|
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
|
|
}
|
|
|
|
impl Foo for u32 {
|
|
const fn foo() -> u32 { 0 } //~ ERROR functions in trait impls cannot be declared const
|
|
}
|
|
|
|
trait Bar {}
|
|
|
|
impl dyn Bar {
|
|
const fn baz() -> u32 { 0 } // stabilized
|
|
}
|
|
|
|
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()] = [];
|
|
}
|