about summary refs log tree commit diff
path: root/tests/ui/specialization/trait-specialization-default-methods-55380.rs
blob: b3d79fb5ffb6ac1ca9ef49e219f3329b828e4e44 (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
// https://github.com/rust-lang/rust/issues/55380
//@ run-pass
#![feature(specialization)]
//~^ WARN the feature `specialization` is incomplete

pub trait Foo {
    fn abc() -> u32;
    fn def() -> u32;
}

pub trait Marker {}

impl Marker for () {}

impl<T> Foo for T {
    default fn abc() -> u32 { 16 }
    default fn def() -> u32 { 42 }
}

impl<T: Marker> Foo for T {
    fn def() -> u32 {
        Self::abc()
    }
}

fn main() {
   assert_eq!(<()>::def(), 16);
   assert_eq!(<i32>::def(), 42);
}