Repository: rust
Issue: ICE: `erroneous constant not captured by required_consts`
Labels: I-ICE,T-compiler,C-bug,A-const-eval

<!--
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
`src/lib.rs`
```Rust
#![allow(long_running_const_eval)]
const SIZE: usize = 128;
pub const CONST_ARRAY: [u64; SIZE] = expensive_calculation();

const fn expensive_calculation() -> [u64; SIZE] {
    let mut i = 0;
    while i < 10_000_000 {
        i += 1;
    }

    [0; SIZE]
}

pub fn dbg_0<const FOO: bool>() {
    dbg!(CONST_ARRAY[0]);
}
```
`src/main.rs` (`example` is the crate name)
```Rust
fn main() {
    example::dbg_0::<true>();
}
```
If `SIZE` is less than `128` or if beta or stable is used, the compiler will not panic and only produces the error telling me that `long_running_const_eval` is denied by default, even though it is explicitly allowed in `lib.rs`.

### 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.75.0-nightly (c543b6f35 2023-10-14)
binary: rustc
commit-hash: c543b6f3516767150af84d94c14a27b19d4b0291
commit-date: 2023-10-14
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.2
```

### Error output

```Rust
error: constant evaluation is taking a long time
 --> /home/greatgodoffire/example/src/lib.rs:7:5
  |
7 | /     while i < 10_000_000 {
8 | |         i += 1;
9 | |     }
  | |_____^
  |
  = note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
          If your compilation actually takes a long time, you can safely allow the lint.
help: the constant being evaluated
 --> /home/greatgodoffire/example/src/lib.rs:3:1
  |
3 | pub const CONST_ARRAY: [u64; SIZE] = expensive_calculation();
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: `#[deny(long_running_const_eval)]` on by default

