Repository: rust
Issue: ICE generic_const_exprs when only enabled in lib and not bin
Labels: I-ICE,T-compiler,C-bug,requires-nightly,F-generic_const_exprs,requires-incomplete-features

<!--
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
// lib.rs
#![feature(portable_simd)]
#![feature(generic_const_exprs)]

use core::simd::*;

pub fn bar<const N: usize>() -> Simd<f32, { N * 2 }>
where
    LaneCount<N>: SupportedLaneCount,
    LaneCount<{ N * 2 }>: SupportedLaneCount,
{
    let v = Simd::<f32, N>::default();
    struct S;
    impl<const N: usize> Swizzle2<N, { N * 2 }> for S {
        const INDEX: [Which; N * 2] = [Which::First(0); N * 2];
    }
    S::swizzle2(v, v)
}

// main.rs
#![feature(portable_simd)]
// #![feature(generic_const_exprs)]

fn main() {
    foo::bar::<8>();
}
```
Note that the code runs fine if combined into one file.
Uncomment the line in main.rs for a workaround.

### 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.66.0-nightly (57f097ea2 2022-10-01)
binary: rustc
commit-hash: 57f097ea25f2c05f424fc9b9dc50dbd6d399845c
commit-date: 2022-10-01
host: x86_64-pc-windows-msvc
release: 1.66.0-nightly
LLVM version: 15.0.2
```

### Error output

```
thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler\rustc_monomorphize\src\collector.rs:940: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.66.0-nightly (57f097ea2 2022-10-01) running on x86_64-pc-windows-msvc

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED] -C target-cpu=native  

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
```

