2019-07-27 00:54:25 +03:00
|
|
|
// run-pass
|
2015-01-28 05:13:43 -05:00
|
|
|
// Test for using an object with an associated type binding as the
|
|
|
|
// instantiation for a generic type with a bound.
|
|
|
|
|
2015-03-22 13:13:15 -07:00
|
|
|
|
2015-01-28 05:13:43 -05:00
|
|
|
trait SomeTrait {
|
|
|
|
type SomeType;
|
|
|
|
|
|
|
|
fn get(&self) -> Self::SomeType;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_int<T:SomeTrait<SomeType=i32>+?Sized>(x: &T) -> i32 {
|
|
|
|
x.get()
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SomeTrait for i32 {
|
|
|
|
type SomeType = i32;
|
|
|
|
fn get(&self) -> i32 {
|
|
|
|
*self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2015-03-03 10:42:26 +02:00
|
|
|
let x = 22;
|
2019-05-28 14:47:21 -04:00
|
|
|
let x1: &dyn SomeTrait<SomeType=i32> = &x;
|
2015-01-28 05:13:43 -05:00
|
|
|
let y = get_int(x1);
|
|
|
|
assert_eq!(x, y);
|
|
|
|
}
|