I tried this code:
struct Foo {
bar: u8
}
fn main() {
let Foo { ref bar } = panic!();
}
I expected to see this happen: The code should compile successfully by coercing the ! from panic!() to Foo.
Instead, this happened: rustc produces the following error:
error[E0308]: mismatched types
--> src/main.rs:6:9
|
6 | let Foo { ref bar } = panic!();
| ^^^^^^^^^^^^^^^ -------- this expression has type `!`
| |
| expected `!`, found `Foo`
|
= note: expected type `!`
found struct `Foo`
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (bin "playground") due to previous error
The code compiles successfully if the ref keyword is removed.
Meta
rustc --version --verbose:
rustc 1.76.0-nightly (2b603f95a 2023-11-12)
binary: rustc
commit-hash: 2b603f95a48f10f931a61dd208fe3e5ffd64e491
commit-date: 2023-11-12
host: x86_64-unknown-linux-gnu
release: 1.76.0-nightly
LLVM version: 17.0.4
I tried this code:
I expected to see this happen: The code should compile successfully by coercing the
!frompanic!()toFoo.Instead, this happened: rustc produces the following error:
The code compiles successfully if the
refkeyword is removed.Meta
rustc --version --verbose: