Repository: rust
Issue: ICE: `called 'Result::unwrap()' on an 'Err' value: Unknown(Aligned)`
Labels: I-ICE,T-compiler,A-MIR,C-bug,S-bug-has-test

<!--
[31mICE[0m: Rustc ./B7CDE92A5B68DDD16E70A29CA83546B67D7A4F6F5CDB14A30317BDEE5442C48B.rs '' 'thread 'rustc' panicked at compiler/rustc_mir_build/src/build/expr/as_rvalue.rs:222:57: 'called `Result::unwrap()` on an `Err` value: Unknown(Aligned)'', 'thread 'rustc' panicked at compiler/rustc_mir_build/src/build/expr/as_rvalue.rs:222:57: 'called `Result::unwrap()` on an `Err` value: Unknown(Aligned)''
File: /tmp/im/B7CDE92A5B68DDD16E70A29CA83546B67D7A4F6F5CDB14A30317BDEE5442C48B.rs
-->

auto-reduced (treereduce-rust):
````rust
#[repr(simd)]
enum Aligned {
    Zero = 0,
    One = 1,
}

fn tou8(al: Aligned) -> u8 {
    al as u8
}


````

original:
````rust
// run-pass
// allows aligned custom discriminant enums to cast into other types
// See the issue #92464 for more info
#[allow(dead_code)]
#[repr(simd)]
enum Aligned {
    Zero = 0,
    One = 1,
}

fn main() {
    let aligned = Aligned::Zero;
    let fo = aligned as u8;
    println!("foo {}", fo);
    assert_eq!(fo, 0);
    println!("{}", tou8(Aligned::Zero));
    assert_eq!(tou8(Aligned::Zero), 0);
}

#[inline(never)]
fn tou8(al: Aligned) -> u8 {
    // Cast behind a function call so ConstProp does not see it
    // (so that we can test codegen).
    al as u8
}

````

Version information
````
rustc 1.78.0-nightly (340bb19fe 2024-02-14)
binary: rustc
commit-hash: 340bb19fea20fd5f9357bbfac542fad84fc7ea2b
commit-date: 2024-02-14
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

````

Command:
`/home/matthias/.rustup/toolchains/master/bin/rustc `

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Program output</strong></summary>
<p>

```
error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.SYcwJ0ZhbP03/rustc_testrunner_tmpdir_reporting.auBmqDN1Oibq/mvce.rs:9:2
  |
9 | }
  |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.SYcwJ0ZhbP03/rustc_testrunner_tmpdir_reporting.auBmqDN1Oibq/mvce.rs`

error[E0517]: attribute should be applied to a struct
 --> /tmp/icemaker_global_tempdir.SYcwJ0ZhbP03/rustc_testrunner_tmpdir_reporting.auBmqDN1Oibq/mvce.rs:1:8
  |
1 |   #[repr(simd)]
  |          ^^^^
2 | / enum Aligned {
3 | |     Zero = 0,
4 | |     One = 1,
5 | | }
  | |_- not a struct

thread 'rustc' panicked at compiler/rustc_mir_build/src/build/expr/as_rvalue.rs:222:57:
called `Result::unwrap()` on an `Err` value: Unknown(Aligned)
stack backtrace:
   0:     0x7f0dba78ce46 - std::backtrace_rs::backtrace::libunwind::trace::h741b35e6ebf0ea82
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f0dba78ce46 - std::backtrace_rs::backtrace::trace_unsynchronized::hf3b09a36cbdb818e
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f0dba78ce46 - std::sys_common::backtrace::_print_fmt::hd9ddcb56e855ae1f
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f0dba78ce46 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1d659f3f1b376713
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f0dba7dd46c - core::fmt::rt::Argument::fmt::h268aa39b6fb00372
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/core/src/fmt/rt.rs:142:9
   5:     0x7f0dba7dd46c - core::fmt::write::h3ca4c8a121ee4a21
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f0dba78087f - std::io::Write::write_fmt::hbae5643614f30ef5
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/io/mod.rs:1854:15
   7:     0x7f0dba78cbf4 - std::sys_common::backtrace::_print::h46251963e880a6db
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f0dba78cbf4 - std::sys_common::backtrace::print::hf7d8eafd5758e700
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f0dba78f93b - std::panicking::default_hook::{{closure}}::h762f7d01310422ff
  10:     0x7f0dba78f689 - std::panicking::default_hook::h6bf045830ee7f539
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/panicking.rs:292:9
  11:     0x7f0dbd5f2bac - std[3c399c9137e7035e]::panicking::update_hook::<alloc[b5118abce3d9b84a]::boxed::Box<rustc_driver_impl[aed52aad4ff697f9]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f0dba7900a0 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h183d4d6c4a9f8452
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/alloc/src/boxed.rs:2030:9
  13:     0x7f0dba7900a0 - std::panicking::rust_panic_with_hook::hf47919d70d1ff480
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/panicking.rs:785:13
  14:     0x7f0dba78fde2 - std::panicking::begin_panic_handler::{{closure}}::h5fbc7433175e9186
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/panicking.rs:659:13
  15:     0x7f0dba78d326 - std::sys_common::backtrace::__rust_end_short_backtrace::h2b0c01029bb6a245
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f0dba78fb14 - rust_begin_unwind
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/panicking.rs:647:5
  17:     0x7f0dba7d9975 - core::panicking::panic_fmt::h213e6f8381440dd9
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/core/src/panicking.rs:72:14
  18:     0x7f0dba7da023 - core::result::unwrap_failed::h2846c66592a52b33
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/core/src/result.rs:1653:5
  19:     0x7f0dbec72962 - <rustc_mir_build[b81a605d07a272cd]::build::Builder>::as_rvalue
  20:     0x7f0dbeefc114 - <rustc_mir_build[b81a605d07a272cd]::build::Builder>::expr_into_dest
  21:     0x7f0dbeefde7c - <rustc_mir_build[b81a605d07a272cd]::build::Builder>::expr_into_dest
  22:     0x7f0dbbc25273 - <rustc_mir_build[b81a605d07a272cd]::build::Builder>::ast_block_stmts
  23:     0x7f0dbeefcf0b - <rustc_mir_build[b81a605d07a272cd]::build::Builder>::expr_into_dest
  24:     0x7f0dbeefde7c - <rustc_mir_build[b81a605d07a272cd]::build::Builder>::expr_into_dest
  25:     0x7f0dbeef451d - rustc_mir_build[b81a605d07a272cd]::build::mir_build::{closure#0}
  26:     0x7f0dbeef0933 - rustc_mir_build[b81a605d07a272cd]::build::mir_built
  27:     0x7f0dbeef062b - rustc_query_impl[2b06c656d5e1ef18]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2b06c656d5e1ef18]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[70484f9a8b697519]::query::erase::Erased<[u8; 8usize]>>
  28:     0x7f0dbe9858f0 - rustc_query_system[27a374b315d29eb0]::query::plumbing::try_execute_query::<rustc_query_impl[2b06c656d5e1ef18]::DynamicConfig<rustc_query_system[27a374b315d29eb0]::query::caches::VecCache<rustc_span[193b94924c128396]::def_id::LocalDefId, rustc_middle[70484f9a8b697519]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[2b06c656d5e1ef18]::plumbing::QueryCtxt, false>
  29:     0x7f0dbe98534c - rustc_query_impl[2b06c656d5e1ef18]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  30:     0x7f0dbec75956 - rustc_mir_build[b81a605d07a272cd]::check_unsafety::check_unsafety
  31:     0x7f0dbec75761 - rustc_query_impl[2b06c656d5e1ef18]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2b06c656d5e1ef18]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[70484f9a8b697519]::query::erase::Erased<[u8; 0usize]>>
  32:     0x7f0dbefb978a - rustc_query_system[27a374b315d29eb0]::query::plumbing::try_execute_query::<rustc_query_impl[2b06c656d5e1ef18]::DynamicConfig<rustc_query_system[27a374b315d29eb0]::query::caches::VecCache<rustc_span[193b94924c128396]::def_id::LocalDefId, rustc_middle[70484f9a8b697519]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[2b06c656d5e1ef18]::plumbing::QueryCtxt, false>
  33:     0x7f0dbefb94cf - rustc_query_impl[2b06c656d5e1ef18]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
  34:     0x7f0dbf21378f - rustc_interface[85a46e65fd36dd64]::passes::analysis
  35:     0x7f0dbf2131e9 - rustc_query_impl[2b06c656d5e1ef18]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2b06c656d5e1ef18]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[70484f9a8b697519]::query::erase::Erased<[u8; 1usize]>>
  36:     0x7f0dbf7b0025 - rustc_query_system[27a374b315d29eb0]::query::plumbing::try_execute_query::<rustc_query_impl[2b06c656d5e1ef18]::DynamicConfig<rustc_query_system[27a374b315d29eb0]::query::caches::SingleCache<rustc_middle[70484f9a8b697519]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[2b06c656d5e1ef18]::plumbing::QueryCtxt, false>
  37:     0x7f0dbf7afd89 - rustc_query_impl[2b06c656d5e1ef18]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  38:     0x7f0dbf62e055 - rustc_interface[85a46e65fd36dd64]::interface::run_compiler::<core[7e3aa1eb1ad3b865]::result::Result<(), rustc_span[193b94924c128396]::ErrorGuaranteed>, rustc_driver_impl[aed52aad4ff697f9]::run_compiler::{closure#0}>::{closure#0}
  39:     0x7f0dbf7c7b58 - std[3c399c9137e7035e]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[85a46e65fd36dd64]::util::run_in_thread_with_globals<rustc_interface[85a46e65fd36dd64]::util::run_in_thread_pool_with_globals<rustc_interface[85a46e65fd36dd64]::interface::run_compiler<core[7e3aa1eb1ad3b865]::result::Result<(), rustc_span[193b94924c128396]::ErrorGuaranteed>, rustc_driver_impl[aed52aad4ff697f9]::run_compiler::{closure#0}>::{closure#0}, core[7e3aa1eb1ad3b865]::result::Result<(), rustc_span[193b94924c128396]::ErrorGuaranteed>>::{closure#0}, core[7e3aa1eb1ad3b865]::result::Result<(), rustc_span[193b94924c128396]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7e3aa1eb1ad3b865]::result::Result<(), rustc_span[193b94924c128396]::ErrorGuaranteed>>
  40:     0x7f0dbf7c7984 - <<std[3c399c9137e7035e]::thread::Builder>::spawn_unchecked_<rustc_interface[85a46e65fd36dd64]::util::run_in_thread_with_globals<rustc_interface[85a46e65fd36dd64]::util::run_in_thread_pool_with_globals<rustc_interface[85a46e65fd36dd64]::interface::run_compiler<core[7e3aa1eb1ad3b865]::result::Result<(), rustc_span[193b94924c128396]::ErrorGuaranteed>, rustc_driver_impl[aed52aad4ff697f9]::run_compiler::{closure#0}>::{closure#0}, core[7e3aa1eb1ad3b865]::result::Result<(), rustc_span[193b94924c128396]::ErrorGuaranteed>>::{closure#0}, core[7e3aa1eb1ad3b865]::result::Result<(), rustc_span[193b94924c128396]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7e3aa1eb1ad3b865]::result::Result<(), rustc_span[193b94924c128396]::ErrorGuaranteed>>::{closure#1} as core[7e3aa1eb1ad3b865]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  41:     0x7f0dba7991e5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1516af221a452bc1
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/alloc/src/boxed.rs:2016:9
  42:     0x7f0dba7991e5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hff2a9d52ad89d581
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/alloc/src/boxed.rs:2016:9
  43:     0x7f0dba7991e5 - std::sys::pal::unix::thread::Thread::new::thread_start::hf359248e8c5b2b25
                               at /rustc/340bb19fea20fd5f9357bbfac542fad84fc7ea2b/library/std/src/sys/pal/unix/thread.rs:108:17
  44:     0x7f0dba54a9eb - <unknown>
  45:     0x7f0dba5ce7cc - <unknown>
  46:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.78.0-nightly (340bb19fe 2024-02-14) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_built] building MIR for `tou8`
#1 [check_unsafety] unsafety-checking `tou8`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0517, E0601.
For more information about an error, try `rustc --explain E0517`.

```

</p>
</details>

<!--
query stack:
#0 [mir_built] building MIR for `tou8`
#1 [check_unsafety] unsafety-checking `tou8`
#2 [analysis] running analysis passes on this crate

-->



<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_ASSIGN_START -->

<!-- TRIAGEBOT_ASSIGN_DATA_START$${"user":"gurry"}$$TRIAGEBOT_ASSIGN_DATA_END -->

<!-- TRIAGEBOT_ASSIGN_END -->
<!-- TRIAGEBOT_END -->