2018-08-30 14:18:55 +02:00
|
|
|
//@ run-pass
|
2019-01-03 13:25:49 +01:00
|
|
|
|
2015-01-20 15:45:07 -08:00
|
|
|
use std::fmt::Debug;
|
2014-10-09 17:19:50 -04:00
|
|
|
trait MyTrait {
|
|
|
|
fn get(&self) -> Self;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> MyTrait for T
|
|
|
|
where T : Default
|
|
|
|
{
|
|
|
|
fn get(&self) -> T {
|
|
|
|
Default::default()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-24 16:36:30 -05:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
2014-10-09 17:19:50 -04:00
|
|
|
struct MyType {
|
2015-03-25 17:06:52 -07:00
|
|
|
dummy: usize
|
2014-10-09 17:19:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl MyTrait for MyType {
|
|
|
|
fn get(&self) -> MyType { (*self).clone() }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_eq<M>(m: M, n: M)
|
2015-01-20 15:45:07 -08:00
|
|
|
where M : MyTrait + Debug + PartialEq
|
2014-10-09 17:19:50 -04:00
|
|
|
{
|
|
|
|
assert_eq!(m.get(), n);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
2015-02-18 05:42:01 -05:00
|
|
|
test_eq(0_usize, 0_usize);
|
2014-10-09 17:19:50 -04:00
|
|
|
|
|
|
|
let value = MyType { dummy: 256 + 22 };
|
|
|
|
test_eq(value, value);
|
|
|
|
}
|