mirror of
https://github.com/rust-lang/rust
synced 2024-09-15 22:50:55 +00:00
38 lines
624 B
Rust
38 lines
624 B
Rust
//@ run-pass
|
|
|
|
trait ConstDefault {
|
|
const DEFAULT: Self;
|
|
}
|
|
|
|
#[derive(PartialEq)]
|
|
enum E {
|
|
V(i32),
|
|
W(usize),
|
|
}
|
|
|
|
impl ConstDefault for E {
|
|
const DEFAULT: Self = Self::V(23);
|
|
}
|
|
|
|
impl ConstDefault for Option<i32> {
|
|
const DEFAULT: Self = Self::Some(23);
|
|
}
|
|
|
|
impl E {
|
|
const NON_DEFAULT: Self = Self::W(12);
|
|
const fn local_fn() -> Self {
|
|
Self::V(23)
|
|
}
|
|
}
|
|
|
|
const fn explicit_qpath() -> E {
|
|
let _x = <Option<usize>>::Some(23);
|
|
<E>::W(12)
|
|
}
|
|
|
|
fn main() {
|
|
assert!(E::DEFAULT == E::local_fn());
|
|
assert!(Option::DEFAULT == Some(23));
|
|
assert!(E::NON_DEFAULT == explicit_qpath());
|
|
}
|