2020-05-17 08:22:48 +00:00
|
|
|
#![feature(specialization)] //~ WARN the feature `specialization` is incomplete
|
2016-08-10 21:04:43 +00:00
|
|
|
|
|
|
|
trait Foo: Copy + ToString {}
|
|
|
|
|
|
|
|
impl<T: Copy + ToString> Foo for T {}
|
|
|
|
|
|
|
|
fn hide<T: Foo>(x: T) -> impl Foo {
|
|
|
|
x
|
|
|
|
}
|
|
|
|
|
|
|
|
fn two(x: bool) -> impl Foo {
|
|
|
|
if x {
|
|
|
|
return 1_i32;
|
|
|
|
}
|
|
|
|
0_u32
|
|
|
|
//~^ ERROR mismatched types
|
2019-11-15 17:37:01 +00:00
|
|
|
//~| expected `i32`, found `u32`
|
2016-08-10 21:04:43 +00:00
|
|
|
}
|
|
|
|
|
2022-01-29 23:34:06 +00:00
|
|
|
fn sum_to(n: u32) -> impl Foo {
|
2022-02-11 07:18:06 +00:00
|
|
|
if n == 0 {
|
2016-08-10 21:04:43 +00:00
|
|
|
0
|
|
|
|
} else {
|
|
|
|
n + sum_to(n - 1)
|
2018-01-20 09:33:39 +00:00
|
|
|
//~^ ERROR cannot add `impl Foo` to `u32`
|
2016-08-10 21:04:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait Leak: Sized {
|
|
|
|
type T;
|
|
|
|
fn leak(self) -> Self::T;
|
|
|
|
}
|
|
|
|
impl<T> Leak for T {
|
|
|
|
default type T = ();
|
|
|
|
default fn leak(self) -> Self::T { panic!() }
|
|
|
|
}
|
|
|
|
impl Leak for i32 {
|
|
|
|
type T = i32;
|
|
|
|
fn leak(self) -> i32 { self }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
}
|