]> git.lizzy.rs Git - rust.git/blob - tests/ui/methods/method-where-clause.rs
Rollup merge of #107125 - WaffleLapkin:expect_an_item_in_your_hir_by_the_next_morning...
[rust.git] / tests / ui / methods / method-where-clause.rs
1 // run-pass
2 // Test that we can use method notation to call methods based on a
3 // where clause type, and not only type parameters.
4
5
6 trait Foo {
7     fn foo(&self) -> i32;
8 }
9
10 impl Foo for Option<i32>
11 {
12     fn foo(&self) -> i32 {
13         self.unwrap_or(22)
14     }
15 }
16
17 impl Foo for Option<u32>
18 {
19     fn foo(&self) -> i32 {
20         self.unwrap_or(22) as i32
21     }
22 }
23
24 fn check<T>(x: Option<T>) -> (i32, i32)
25     where Option<T> : Foo
26 {
27     let y: Option<T> = None;
28     (x.foo(), y.foo())
29 }
30
31 fn main() {
32     assert_eq!(check(Some(23u32)), (23, 22));
33     assert_eq!(check(Some(23)), (23, 22));
34 }