]> git.lizzy.rs Git - rust.git/blob - src/test/ui/fn/fn-item-type.rs
Auto merge of #106349 - LeSeulArtichaut:dyn-star-tracking-issue, r=jackh726
[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     //~| found fn item `fn(_) -> _ {bar::<Vec<u8>>}`
32     //~| expected struct `String`, found struct `Vec`
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
36
37     // Make sure we distinguish between trait methods correctly.
38     eq(<u8 as Foo>::foo, <u16 as Foo>::foo);
39     //~^ ERROR mismatched types
40     //~| expected `u8`, found `u16`
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
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!
53 }