Repository: rust
Issue: ICE: thread 'rustc' panicked at 'assertion failed: `(left == right)`   left: `2`,  right: `1`', compiler/rustc_middle/src/mir/mod.rs:474:13
Labels: I-ICE,E-needs-test,T-compiler,C-bug

### Code

Note: requires full build (ie, `cargo check` doesn't trigger it)
```Rust
// lib.rs
pub struct S;

// n.b *has* to be an associated const.
impl S {
    pub const CONST: u8 = panic!();
}

// inner types can be anything(?) outer types must be option.
fn f(_: Option<()>, _: Option<u8>) {}

pub fn ice() {
    // "sandwich" is required. (arms on both sides of the middle one)
    match 0 {
        0 => {
            f(None, None);
        }
        1 => {
            S::CONST;
        }
        _ => {}
    };
}
```

### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
(stable)
```
rustc 1.57.0 (f1edd0429 2021-11-29)
binary: rustc
commit-hash: f1edd0429582dd29cccacaf50fd134b05593bd9c
commit-date: 2021-11-29
host: x86_64-unknown-linux-gnu
release: 1.57.0
LLVM version: 13.0.0
```
(beta)
```
rustc 1.58.0-beta.1 (426b94d7d 2021-11-29)
binary: rustc
commit-hash: 426b94d7df183ac00ed4492541d92855181e9c4e
commit-date: 2021-11-29
host: x86_64-unknown-linux-gnu
release: 1.58.0-beta.1
LLVM version: 13.0.0
```
(latest nightly as of right now)
```
rustc --version --verbose
rustc 1.59.0-nightly (532d2b14c 2021-12-03)
binary: rustc
commit-hash: 532d2b14c05f9bc20b2d27cbb5f4550d28343a36
commit-date: 2021-12-03
host: x86_64-unknown-linux-gnu
release: 1.59.0-nightly
LLVM version: 13.0.0
```

### Error output

```
cargo build
   Compiling ribit v0.1.0 (/home/sr/ghq/github.com/izik1/ribit)
warning: path statement with no effect
  --> src/lib.rs:18:13
   |
18 |             S::CONST;
   |             ^^^^^^^^^
   |
   = note: `#[warn(path_statements)]` on by default

error[E0080]: evaluation of constant value failed
 --> src/lib.rs:5:27
  |
5 |     pub const CONST: u8 = panic!();
  |                           ^^^^^^^^ the evaluated program panicked at 'explicit panic', src/lib.rs:5:27
  |
  = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)

thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `2`,
 right: `1`', compiler/rustc_middle/src/mir/mod.rs:474:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: 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.59.0-nightly (532d2b14c 2021-12-03) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [optimized_mir] optimizing MIR for `ice`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
For more information about this error, try `rustc --explain E0080`.
warning: `ribit` (lib) generated 1 warning
error: could not compile `ribit` due to previous error; 1 warning emitted
```

<!--
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>Backtrace</strong></summary>
<p>

```
thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `2`,
 right: `1`', compiler/rustc_middle/src/mir/mod.rs:474:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/532d2b14c05f9bc20b2d27cbb5f4550d28343a36/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/532d2b14c05f9bc20b2d27cbb5f4550d28343a36/library/core/src/panicking.rs:107:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed::<usize, usize>
   4: <rustc_middle::mir::Body>::source_info
   5: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_mir_transform::const_prop::ConstPropMachine>>::generate_stacktrace
   6: <rustc_const_eval::const_eval::error::ConstEvalErr>::new::<rustc_mir_transform::const_prop::ConstPropMachine>
   7: <rustc_mir_transform::const_prop::ConstPropagator as rustc_middle::mir::visit::MutVisitor>::visit_body
   8: <rustc_mir_transform::const_prop::ConstProp as rustc_middle::mir::MirPass>::run_pass
   9: rustc_mir_transform::run_passes
  10: rustc_mir_transform::optimized_mir
  11: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::def_id::DefId, &rustc_middle::mir::Body>
  12: rustc_data_structures::stack::ensure_sufficient_stack::<(&rustc_middle::mir::Body, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, rustc_span::def_id::DefId, &rustc_middle::mir::Body>::{closure#3}>
  13: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, &rustc_middle::mir::Body>>
  14: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::optimized_mir
  15: <rustc_middle::ty::context::TyCtxt>::instance_mir
  16: rustc_monomorphize::collector::collect_neighbours
  17: rustc_monomorphize::collector::collect_items_rec
  18: <rustc_session::session::Session>::time::<(), rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}>
  19: rustc_monomorphize::collector::collect_crate_mono_items
  20: rustc_monomorphize::partitioning::collect_and_partition_mono_items
  21: <rustc_middle::dep_graph::dep_node::DepKind as rustc_query_system::dep_graph::DepKind>::with_deps::<<rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task_impl<rustc_middle::ty::context::TyCtxt, (), (&std::collections::hash::set::HashSet<rustc_span::def_id::DefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, &[rustc_middle::mir::mono::CodegenUnit])>::{closure#0}, (&std::collections::hash::set::HashSet<rustc_span::def_id::DefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, &[rustc_middle::mir::mono::CodegenUnit])>
  22: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), (&std::collections::hash::set::HashSet<rustc_span::def_id::DefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, &[rustc_middle::mir::mono::CodegenUnit])>
  23: rustc_data_structures::stack::ensure_sufficient_stack::<((&std::collections::hash::set::HashSet<rustc_span::def_id::DefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, &[rustc_middle::mir::mono::CodegenUnit]), rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, (), (&std::collections::hash::set::HashSet<rustc_span::def_id::DefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, &[rustc_middle::mir::mono::CodegenUnit])>::{closure#3}>
  24: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), (&std::collections::hash::set::HashSet<rustc_span::def_id::DefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, &[rustc_middle::mir::mono::CodegenUnit])>>
  25: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::collect_and_partition_mono_items, rustc_query_impl::plumbing::QueryCtxt>
  26: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::collect_and_partition_mono_items
  27: rustc_codegen_ssa::back::symbol_export::exported_symbols_provider_local
  28: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::def_id::CrateNum, &[(rustc_middle::middle::exported_symbols::ExportedSymbol, rustc_middle::middle::exported_symbols::SymbolExportLevel)]>
  29: rustc_data_structures::stack::ensure_sufficient_stack::<(&[(rustc_middle::middle::exported_symbols::ExportedSymbol, rustc_middle::middle::exported_symbols::SymbolExportLevel)], rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, rustc_span::def_id::CrateNum, &[(rustc_middle::middle::exported_symbols::ExportedSymbol, rustc_middle::middle::exported_symbols::SymbolExportLevel)]>::{closure#3}>
  30: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::CrateNum, &[(rustc_middle::middle::exported_symbols::ExportedSymbol, rustc_middle::middle::exported_symbols::SymbolExportLevel)]>>
  31: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::exported_symbols, rustc_query_impl::plumbing::QueryCtxt>
  32: <rustc_metadata::rmeta::encoder::EncodeContext>::encode_crate_root
  33: rustc_metadata::rmeta::encoder::encode_metadata_impl
  34: rustc_data_structures::sync::join::<rustc_metadata::rmeta::encoder::encode_metadata::{closure#0}, rustc_metadata::rmeta::encoder::encode_metadata::{closure#1}, rustc_metadata::rmeta::encoder::EncodedMetadata, ()>
  35: rustc_metadata::rmeta::encoder::encode_metadata
  36: <rustc_interface::queries::Queries>::ongoing_codegen
  37: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
  38: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  39: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
```

</p>
</details>

Note that the specific version of the panic macro doesn't matter (this triggers with edition=2021 as well)

Going to attempt a bisect through nightlies, will report back once I divine a nightly (unless someone else figures it out first, /shrug)

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_ASSIGN_START -->

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

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