summaryrefslogtreecommitdiffstats
path: root/tests/ui/coercion/coerce-to-bang.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/coercion/coerce-to-bang.rs
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/coercion/coerce-to-bang.rs')
-rw-r--r--tests/ui/coercion/coerce-to-bang.rs79
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/ui/coercion/coerce-to-bang.rs b/tests/ui/coercion/coerce-to-bang.rs
new file mode 100644
index 000000000..1e06934d0
--- /dev/null
+++ b/tests/ui/coercion/coerce-to-bang.rs
@@ -0,0 +1,79 @@
+#![feature(never_type)]
+
+fn foo(x: usize, y: !, z: usize) { }
+
+fn call_foo_a() {
+ foo(return, 22, 44);
+ //~^ ERROR mismatched types
+}
+
+fn call_foo_b() {
+ // Divergence happens in the argument itself, definitely ok.
+ foo(22, return, 44);
+}
+
+fn call_foo_c() {
+ // This test fails because the divergence happens **after** the
+ // coercion to `!`:
+ foo(22, 44, return); //~ ERROR mismatched types
+}
+
+fn call_foo_d() {
+ // This test passes because `a` has type `!`:
+ let a: ! = return;
+ let b = 22;
+ let c = 44;
+ foo(a, b, c); // ... and hence a reference to `a` is expected to diverge.
+ //~^ ERROR mismatched types
+}
+
+fn call_foo_e() {
+ // This test probably could pass but we don't *know* that `a`
+ // has type `!` so we don't let it work.
+ let a = return;
+ let b = 22;
+ let c = 44;
+ foo(a, b, c); //~ ERROR mismatched types
+}
+
+fn call_foo_f() {
+ // This fn fails because `a` has type `usize`, and hence a
+ // reference to is it **not** considered to diverge.
+ let a: usize = return;
+ let b = 22;
+ let c = 44;
+ foo(a, b, c); //~ ERROR mismatched types
+}
+
+fn array_a() {
+ // Return is coerced to `!` just fine, but `22` cannot be.
+ let x: [!; 2] = [return, 22]; //~ ERROR mismatched types
+}
+
+fn array_b() {
+ // Error: divergence has not yet occurred.
+ let x: [!; 2] = [22, return]; //~ ERROR mismatched types
+}
+
+fn tuple_a() {
+ // No divergence at all.
+ let x: (usize, !, usize) = (22, 44, 66); //~ ERROR mismatched types
+}
+
+fn tuple_b() {
+ // Divergence happens before coercion: OK
+ let x: (usize, !, usize) = (return, 44, 66);
+ //~^ ERROR mismatched types
+}
+
+fn tuple_c() {
+ // Divergence happens before coercion: OK
+ let x: (usize, !, usize) = (22, return, 66);
+}
+
+fn tuple_d() {
+ // Error: divergence happens too late
+ let x: (usize, !, usize) = (22, 44, return); //~ ERROR mismatched types
+}
+
+fn main() { }