|
| 1 | +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +#![feature(never_type)] |
| 12 | + |
| 13 | +fn foo(x: usize, y: !, z: usize) { } |
| 14 | + |
| 15 | +fn call_foo_a() { |
| 16 | + // FIXME(#40800) -- accepted beacuse divergence happens **before** |
| 17 | + // the coercion to `!`, but within same expression. Not clear that |
| 18 | + // these are the rules we want. |
| 19 | + foo(return, 22, 44); |
| 20 | +} |
| 21 | + |
| 22 | +fn call_foo_b() { |
| 23 | + // Divergence happens in the argument itself, definitely ok. |
| 24 | + foo(22, return, 44); |
| 25 | +} |
| 26 | + |
| 27 | +fn call_foo_c() { |
| 28 | + // This test fails because the divergence happens **after** the |
| 29 | + // coercion to `!`: |
| 30 | + foo(22, 44, return); //~ ERROR mismatched types |
| 31 | +} |
| 32 | + |
| 33 | +fn call_foo_d() { |
| 34 | + // This test passes because `a` has type `!`: |
| 35 | + let a: ! = return; |
| 36 | + let b = 22; |
| 37 | + let c = 44; |
| 38 | + foo(a, b, c); // ... and hence a reference to `a` is expected to diverge. |
| 39 | +} |
| 40 | + |
| 41 | +fn call_foo_e() { |
| 42 | + // This test probably could pass but we don't *know* that `a` |
| 43 | + // has type `!` so we don't let it work. |
| 44 | + let a = return; |
| 45 | + let b = 22; |
| 46 | + let c = 44; |
| 47 | + foo(a, b, c); //~ ERROR mismatched types |
| 48 | +} |
| 49 | + |
| 50 | +fn call_foo_f() { |
| 51 | + // This fn fails because `a` has type `usize`, and hence a |
| 52 | + // reference to is it **not** considered to diverge. |
| 53 | + let a: usize = return; |
| 54 | + let b = 22; |
| 55 | + let c = 44; |
| 56 | + foo(a, b, c); //~ ERROR mismatched types |
| 57 | +} |
| 58 | + |
| 59 | +fn array_a() { |
| 60 | + // Accepted: return is coerced to `!` just fine, and then `22` can be |
| 61 | + // because we already diverged. |
| 62 | + let x: [!; 2] = [return, 22]; |
| 63 | +} |
| 64 | + |
| 65 | +fn array_b() { |
| 66 | + // Error: divergence has not yet occurred. |
| 67 | + let x: [!; 2] = [22, return]; //~ ERROR mismatched types |
| 68 | +} |
| 69 | + |
| 70 | +fn tuple_a() { |
| 71 | + // No divergence at all. |
| 72 | + let x: (usize, !, usize) = (22, 44, 66); //~ ERROR mismatched types |
| 73 | +} |
| 74 | + |
| 75 | +fn tuple_b() { |
| 76 | + // Divergence happens before coercion: OK |
| 77 | + let x: (usize, !, usize) = (return, 44, 66); |
| 78 | +} |
| 79 | + |
| 80 | +fn tuple_c() { |
| 81 | + // Divergence happens before coercion: OK |
| 82 | + let x: (usize, !, usize) = (22, return, 66); |
| 83 | +} |
| 84 | + |
| 85 | +fn tuple_d() { |
| 86 | + // Error: divergence happens too late |
| 87 | + let x: (usize, !, usize) = (22, 44, return); //~ ERROR mismatched types |
| 88 | +} |
| 89 | + |
| 90 | +fn main() { } |
0 commit comments