Repository: rust
Issue: rustc panicked with a simple code 
Labels: I-ICE,T-compiler,C-bug,S-has-mcve

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.
http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/
-->

### Code

```Rust
mod bytes_num {
    use std::{error::Error, time::Duration};

    const NANOSECOND_CHARS: &[char] = &['n', 's'];
    const MICROSECOND_CHARS: &[char] = &['u', 's'];
    const MICROSECOND_GREEK_CHARS: &[char] = &['μ', 's'];
    const MILLISECOND_CHARS: &[char] = &['m', 's'];
    const SECOND_CHARS: &[char] = &['s'];
    const MINUTE_CHARS: &[char] = &['m'];
    const HOUR_CHARS: &[char] = &['h'];

    const NANOSECOND: u64 = 1;
    const MICROSECOND: u64 = NANOSECOND * 1000;
    const MILLISECOND: u64 = MICROSECOND * 1000;
    const SECOND: u64 = MILLISECOND * 1000;
    const MINUTE: u64 = SECOND * 60;
    const HOUR: u64 = MINUTE * 60;

    pub(crate) fn foo(bar: &str) -> Result<Duration, Box<dyn Error>> {
        let u = ['s'].as_slice();
        let unit = match u {
            NANOSECOND_CHARS => NANOSECOND,
            MICROSECOND_CHARS => MICROSECOND,
            MICROSECOND_GREEK_CHARS => MICROSECOND,
            MILLISECOND_CHARS => MILLISECOND,
            SECOND_CHARS => SECOND,
            MINUTE_CHARS => MINUTE,
            HOUR_CHARS => HOUR,
            _ => return Err(From::from(format!("Unknown Unit '{:?}' in '{}'", u, bar))),
        };

        Ok(Duration::from_secs(1))
    }
}

mod duration {
    use std::error::Error;

    const BYTE_CHARS: &[char] = &['b'];

    const KILOBYTES_CHARS: &[char] = &['k', 'b'];
    const KIBIBYTES_CHARS: &[char] = &['k', 'i', 'b'];
    const KIBIBYTES_SHORT: &[char] = &['k'];
    const MEGABYTES_CHARS: &[char] = &['m', 'b'];
    const MEBIBYTES_CHARS: &[char] = &['m', 'i', 'b'];
    const MEBIBYTES_SHORT: &[char] = &['m'];
    const GIGABYTES_CHARS: &[char] = &['g', 'b'];
    const GIBIBYTES_CHARS: &[char] = &['g', 'i', 'b'];
    const GIBIBYTES_SHORT: &[char] = &['g'];

    const BYTES: u64 = 1;
    const KILOBYTES: u64 = BYTES * 1000;
    const KIBIBYTES: u64 = BYTES * 1024;
    const MEGABYTES: u64 = KILOBYTES * 1000;
    const MEBIBYTES: u64 = KIBIBYTES * 1024;
    const GIGABYTES: u64 = MEGABYTES * 1000;
    const GIBIBYTES: u64 = MEBIBYTES * 1024;

    pub(crate) fn baz(qux: &str) -> Result<u64, Box<dyn Error>> {
        let u = ['b'].as_slice();
        let unit = match u {
            BYTE_CHARS => BYTES,
            KILOBYTES_CHARS => KILOBYTES,
            KIBIBYTES_CHARS | KIBIBYTES_SHORT => KIBIBYTES,
            MEGABYTES_CHARS => MEGABYTES,
            MEBIBYTES_CHARS | MEBIBYTES_SHORT => MEBIBYTES,
            GIGABYTES_CHARS => GIGABYTES,
            GIBIBYTES_CHARS | GIBIBYTES_SHORT => GIBIBYTES,
            _ => return Err(From::from(format!("Unknown unit '{:?}' in '{}'", u, qux))),
        };

        Ok(1)
    }
}

fn main() {
    println!("Hello world");
}
```


### 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`:
```
rustc 1.67.1 (d5a82bbd2 2023-02-07)
binary: rustc
commit-hash: d5a82bbd26e1ad8b7401f6a718a9c57c96905483
commit-date: 2023-02-07
host: aarch64-apple-darwin
release: 1.67.1
LLVM version: 15.0.6
```

