blob: 05ba4c8d45d5b22a74bec099d7c75177ec48ac27 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
// check-pass
#![feature(const_trait_impl, min_specialization, rustc_attrs)]
#[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 Default> const A for T {
default fn a() -> u32 {
2
}
}
impl<T: ~const Default + ~const Sup> const A for T {
default fn a() -> u32 {
3
}
}
impl<T: ~const Default + ~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() {}
|