]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Test that the types of distinct fn items are not compatible by |
2 | // default. See also `run-pass/fn-item-type-*.rs`. | |
3 | ||
54a0048b SL |
4 | fn foo<T>(x: isize) -> isize { x * 2 } |
5 | fn bar<T>(x: isize) -> isize { x * 4 } | |
1a4d82fc JJ |
6 | |
7 | fn eq<T>(x: T, y: T) { } | |
8 | ||
54a0048b SL |
9 | trait Foo { fn foo() { /* this is a default fn */ } } |
10 | impl<T> Foo for T { /* `foo` is still default here */ } | |
11 | ||
1a4d82fc | 12 | fn main() { |
54a0048b | 13 | eq(foo::<u8>, bar::<u8>); |
85aaf69f | 14 | //~^ ERROR mismatched types |
f035d41b XL |
15 | //~| expected fn item `fn(_) -> _ {foo::<u8>}` |
16 | //~| found fn item `fn(_) -> _ {bar::<u8>}` | |
17 | //~| expected fn item, found a different fn item | |
18 | //~| different `fn` items always have unique types, even if their signatures are the same | |
19 | //~| change the expected type to be function pointer | |
20 | //~| if the expected type is due to type inference, cast the expected `fn` to a function pointer | |
54a0048b SL |
21 | |
22 | eq(foo::<u8>, foo::<i8>); | |
23 | //~^ ERROR mismatched types | |
60c5eb7d | 24 | //~| expected `u8`, found `i8` |
f035d41b XL |
25 | //~| different `fn` items always have unique types, even if their signatures are the same |
26 | //~| change the expected type to be function pointer | |
27 | //~| if the expected type is due to type inference, cast the expected `fn` to a function pointer | |
54a0048b SL |
28 | |
29 | eq(bar::<String>, bar::<Vec<u8>>); | |
30 | //~^ ERROR mismatched types | |
1b1a35ee XL |
31 | //~| found fn item `fn(_) -> _ {bar::<Vec<u8>>}` |
32 | //~| expected struct `String`, found struct `Vec` | |
f035d41b XL |
33 | //~| different `fn` items always have unique types, even if their signatures are the same |
34 | //~| change the expected type to be function pointer | |
35 | //~| if the expected type is due to type inference, cast the expected `fn` to a function pointer | |
54a0048b SL |
36 | |
37 | // Make sure we distinguish between trait methods correctly. | |
38 | eq(<u8 as Foo>::foo, <u16 as Foo>::foo); | |
39 | //~^ ERROR mismatched types | |
60c5eb7d | 40 | //~| expected `u8`, found `u16` |
f035d41b XL |
41 | //~| different `fn` items always have unique types, even if their signatures are the same |
42 | //~| change the expected type to be function pointer | |
43 | //~| if the expected type is due to type inference, cast the expected `fn` to a function pointer | |
44 | ||
45 | eq(foo::<u8>, bar::<u8> as fn(isize) -> isize); | |
46 | //~^ ERROR mismatched types | |
f035d41b XL |
47 | //~| found fn pointer `fn(_) -> _` |
48 | //~| expected fn item, found fn pointer | |
49 | //~| change the expected type to be function pointer | |
50 | //~| if the expected type is due to type inference, cast the expected `fn` to a function pointer | |
51 | ||
52 | eq(foo::<u8> as fn(isize) -> isize, bar::<u8>); // ok! | |
1a4d82fc | 53 | } |