]> git.lizzy.rs Git - rust.git/blob - src/test/ui/coercion/coerce-to-bang.rs
Auto merge of #102458 - JohnTitor:stabilize-instruction-set, r=oli-obk
[rust.git] / src / test / ui / coercion / coerce-to-bang.rs
1 #![feature(never_type)]
2
3 fn foo(x: usize, y: !, z: usize) { }
4
5 fn call_foo_a() {
6     foo(return, 22, 44);
7     //~^ ERROR mismatched types
8 }
9
10 fn call_foo_b() {
11     // Divergence happens in the argument itself, definitely ok.
12     foo(22, return, 44);
13 }
14
15 fn call_foo_c() {
16     // This test fails because the divergence happens **after** the
17     // coercion to `!`:
18     foo(22, 44, return); //~ ERROR mismatched types
19 }
20
21 fn call_foo_d() {
22     // This test passes because `a` has type `!`:
23     let a: ! = return;
24     let b = 22;
25     let c = 44;
26     foo(a, b, c); // ... and hence a reference to `a` is expected to diverge.
27     //~^ ERROR mismatched types
28 }
29
30 fn call_foo_e() {
31     // This test probably could pass but we don't *know* that `a`
32     // has type `!` so we don't let it work.
33     let a = return;
34     let b = 22;
35     let c = 44;
36     foo(a, b, c); //~ ERROR mismatched types
37 }
38
39 fn call_foo_f() {
40     // This fn fails because `a` has type `usize`, and hence a
41     // reference to is it **not** considered to diverge.
42     let a: usize = return;
43     let b = 22;
44     let c = 44;
45     foo(a, b, c); //~ ERROR mismatched types
46 }
47
48 fn array_a() {
49     // Return is coerced to `!` just fine, but `22` cannot be.
50     let x: [!; 2] = [return, 22]; //~ ERROR mismatched types
51 }
52
53 fn array_b() {
54     // Error: divergence has not yet occurred.
55     let x: [!; 2] = [22, return]; //~ ERROR mismatched types
56 }
57
58 fn tuple_a() {
59     // No divergence at all.
60     let x: (usize, !, usize) = (22, 44, 66); //~ ERROR mismatched types
61 }
62
63 fn tuple_b() {
64     // Divergence happens before coercion: OK
65     let x: (usize, !, usize) = (return, 44, 66);
66     //~^ ERROR mismatched types
67 }
68
69 fn tuple_c() {
70     // Divergence happens before coercion: OK
71     let x: (usize, !, usize) = (22, return, 66);
72 }
73
74 fn tuple_d() {
75     // Error: divergence happens too late
76     let x: (usize, !, usize) = (22, 44, return); //~ ERROR mismatched types
77 }
78
79 fn main() { }