<!--
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 'called `Option::unwrap()` on a `None` value', compiler\rustc_monomorphize\src\collector.rs:940:13
stack backtrace:
   0:     0x7ffeb7ab91c2 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h143df0519cd3d364
   1:     0x7ffeb7af43fb - core::fmt::write::hc14a7656b75d53d0
   2:     0x7ffeb7aab97a - <std::io::IoSlice as core::fmt::Debug>::fmt::h31adba04a0751347
   3:     0x7ffeb7abc8b4 - std::panicking::default_hook::hf6a1a055ecc314ef
   4:     0x7ffeb7abc4ea - std::panicking::default_hook::hf6a1a055ecc314ef
   5:     0x7ffe8f958a1b - rustc_driver[8ce7d65e33148011]::describe_lints
   6:     0x7ffeb7abd2ca - std::panicking::rust_panic_with_hook::h706aa36ef8c2ccfd
   7:     0x7ffeb7abcffa - <std::panicking::begin_panic_handler::StrPanicPayload as core::panic::BoxMeUp>::get::h2fe9501abe7bad3a
   8:     0x7ffeb7ab9ecf - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h143df0519cd3d364
   9:     0x7ffeb7abcd00 - rust_begin_unwind
  10:     0x7ffeb7b2a0b5 - core::panicking::panic_fmt::h2c62a60b41506e53
  11:     0x7ffeb7b29f5c - core::panicking::panic::h7256dca92391a51f
  12:     0x7ffe8ed1072a - <rustc_monomorphize[6d8a1661af88e003]::collector::MirNeighborCollector as rustc_middle[1189f5b771ea6a30]::mir::visit::Visitor>::visit_operand
  13:     0x7ffe8ed06875 - <rustc_monomorphize[6d8a1661af88e003]::collector::MirNeighborCollector as rustc_middle[1189f5b771ea6a30]::mir::visit::Visitor>::visit_operand
  14:     0x7ffe8ed06c6d - <rustc_monomorphize[6d8a1661af88e003]::collector::MirNeighborCollector as rustc_middle[1189f5b771ea6a30]::mir::visit::Visitor>::visit_operand
  15:     0x7ffe8ed06c6d - <rustc_monomorphize[6d8a1661af88e003]::collector::MirNeighborCollector as rustc_middle[1189f5b771ea6a30]::mir::visit::Visitor>::visit_operand
  16:     0x7ffe8d9edc4e - <rustc_monomorphize[6d8a1661af88e003]::collector::MirNeighborCollector as rustc_middle[1189f5b771ea6a30]::mir::visit::Visitor>::visit_constant
  17:     0x7ffe8d9ece2d - <rustc_monomorphize[6d8a1661af88e003]::partitioning::default::DefaultPartitioning as rustc_monomorphize[6d8a1661af88e003]::partitioning::Partitioner>::place_inlined_mono_items
  18:     0x7ffe8d9e6681 - rustc_ty_utils[aef50da447823be1]::instance::provide
  19:     0x7ffe8dc7f485 - <rustc_query_impl[61fb7758d092f186]::queries::is_reachable_non_generic as rustc_query_system[ac3a70e976c77693]::query::config::QueryDescription<rustc_query_impl[61fb7758d092f186]::plumbing::QueryCtxt>>::execute_query 
  20:     0x7ffe8dcd7ae3 - <&rustc_index[74bb416820f8ff6f]::vec::IndexVec<rustc_middle[1189f5b771ea6a30]::mir::Promoted, rustc_middle[1189f5b771ea6a30]::mir::Body> as rustc_serialize[a5ed55a1dfcd8690]::serialize::Decodable<rustc_query_impl[61fb7758d092f186]::on_disk_cache::CacheDecoder>>::decode
  21:     0x7ffe8ddae216 - <&rustc_index[74bb416820f8ff6f]::vec::IndexVec<rustc_middle[1189f5b771ea6a30]::mir::Promoted, rustc_middle[1189f5b771ea6a30]::mir::Body> as rustc_serialize[a5ed55a1dfcd8690]::serialize::Decodable<rustc_query_impl[61fb7758d092f186]::on_disk_cache::CacheDecoder>>::decode
  22:     0x7ffe8dded325 - <&rustc_index[74bb416820f8ff6f]::vec::IndexVec<rustc_middle[1189f5b771ea6a30]::mir::Promoted, rustc_middle[1189f5b771ea6a30]::mir::Body> as rustc_serialize[a5ed55a1dfcd8690]::serialize::Decodable<rustc_query_impl[61fb7758d092f186]::on_disk_cache::CacheDecoder>>::decode
  23:     0x7ffe8dc3675a - <rustc_query_impl[61fb7758d092f186]::Queries as rustc_middle[1189f5b771ea6a30]::ty::query::QueryEngine>::try_mark_green
  24:     0x7ffe8d29f34f - <rustc_codegen_llvm[3b0f0ef4628a7e1a]::llvm_::ffi::Type>::i8p_llcx
  25:     0x7ffe8d291527 - <rustc_codegen_llvm[3b0f0ef4628a7e1a]::LlvmCodegenBackend as rustc_codegen_ssa[6a8919630679a748]::traits::backend::CodegenBackend>::codegen_crate
  26:     0x7ffe8d268554 - rustc_interface[752ff9d58021be80]::passes::analysis
  27:     0x7ffe8d2671e9 - <rustc_interface[752ff9d58021be80]::passes::LintStoreExpandImpl as rustc_expand[744b096b6351d8b1]::base::LintStoreExpand>::pre_expansion_lint
  28:     0x7ffe8d25c64c - <rustc_interface[752ff9d58021be80]::queries::Queries>::ongoing_codegen
  29:     0x7ffe8d21a559 - rustc_driver[8ce7d65e33148011]::main
  30:     0x7ffe8d24e66a - <rustc_middle[1189f5b771ea6a30]::ty::SymbolName as core[9a4bff41b36e4617]::fmt::Debug>::fmt    
  31:     0x7ffe8d21b970 - rustc_driver[8ce7d65e33148011]::main
  32:     0x7ffe8d24cca7 - rustc_driver[8ce7d65e33148011]::args::arg_expand_all
  33:     0x7ffe8d23e4c9 - rustc_driver[8ce7d65e33148011]::main
  34:     0x7ffe8d23e92d - rustc_driver[8ce7d65e33148011]::main
  35:     0x7ffeb7acdabc - std::sys::windows::thread::Thread::new::h9e74e9039aaece07
  36:     0x7fff23e47034 - BaseThreadInitThunk
  37:     0x7fff240c2651 - RtlUserThreadStart

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.66.0-nightly (57f097ea2 2022-10-01) running on x86_64-pc-windows-msvc

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED] -C target-cpu=native  

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: could not compile `sorting_network`
```

</p>
</details>