### Error output

```
thread 'rustc' panicked at 'forcing query with already existing `DepNode`
- query-key: ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing, constness: NotConst }, value: Val(ByRef { alloc: ConstAllocation { .. }, offset: Size(0 bytes) }, &[char]) }
- dep-node: deref_mir_constant(6c0d3808aaf7532e-5e094c413a0202f3)', /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/compiler/rustc_query_system/src/dep_graph/graph.rs:316:9
```

<!--
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>

```
> RUST_BACKTRACE=1 cargo build
   Compiling demo v0.1.0 (/Users/zipper/Rust/magz/demo)
thread 'rustc' panicked at 'forcing query with already existing `DepNode`
- query-key: ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing, constness: NotConst }, value: Val(ByRef { alloc: ConstAllocation { .. }, offset: Size(0 bytes) }, &[char]) }
- dep-node: deref_mir_constant(6c0d3808aaf7532e-5e094c413a0202f3)', /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/compiler/rustc_query_system/src/dep_graph/graph.rs:316:9
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::ConstantKind>, rustc_middle::mir::ConstantKind>
   3: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::deref_mir_constant, rustc_query_impl::plumbing::QueryCtxt>
   4: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::deref_mir_constant
   5: <rustc_mir_build::thir::pattern::const_to_pat::ConstToPat>::recur
   6: <rustc_mir_build::thir::pattern::const_to_pat::ConstToPat>::to_pat
   7: <rustc_mir_build::thir::pattern::PatCtxt>::const_to_pat
   8: <rustc_mir_build::thir::pattern::PatCtxt>::lower_path
   9: <rustc_mir_build::thir::pattern::PatCtxt>::lower_pattern
  10: <rustc_mir_build::thir::pattern::PatCtxt>::lower_pattern
  11: <rustc_mir_build::thir::pattern::check_match::MatchVisitor>::lower_pattern
  12: <alloc::vec::Vec<rustc_mir_build::thir::pattern::usefulness::MatchArm> as alloc::vec::spec_from_iter::SpecFromIter<rustc_mir_build::thir::pattern::usefulness::MatchArm, core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_hir::hir::Arm>, <rustc_mir_build::thir::pattern::check_match::MatchVisitor>::check_match::{closure#0}>>>::from_iter
  13: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_hir::intravisit::Visitor>::visit_expr
  14: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_hir::intravisit::Visitor>::visit_local
  15: rustc_hir::intravisit::walk_expr::<rustc_mir_build::thir::pattern::check_match::MatchVisitor>
  16: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_hir::intravisit::Visitor>::visit_expr
  17: rustc_mir_build::thir::pattern::check_match::check_match
  18: <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, ()>
  19: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, ()>>
  20: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::check_match, rustc_query_impl::plumbing::QueryCtxt>
  21: rustc_data_structures::sync::par_for_each_in::<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_interface::passes::analysis::{closure#1}::{closure#0}::{closure#0}::{closure#0}>::{closure#0}>
  22: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#1}::{closure#0}::{closure#0}>
  23: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#1}>
  24: rustc_interface::passes::analysis
  25: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  26: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorGuaranteed>>>
  27: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  28: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#2}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  29: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  30: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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.67.1 (d5a82bbd2 2023-02-07) running on aarch64-apple-darwin

note: compiler flags: --crate-type bin -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [deref_mir_constant] dereferencing MIR constant
#1 [check_match] match-checking `duration::baz`
#2 [analysis] running analysis passes on this crate
end of query stack
warning: unused variable: `unit`
  --> src/main.rs:21:13
   |
21 |         let unit = match u {
   |             ^^^^ help: if this is intentional, prefix it with an underscore: `_unit`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `unit`
  --> src/main.rs:61:13
   |
61 |         let unit = match u {
   |             ^^^^ help: if this is intentional, prefix it with an underscore: `_unit`

warning: `demo` (bin "demo") generated 2 warnings
error: could not compile `demo`; 2 warnings emitted
```

</p>
</details>