thread 'rustc' panicked at /rustc/c543b6f3516767150af84d94c14a27b19d4b0291/compiler/rustc_codegen_ssa/src/mir/constant.rs:28:14:
erroneous constant not captured by required_consts: Reported(ReportedErrorInfo { error: ErrorGuaranteed(()), is_tainted_by_errors: false }, /home/greatgodoffire/example/src/lib.rs:15:10: 15:21 (#0))
```

<!--
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 /rustc/c543b6f3516767150af84d94c14a27b19d4b0291/compiler/rustc_codegen_ssa/src/mir/constant.rs:28:14:
erroneous constant not captured by required_consts: Reported(ReportedErrorInfo { error: ErrorGuaranteed(()), is_tainted_by_errors: false }, /home/greatgodoffire/example/src/lib.rs:15:10: 15:21 (#0))
stack backtrace:
   0:     0x7f6513949824 - std::backtrace_rs::backtrace::libunwind::trace::h86105e01919bc1b1
                               at /rustc/c543b6f3516767150af84d94c14a27b19d4b0291/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f6513949824 - std::backtrace_rs::backtrace::trace_unsynchronized::h3ebb299e38badfdc
                               at /rustc/c543b6f3516767150af84d94c14a27b19d4b0291/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f6513949824 - std::backtrace::Backtrace::create::h4a41be5d247bcb9c
                               at /rustc/c543b6f3516767150af84d94c14a27b19d4b0291/library/std/src/backtrace.rs:331:13
   3:     0x7f6513949760 - std::backtrace::Backtrace::force_capture::hbcc8df305fb13ce5
                               at /rustc/c543b6f3516767150af84d94c14a27b19d4b0291/library/std/src/backtrace.rs:313:9
   4:     0x7f6516518361 - std[d6e277ee1edde582]::panicking::update_hook::<alloc[335a4ff28ba342bc]::boxed::Box<rustc_driver_impl[9643c017783a9b1d]::install_ice_hook::{closure#0}>>::{closure#0}
   5:     0x7f6513965c98 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hab00819538617f96
                               at /rustc/c543b6f3516767150af84d94c14a27b19d4b0291/library/alloc/src/boxed.rs:2021:9
   6:     0x7f6513965c98 - std::panicking::rust_panic_with_hook::hd2c0bb41cb12c130
                               at /rustc/c543b6f3516767150af84d94c14a27b19d4b0291/library/std/src/panicking.rs:735:13
   7:     0x7f65139659f1 - std::panicking::begin_panic_handler::{{closure}}::h9194cb16b6a1eb29
                               at /rustc/c543b6f3516767150af84d94c14a27b19d4b0291/library/std/src/panicking.rs:609:13
   8:     0x7f6513962e16 - std::sys_common::backtrace::__rust_end_short_backtrace::h17fc9c5939daa787
                               at /rustc/c543b6f3516767150af84d94c14a27b19d4b0291/library/std/src/sys_common/backtrace.rs:170:18
   9:     0x7f6513965722 - rust_begin_unwind
                               at /rustc/c543b6f3516767150af84d94c14a27b19d4b0291/library/std/src/panicking.rs:597:5
  10:     0x7f65139c6975 - core::panicking::panic_fmt::hc31d3c276d932e6b
                               at /rustc/c543b6f3516767150af84d94c14a27b19d4b0291/library/core/src/panicking.rs:72:14
  11:     0x7f65139c7063 - core::result::unwrap_failed::h441c903c68d7646a
                               at /rustc/c543b6f3516767150af84d94c14a27b19d4b0291/library/core/src/result.rs:1653:5
  12:     0x7f651515027a - <rustc_codegen_ssa[1bd4e60d6873bb15]::mir::FunctionCx<rustc_codegen_llvm[49de242708c666e2]::builder::Builder>>::codegen_operand
  13:     0x7f651829f20e - rustc_codegen_ssa[1bd4e60d6873bb15]::mir::codegen_mir::<rustc_codegen_llvm[49de242708c666e2]::builder::Builder>
  14:     0x7f651828bcab - rustc_codegen_llvm[49de242708c666e2]::base::compile_codegen_unit::module_codegen
  15:     0x7f65183f2900 - <rustc_codegen_llvm[49de242708c666e2]::LlvmCodegenBackend as rustc_codegen_ssa[1bd4e60d6873bb15]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  16:     0x7f65181f2a34 - <rustc_codegen_llvm[49de242708c666e2]::LlvmCodegenBackend as rustc_codegen_ssa[1bd4e60d6873bb15]::traits::backend::CodegenBackend>::codegen_crate
  17:     0x7f6517bf9a4d - rustc_interface[928fd251a38dbca8]::passes::start_codegen
  18:     0x7f65182c2bd2 - <rustc_interface[928fd251a38dbca8]::queries::Queries>::ongoing_codegen
  19:     0x7f65182c1286 - std[d6e277ee1edde582]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[928fd251a38dbca8]::util::run_in_thread_with_globals<rustc_interface[928fd251a38dbca8]::interface::run_compiler<core[930eb81f7a51b89]::result::Result<(), rustc_span[eea9884c2006bad9]::ErrorGuaranteed>, rustc_driver_impl[9643c017783a9b1d]::run_compiler::{closure#1}>::{closure#0}, core[930eb81f7a51b89]::result::Result<(), rustc_span[eea9884c2006bad9]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[930eb81f7a51b89]::result::Result<(), rustc_span[eea9884c2006bad9]::ErrorGuaranteed>>
  20:     0x7f65182c0533 - <<std[d6e277ee1edde582]::thread::Builder>::spawn_unchecked_<rustc_interface[928fd251a38dbca8]::util::run_in_thread_with_globals<rustc_interface[928fd251a38dbca8]::interface::run_compiler<core[930eb81f7a51b89]::result::Result<(), rustc_span[eea9884c2006bad9]::ErrorGuaranteed>, rustc_driver_impl[9643c017783a9b1d]::run_compiler::{closure#1}>::{closure#0}, core[930eb81f7a51b89]::result::Result<(), rustc_span[eea9884c2006bad9]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[930eb81f7a51b89]::result::Result<(), rustc_span[eea9884c2006bad9]::ErrorGuaranteed>>::{closure#1} as core[930eb81f7a51b89]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  21:     0x7f6513970c05 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h51a2ebea04175641
                               at /rustc/c543b6f3516767150af84d94c14a27b19d4b0291/library/alloc/src/boxed.rs:2007:9
  22:     0x7f6513970c05 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7f50f59c641de41e
                               at /rustc/c543b6f3516767150af84d94c14a27b19d4b0291/library/alloc/src/boxed.rs:2007:9
  23:     0x7f6513970c05 - std::sys::unix::thread::Thread::new::thread_start::hfedf3b13f94e6eb0
                               at /rustc/c543b6f3516767150af84d94c14a27b19d4b0291/library/std/src/sys/unix/thread.rs:108:17
  24:     0x7f65137139eb - <unknown>
  25:     0x7f65137977cc - <unknown>
  26:                0x0 - <unknown>


rustc version: 1.75.0-nightly (c543b6f35 2023-10-14)
platform: x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
```

</p>
</details>