Skip to content

[ICE]: monomorphization failure #158756

Open

Description

@mumbleskates

Code

// no idea how to minimize this one; it doesn't happen when i start paring things down, but i have
// committed it in a branch in case you want to see the horrors

Meta

Crashes similarly in all of the below:
rustc --version --verbose:

rustc 1.98.0-nightly (c397dae80 2026-07-02)
binary: rustc
commit-hash: c397dae808f70caebab1fc4e11b3edf7e59f58c7
commit-date: 2026-07-02
host: x86_64-unknown-linux-gnu
release: 1.98.0-nightly
LLVM version: 22.1.8

rustc 1.97.0-beta.6 (b2282dd56 2026-07-01)
binary: rustc
commit-hash: b2282dd5646a57d570fc86fbe8df0e8826665ef6
commit-date: 2026-07-01
host: x86_64-unknown-linux-gnu
release: 1.97.0-beta.6
LLVM version: 22.1.6

rustc 1.96.1 (31fca3adb 2026-06-26)
binary: rustc
commit-hash: 31fca3adb283cc9dfd56b49cdee9a96eb9c96ffd
commit-date: 2026-06-26
host: x86_64-unknown-linux-gnu
release: 1.96.1
LLVM version: 22.1.2

rustc 1.65.0 (897e37553 2022-11-02)
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: x86_64-unknown-linux-gnu
release: 1.65.0
LLVM version: 15.0.0

Error output

from stable:

query stack during panic:
#0 [items_of_instance] collecting items used by `_::_::<impl at examples/schema.rs:15:35: 15:42>::register::{closure#0}`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: could not compile `bilrost` (example "schema")

Caused by:
  process didn't exit successfully: `/home/widders/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name schema --edition=2021 examples/schema.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=185 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="arrayvec"' --cfg 'feature="auto-optimize"' --cfg 'feature="auto-self-copy-optimization"' --cfg 'feature="auto-unroll-varint-encoding"' --cfg 'feature="bstr"' --cfg 'feature="bytestring"' --cfg 'feature="chrono"' --cfg 'feature="default"' --cfg 'feature="derive"' --cfg 'feature="detailed-errors"' --cfg 'feature="extended-diagnostics"' --cfg 'feature="full-test-suite"' --cfg 'feature="hashbrown"' --cfg 'feature="smallvec"' --cfg 'feature="smol_str"' --cfg 'feature="std"' --cfg 'feature="thin-vec"' --cfg 'feature="third-party-type-support"' --cfg 'feature="threadsafe-schema"' --cfg 'feature="time"' --cfg 'feature="tinyvec"' --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values("arrayvec", "auto-optimize", "auto-self-copy-optimization", "auto-unroll-varint-encoding", "bstr", "bytestring", "chrono", "default", "derive", "detailed-errors", "extended-diagnostics", "forbid-unsafe", "full-test-suite", "hashbrown", "no-recursion-limit", "pprof", "prefer-no-self-copy-optimization", "prefer-no-unroll-varint-encoding", "self-copy-optimization", "smallvec", "smol_str", "std", "test-smolstr-force-noncontiguous", "test-suite-extra", "thin-vec", "third-party-type-support", "threadsafe-schema", "time", "tinyvec", "unroll-varint-encoding"))' -C metadata=34e72ac2315b8ee5 -C extra-filename=-8d74cb51b72d2517 --out-dir /home/widders/repos/bilrost/target/debug/examples -C incremental=/home/widders/repos/bilrost/target/debug/incremental -L dependency=/home/widders/repos/bilrost/target/debug/deps --extern arbitrary=/home/widders/repos/bilrost/target/debug/deps/libarbitrary-0728679b9e5fed63.rlib --extern arrayvec=/home/widders/repos/bilrost/target/debug/deps/libarrayvec-43fb47e4eb494826.rlib --extern bilrost=/home/widders/repos/bilrost/target/debug/deps/libbilrost-bf6a6f201ad1d6ad.rlib --extern bilrost=/home/widders/repos/bilrost/target/debug/deps/libbilrost-bf6a6f201ad1d6ad.rlib --extern bilrost_derive=/home/widders/repos/bilrost/target/debug/deps/libbilrost_derive-49c546cfd470378f.so --extern bilrost_types=/home/widders/repos/bilrost/target/debug/deps/libbilrost_types-9d0cd75059bc5925.rlib --extern bstr=/home/widders/repos/bilrost/target/debug/deps/libbstr-6c79ec6770561b68.rlib --extern bytes=/home/widders/repos/bilrost/target/debug/deps/libbytes-89660b0376fecedf.rlib --extern bytestring=/home/widders/repos/bilrost/target/debug/deps/libbytestring-d5491aa098aff8c8.rlib --extern chrono=/home/widders/repos/bilrost/target/debug/deps/libchrono-15470d385670c818.rlib --extern const_panic=/home/widders/repos/bilrost/target/debug/deps/libconst_panic-a84a675caa466021.rlib --extern criterion=/home/widders/repos/bilrost/target/debug/deps/libcriterion-95d5562a18b272eb.rlib --extern hashbrown=/home/widders/repos/bilrost/target/debug/deps/libhashbrown-5fe99400d436e3d9.rlib --extern itertools=/home/widders/repos/bilrost/target/debug/deps/libitertools-e667890de3b201ca.rlib --extern proptest=/home/widders/repos/bilrost/target/debug/deps/libproptest-ba16e32df9e695e4.rlib --extern rand=/home/widders/repos/bilrost/target/debug/deps/librand-b94da0b99e561c86.rlib --extern smallvec=/home/widders/repos/bilrost/target/debug/deps/libsmallvec-0768e0b6ef61c4d6.rlib --extern smol_str=/home/widders/repos/bilrost/target/debug/deps/libsmol_str-b563041025dd90b3.rlib --extern spin=/home/widders/repos/bilrost/target/debug/deps/libspin-9c58c3f0349ea4df.rlib --extern static_assertions=/home/widders/repos/bilrost/target/debug/deps/libstatic_assertions-b762000ac734cfdb.rlib --extern thin_vec=/home/widders/repos/bilrost/target/debug/deps/libthin_vec-fa529e225a04fbba.rlib --extern time=/home/widders/repos/bilrost/target/debug/deps/libtime-bda0b5b6beb993f2.rlib --extern tinyvec=/home/widders/repos/bilrost/target/debug/deps/libtinyvec-0590a625239ec7c9.rlib --extern yoke=/home/widders/repos/bilrost/target/debug/deps/libyoke-15ebf107e3aab358.rlib --cfg rustc_1_66 --cfg rustc_1_82 --check-cfg 'cfg(rustc_1_66)' --check-cfg 'cfg(rustc_1_82)'` (exit status: 101)
