mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-03 10:47:16 +00:00

Full list of `impl const Default` types: - () - bool - char - Cell - std::ascii::Char - usize - u8 - u16 - u32 - u64 - u128 - i8 - i16 - i32 - i64 - i128 - f16 - f32 - f64 - f128 - std::marker::PhantomData<T> - Option<T> - std::iter::Empty<T> - std::ptr::Alignment - &[T] - &mut [T] - &str - &mut str - String - Vec<T>
59 lines
940 B
Rust
59 lines
940 B
Rust
//@ known-bug: #110395
|
|
|
|
#![feature(const_trait_impl, min_specialization, rustc_attrs)]
|
|
|
|
use std::fmt::Debug;
|
|
|
|
#[rustc_specialization_trait]
|
|
#[const_trait]
|
|
pub unsafe trait Sup {
|
|
fn foo() -> u32;
|
|
}
|
|
|
|
#[rustc_specialization_trait]
|
|
#[const_trait]
|
|
pub unsafe trait Sub: [const] Sup {}
|
|
|
|
unsafe impl const Sup for u8 {
|
|
default fn foo() -> u32 {
|
|
1
|
|
}
|
|
}
|
|
|
|
unsafe impl const Sup for () {
|
|
fn foo() -> u32 {
|
|
42
|
|
}
|
|
}
|
|
|
|
unsafe impl const Sub for () {}
|
|
|
|
#[const_trait]
|
|
pub trait A {
|
|
fn a() -> u32;
|
|
}
|
|
|
|
impl<T: [const] Debug> const A for T {
|
|
default fn a() -> u32 {
|
|
2
|
|
}
|
|
}
|
|
|
|
impl<T: [const] Debug + [const] Sup> const A for T {
|
|
default fn a() -> u32 {
|
|
3
|
|
}
|
|
}
|
|
|
|
impl<T: [const] Debug + [const] Sub> const A for T {
|
|
fn a() -> u32 {
|
|
T::foo()
|
|
}
|
|
}
|
|
|
|
const _: () = assert!(<()>::a() == 42);
|
|
const _: () = assert!(<u8>::a() == 3);
|
|
const _: () = assert!(<u16>::a() == 2);
|
|
|
|
fn main() {}
|