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