1 #![feature(never_type)]
2 
foo(x: usize, y: !, z: usize)3 fn foo(x: usize, y: !, z: usize) { }
4 
call_foo_a()5 fn call_foo_a() {
6     foo(return, 22, 44);
7     //~^ ERROR mismatched types
8 }
9 
call_foo_b()10 fn call_foo_b() {
11     // Divergence happens in the argument itself, definitely ok.
12     foo(22, return, 44);
13 }
14 
call_foo_c()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 
call_foo_d()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 
call_foo_e()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 
call_foo_f()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 
array_a()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 
array_b()53 fn array_b() {
54     // Error: divergence has not yet occurred.
55     let x: [!; 2] = [22, return]; //~ ERROR mismatched types
56 }
57 
tuple_a()58 fn tuple_a() {
59     // No divergence at all.
60     let x: (usize, !, usize) = (22, 44, 66); //~ ERROR mismatched types
61 }
62 
tuple_b()63 fn tuple_b() {
64     // Divergence happens before coercion: OK
65     let x: (usize, !, usize) = (return, 44, 66);
66     //~^ ERROR mismatched types
67 }
68 
tuple_c()69 fn tuple_c() {
70     // Divergence happens before coercion: OK
71     let x: (usize, !, usize) = (22, return, 66);
72 }
73 
tuple_d()74 fn tuple_d() {
75     // Error: divergence happens too late
76     let x: (usize, !, usize) = (22, 44, return); //~ ERROR mismatched types
77 }
78 
main()79 fn main() { }
80