Backtrace

thread 'rustc' (521520) panicked at /rustc-dev/31fca3adb283cc9dfd56b49cdee9a96eb9c96ffd/compiler/rustc_middle/src/ty/instance.rs:568:21:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: <rustc_errors::DiagCtxtHandle>::span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
   3: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   5: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   6: rustc_middle::util::bug::span_bug_fmt::<rustc_span::span_encoding::Span>
   7: <rustc_middle::ty::instance::Instance>::expect_resolve
   8: <rustc_monomorphize::collector::MirUsedCollector as rustc_middle::mir::visit::Visitor>::visit_terminator
   9: rustc_monomorphize::collector::items_of_instance
      [... omitted 1 frame ...]
  10: rustc_monomorphize::collector::collect_items_rec
  11: rustc_monomorphize::collector::collect_items_rec
  12: rustc_monomorphize::collector::collect_items_rec
  13: rustc_monomorphize::collector::collect_items_rec
  14: rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure#0}
  15: rustc_monomorphize::partitioning::collect_and_partition_mono_items
      [... omitted 1 frame ...]
  16: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
  17: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  18: <rustc_interface::queries::Linker>::codegen_and_build_linker
  19: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Activity

  1. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Jul 4, 2026
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jul 4, 2026
  3. saethlin commented on Jul 4, 2026

    @saethlin
  4. added
    S-needs-reproStatus: This issue has no reproduction and needs a reproduction to make progress.
    on Jul 4, 2026
  5. mumbleskates commented on Jul 4, 2026

    @mumbleskates
    Author
  6. removed
    S-needs-reproStatus: This issue has no reproduction and needs a reproduction to make progress.
    on Jul 5, 2026
  7. saethlin commented on Jul 5, 2026

    @saethlin
  8. added and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jul 5, 2026
  9. self-assigned this
    on Jul 5, 2026
  10. saethlin commented on Jul 6, 2026

    @saethlin
  11. zachs18 commented on Jul 6, 2026

    @zachs18
    Contributor

    The ICE seems to not happen under -Znext-solver=globally (RUSTFLAGS="-Znext-solver=globally cargo +nightly -Zscript ./bilrost.rs doesn't ICE for https://github.com/saethlin/bilrost/blob/2526a1e0edcb481a55e8ba1ca48eea0965bca3e5/bilrost.rs)

  12. pitust commented on Jul 6, 2026

    @pitust
  13. 2 remaining items

  14. added
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.
    on Jul 7, 2026
  15. theemathas commented on Jul 7, 2026

    @theemathas
    Contributor

    @lcnr What the caching is happening here? My guess is that it looks related to #t-types/trait-system-refactor > The old solver don't record required depth on cache

  16. mumbleskates commented on Jul 7, 2026

    @mumbleskates
    ContributorAuthor

    could these functions be aliasing somehow? like it's storing them under colliding keys and only stores and finds one when both are present in a given compilation?

  17. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jul 8, 2026
  18. matthiaskrgr commented on Jul 8, 2026

    @matthiaskrgr
    Member

    this compiled with nightly-2019-12-11 but ICEs with nightly-2019-12-12

      commit[0] 2019-12-10: Auto merge of #66681 - Mark-Simulacrum:toolstate-into-bootstrap, r=pietroalbini
      commit[1] 2019-12-11: Auto merge of #67198 - Xanewok:update-rls, r=nikomatsakis
      commit[2] 2019-12-11: Auto merge of #67202 - JohnTitor:rollup-0xjm5pz, r=JohnTitor
      commit[3] 2019-12-11: Auto merge of #67220 - Centril:rollup-n3u9wd5, r=Centril
      commit[4] 2019-12-11: Auto merge of #66821 - eddyb:global-trait-caching, r=nikomatsakis
      commit[5] 2019-12-11: Auto merge of #65345 - davidtwco:issue-64130-async-send-sync-error-improvements, r=nikomatsakis
    ERROR: no CI builds available between 7dbfb0a8ca4ab74ee3111e57a024f9e6257ce37c and 27d6f55f47e8875e71083a28ed84ea5a88e1b596 within last 167 days
    

    maybe #66821?

  19. removed their assignment
    on Jul 8, 2026
  20. mumbleskates commented on Jul 9, 2026

    @mumbleskates
    ContributorAuthor

    This patch fixes the crash in current main:

    index 440ed2b4632..8de0b5c6644 100644
    --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs
    +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs
    @@ -1544,7 +1544,7 @@ fn can_use_global_caches(
                 //
                 // FIXME(#132279): This is still incorrect as we treat opaque types
                 // and default associated items differently between these two modes.
    -            TypingMode::PostAnalysis | TypingMode::Codegen => true,
    +            TypingMode::PostAnalysis | TypingMode::Codegen => false,
             }
         }
     

    re: #132279

  21. mumbleskates commented on Jul 9, 2026

    @mumbleskates
    ContributorAuthor

    in fact, going by my testing (as far as i can tell, i might be holding the rustc builder subtly wrong) each of the following also fix it:

    edit: sorry, there was build caching that CARGO_INCREMENTAL=0 was not taking care of in trying to test this. i've rerun against clean caches:

    this fixes the crash:

    index 440ed2b4632..04ccd0d73e3 100644
    --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs
    +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs
    @@ -1544,7 +1544,8 @@ fn can_use_global_caches(
                 //
                 // FIXME(#132279): This is still incorrect as we treat opaque types
                 // and default associated items differently between these two modes.
    -            TypingMode::PostAnalysis | TypingMode::Codegen => true,
    +            TypingMode::PostAnalysis => true,
    +            TypingMode::Codegen => false,
             }
         }
     

    ...and this does not fix it:

    Details
    index 440ed2b4632..e8126adcf86 100644
    --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs
    +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs
    @@ -1544,7 +1544,8 @@ fn can_use_global_caches(
                 //
                 // FIXME(#132279): This is still incorrect as we treat opaque types
                 // and default associated items differently between these two modes.
    -            TypingMode::PostAnalysis | TypingMode::Codegen => true,
    +            TypingMode::PostAnalysis => false,
    +            TypingMode::Codegen => true,
             }
         }
     
  22. mumbleskates commented on Jul 11, 2026

    @mumbleskates
    ContributorAuthor

    i poked around a little bit and the above patch also fixes the crash in #146965
    edit: and #146813

  23. added 2 commits that reference this issue on Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationA-monomorphizationArea: MonomorphizationA-trait-systemArea: Trait systemC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions