|
11 | 11 | // Test that the types of distinct fn items are not compatible by
|
12 | 12 | // default. See also `run-pass/fn-item-type-*.rs`.
|
13 | 13 |
|
14 |
| -fn foo(x: isize) -> isize { x * 2 } |
15 |
| -fn bar(x: isize) -> isize { x * 4 } |
| 14 | +fn foo<T>(x: isize) -> isize { x * 2 } |
| 15 | +fn bar<T>(x: isize) -> isize { x * 4 } |
16 | 16 |
|
17 | 17 | fn eq<T>(x: T, y: T) { }
|
18 | 18 |
|
| 19 | +trait Foo { fn foo() { /* this is a default fn */ } } |
| 20 | +impl<T> Foo for T { /* `foo` is still default here */ } |
| 21 | + |
19 | 22 | fn main() {
|
20 |
| - let f = if true { foo } else { bar }; |
| 23 | + let f = if true { foo::<u8> } else { bar::<u8> }; |
21 | 24 | //~^ ERROR if and else have incompatible types
|
22 |
| - //~| expected `fn(isize) -> isize {foo}` |
23 |
| - //~| found `fn(isize) -> isize {bar}` |
| 25 | + //~| expected `fn(isize) -> isize {foo::<u8>}` |
| 26 | + //~| found `fn(isize) -> isize {bar::<u8>}` |
24 | 27 | //~| expected fn item,
|
25 | 28 | //~| found a different fn item
|
26 | 29 |
|
27 |
| - eq(foo, bar); |
| 30 | + eq(foo::<u8>, bar::<u8>); |
28 | 31 | //~^ ERROR mismatched types
|
29 |
| - //~| expected `fn(isize) -> isize {foo}` |
30 |
| - //~| found `fn(isize) -> isize {bar}` |
| 32 | + //~| expected `fn(isize) -> isize {foo::<u8>}` |
| 33 | + //~| found `fn(isize) -> isize {bar::<u8>}` |
31 | 34 | //~| expected fn item
|
32 | 35 | //~| found a different fn item
|
| 36 | + |
| 37 | + eq(foo::<u8>, foo::<i8>); |
| 38 | + //~^ ERROR mismatched types |
| 39 | + //~| expected `fn(isize) -> isize {foo::<u8>}` |
| 40 | + //~| found `fn(isize) -> isize {foo::<i8>}` |
| 41 | + |
| 42 | + eq(bar::<String>, bar::<Vec<u8>>); |
| 43 | + //~^ ERROR mismatched types |
| 44 | + //~| expected `fn(isize) -> isize {bar::<collections::string::String>}` |
| 45 | + //~| found `fn(isize) -> isize {bar::<collections::vec::Vec<u8>>}` |
| 46 | + //~| expected struct `collections::string::String` |
| 47 | + //~| found struct `collections::vec::Vec` |
| 48 | + |
| 49 | + // Make sure we distinguish between trait methods correctly. |
| 50 | + eq(<u8 as Foo>::foo, <u16 as Foo>::foo); |
| 51 | + //~^ ERROR mismatched types |
| 52 | + //~| expected `fn() {Foo::foo}` |
| 53 | + //~| found `fn() {Foo::foo}` |
33 | 54 | }
|
0 commit comments