Skip to content

Internal compiler error on HashMap/HashSet (RandomState::new): rustc_metadata panics on AnonConst #5101

Open

Description

@feliperodri

Kani version: 0.68.0 (main @ cd355b0), nightly-2026-10-22, CBMC 6.11.0.

Reproduction

src/lib.rs:

use std::collections::HashMap;

pub fn uses_hashmap(x: u32) -> u32 {
    let mut m: HashMap<u32, u32> = HashMap::new();
    m.insert(x, x);
    *m.get(&x).unwrap()
}

#[kani::proof]
fn check_uses_hashmap() {
    let x: u32 = kani::any();
    uses_hashmap(x);
}
$ cargo kani

Actual

thread 'rustc' panicked at compiler/rustc_metadata/src/rmeta/decoder.rs:1494:26:
Definition key DefKey { parent: Some(DefIndex(7826)), disambiguated_data: DisambiguatedDefPathData { data: AnonConst, disambiguator: 0 } } of type `AnonConst` did not have any attributes stored
error: internal compiler error: Kani unexpectedly panicked at ...
[Kani] current codegen item: declare_function: std::hash::RandomState::new::KEYS::{constant#0}::{closure#1}::{closure#0}
[Kani] current codegen location: .../library/std/src/sys/thread_local/native/mod.rs:112

Expected

Either verification runs (stubbing RandomState::new the way tests/perf/hashset already does internally, or supporting the construct), or a clean diagnostic — not an ICE.

Notes

  • Uses the default --reachability=harnesses; not specific to -Z autoharness or --reachability=all_fns (both reproduce it too, which is how this was first noticed, on firecracker's vmm crate and on verus's air crate — same panic, same DefIndex(7826), same codegen item, in both).
  • tests/kani has no coverage at all for HashMap/HashSet; the only two mentions of either (tests/perf/hashset, tests/expected/bounded-arbitrary/hash/hash.rs) stub RandomState::new themselves and don't go through this thread_local path.
  • Related but distinct: HashMap::new fails to verify: syscall undefined #723 is HashMap::new failing verification ("syscall undefined") on old RMC. This is a hard crash during compilation, seemingly introduced since, probably when std's TLS implementation changed to the "native" thread_local path with an anonymous const (the panicking file is sys/thread_local/native/mod.rs).

Activity

  1. added
    [F] Crash
    [C] Bug
    T-High Priority
    on Oct 31, 2026
  2. feliperodri commented on Nov 6, 2026

    @feliperodri
    MemberAuthor

    More evidence for this issue. Kani hit it while verifying these 12 crate(s):

    Minimal reproducer (Kani 0.68.0):

    use std::collections::HashMap;
    
    #[cfg(kani)]
    #[kani::proof]
    fn hashmap_new() {
        let mut m: HashMap<u8, u8> = HashMap::new();
        m.insert(1, 2);
        assert!(m.len() == 1);
    }
    $ cargo kani -Z unstable-options --harness hashmap_new --harness-timeout 5m
    error: internal compiler error: Kani unexpectedly panicked at panicked at /rustc-dev/1a2c4797ef2570bd76ca5dee34449169bc7dc457/compiler/rustc_metadata/src/rmeta/decoder.rs:1494:26:
     Definition key DefKey { parent: Some(DefIndex(7826)), disambiguated_data: DisambiguatedDefPathData { data: AnonConst, disambiguator: 0 } } of type `AnonConst` did not have any att
    error: Failed to compile `k01` due to an internal compiler error.: error: internal compiler error: Kani unexpectedly panicked at panicked at /rustc-dev/1a2c4797ef2570bd76ca5dee3444
    Definition key DefKey { parent: Some(DefIndex(7826)), disambiguated_data: DisambiguatedDefPathData { data: AnonConst, disambiguator: 0 } } of type `AnonConst` did not have any attr
    [Kani] current codegen item: declare_function: std::hash::RandomState::new::KEYS::{constant#0}::{closure#1}::{closure#0}
    error: could not compile `k01` (lib); 1 warning emitted
    

    Context: we ran AI agents that use the Kani agent plugin (#5059) to verify 101 of the most downloaded crates on crates.io with Kani 0.68.0, CBMC 6.11.0 and nightly-2026-10-22. The minimal reproducer above was re-run by hand with the same versions. This text was written with AI assistance.

  3. added
    Z-Kani Compiler
    on Nov 6, 2026
  4. added theissue type on Nov 6, 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

    T-High PriorityZ-Kani Compiler[C] Bug[F] Crash

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions