2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2015-01-05 15:01:04 -06:00
|
|
|
// Test that we can use method notation to call methods based on a
|
|
|
|
// where clause type, and not only type parameters.
|
|
|
|
|
2015-03-22 15:13:15 -05:00
|
|
|
|
2015-01-05 15:01:04 -06:00
|
|
|
trait Foo {
|
2015-01-25 15:05:03 -06:00
|
|
|
fn foo(&self) -> i32;
|
2015-01-05 15:01:04 -06:00
|
|
|
}
|
|
|
|
|
2015-01-25 15:05:03 -06:00
|
|
|
impl Foo for Option<i32>
|
2015-01-05 15:01:04 -06:00
|
|
|
{
|
2015-01-25 15:05:03 -06:00
|
|
|
fn foo(&self) -> i32 {
|
2015-01-05 15:01:04 -06:00
|
|
|
self.unwrap_or(22)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-25 15:05:03 -06:00
|
|
|
impl Foo for Option<u32>
|
2015-01-05 15:01:04 -06:00
|
|
|
{
|
2015-01-25 15:05:03 -06:00
|
|
|
fn foo(&self) -> i32 {
|
|
|
|
self.unwrap_or(22) as i32
|
2015-01-05 15:01:04 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-25 15:05:03 -06:00
|
|
|
fn check<T>(x: Option<T>) -> (i32, i32)
|
2015-01-05 15:01:04 -06:00
|
|
|
where Option<T> : Foo
|
|
|
|
{
|
|
|
|
let y: Option<T> = None;
|
|
|
|
(x.foo(), y.foo())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2015-01-25 15:05:03 -06:00
|
|
|
assert_eq!(check(Some(23u32)), (23, 22));
|
|
|
|
assert_eq!(check(Some(23)), (23, 22));
|
2015-01-05 15:01:04 -06:00
|
|
|
}
|