]> git.lizzy.rs Git - rust.git/blob - src/test/ui/fn/fn-item-type.rs
Merge commit 'b7f3f7f6082679da2da9a0b3faf1b5adef3afd3b' into clippyup
[rust.git] / src / test / ui / fn / fn-item-type.rs
1 // Test that the types of distinct fn items are not compatible by
2 // default. See also `run-pass/fn-item-type-*.rs`.
3
4 fn foo<T>(x: isize) -> isize { x * 2 }
5 fn bar<T>(x: isize) -> isize { x * 4 }
6
7 fn eq<T>(x: T, y: T) { }
8
9 trait Foo { fn foo() { /* this is a default fn */ } }
10 impl<T> Foo for T { /* `foo` is still default here */ }
11
12 fn main() {
13     eq(foo::<u8>, bar::<u8>);
14     //~^ ERROR mismatched types
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
21
22     eq(foo::<u8>, foo::<i8>);
23     //~^ ERROR mismatched types
24     //~| expected `u8`, found `i8`
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
28
29     eq(bar::<String>, bar::<Vec<u8>>);
30     //~^ ERROR mismatched types
31     //~| expected fn item `fn(_) -> _ {bar::<String>}`
32     //~| found fn item `fn(_) -> _ {bar::<Vec<u8>>}`
33     //~| expected struct `String`, found struct `Vec`
34     //~| different `fn` items always have unique types, even if their signatures are the same
35     //~| change the expected type to be function pointer
36     //~| if the expected type is due to type inference, cast the expected `fn` to a function pointer
37
38     // Make sure we distinguish between trait methods correctly.
39     eq(<u8 as Foo>::foo, <u16 as Foo>::foo);
40     //~^ ERROR mismatched types
41     //~| expected `u8`, found `u16`
42     //~| different `fn` items always have unique types, even if their signatures are the same
43     //~| change the expected type to be function pointer
44     //~| if the expected type is due to type inference, cast the expected `fn` to a function pointer
45
46     eq(foo::<u8>, bar::<u8> as fn(isize) -> isize);
47     //~^ ERROR mismatched types
48     //~| expected fn item `fn(_) -> _ {foo::<u8>}`
49     //~| found fn pointer `fn(_) -> _`
50     //~| expected fn item, found fn pointer
51     //~| change the expected type to be function pointer
52     //~| if the expected type is due to type inference, cast the expected `fn` to a function pointer
53
54     eq(foo::<u8> as fn(isize) -> isize, bar::<u8>); // ok!
55 }