remove test for T -> ! coercion

We used to allow `T -> !` coercions (yes!! not `! -> T`) in unreachable
code. This was later removed during 2018 stabilization attempt, see:
- https://github.com/rust-lang/rust/issues/40800
- https://github.com/rust-lang/rust/pull/47630/commits/59688e119e1b9c2506fa9173728ae88eb196bf5e
- https://github.com/rust-lang/rust/issues/46325

I've kept `tests/ui/coercion/coerce-to-bang-cast.rs`, as that is a
reasonable test for us *not* having `-> !` coercions.
This commit is contained in:
Waffle Lapkin 2025-11-13 15:39:17 +01:00
parent 140832aa59
commit 3432ff9a1d
No known key found for this signature in database
2 changed files with 0 additions and 209 deletions

View file

@ -1,79 +0,0 @@
#![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() { }

View file

@ -1,130 +0,0 @@
error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:6:17
|
LL | foo(return, 22, 44);
| --- ^^ expected `!`, found integer
| |
| arguments to this function are incorrect
|
= note: expected type `!`
found type `{integer}`
note: function defined here
--> $DIR/coerce-to-bang.rs:3:4
|
LL | fn foo(x: usize, y: !, z: usize) { }
| ^^^ ----
error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:18:13
|
LL | foo(22, 44, return);
| --- ^^ expected `!`, found integer
| |
| arguments to this function are incorrect
|
= note: expected type `!`
found type `{integer}`
note: function defined here
--> $DIR/coerce-to-bang.rs:3:4
|
LL | fn foo(x: usize, y: !, z: usize) { }
| ^^^ ----
error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:26:12
|
LL | foo(a, b, c); // ... and hence a reference to `a` is expected to diverge.
| --- ^ expected `!`, found integer
| |
| arguments to this function are incorrect
|
= note: expected type `!`
found type `{integer}`
note: function defined here
--> $DIR/coerce-to-bang.rs:3:4
|
LL | fn foo(x: usize, y: !, z: usize) { }
| ^^^ ----
error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:36:12
|
LL | foo(a, b, c);
| --- ^ expected `!`, found integer
| |
| arguments to this function are incorrect
|
= note: expected type `!`
found type `{integer}`
note: function defined here
--> $DIR/coerce-to-bang.rs:3:4
|
LL | fn foo(x: usize, y: !, z: usize) { }
| ^^^ ----
error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:45:12
|
LL | foo(a, b, c);
| --- ^ expected `!`, found integer
| |
| arguments to this function are incorrect
|
= note: expected type `!`
found type `{integer}`
note: function defined here
--> $DIR/coerce-to-bang.rs:3:4
|
LL | fn foo(x: usize, y: !, z: usize) { }
| ^^^ ----
error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:50:21
|
LL | let x: [!; 2] = [return, 22];
| ------ ^^^^^^^^^^^^ expected `[!; 2]`, found `[{integer}; 2]`
| |
| expected due to this
|
= note: expected array `[!; 2]`
found array `[{integer}; 2]`
error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:55:22
|
LL | let x: [!; 2] = [22, return];
| ^^ expected `!`, found integer
|
= note: expected type `!`
found type `{integer}`
error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:60:37
|
LL | let x: (usize, !, usize) = (22, 44, 66);
| ^^ expected `!`, found integer
|
= note: expected type `!`
found type `{integer}`
error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:65:41
|
LL | let x: (usize, !, usize) = (return, 44, 66);
| ^^ expected `!`, found integer
|
= note: expected type `!`
found type `{integer}`
error[E0308]: mismatched types
--> $DIR/coerce-to-bang.rs:76:37
|
LL | let x: (usize, !, usize) = (22, 44, return);
| ^^ expected `!`, found integer
|
= note: expected type `!`
found type `{integer}`
error: aborting due to 10 previous errors
For more information about this error, try `rustc --explain E0308`.