Skip to content

panic: const generics with N: i64 instead of usize #22953

Description

@matthiaskrgr
struct Struct<const N: i64>(pub [u8; N]); // "const N: usize" works

pub fn function(value: Struct<3>) -> u8 {
    value.0[0]
}

fn main() {}

rust-analyzer analysis-stats . --run-all-ide-things

Database loaded:     611.62ms, 229minstr, 48mb (metadata 304.75ms, 1010kinstr, 151kb; build 32.86ms, 181kinstr, 2064b)
  item trees: 1
  dependency lines of code: 1_467_433, item trees: 2_948
  dependency item stats: traits: 848, impl: 9_686, mods: 3_059, macro calls: 5_580, macro rules: 1_054
Item Tree Collection: 4.23s, 23ginstr, 427mb
  Total Statistics:
    crates: 1, mods: 1, decls: 3, bodies: 2, adts: 1, consts: 0, signatures: 3, variants: 1
  Workspace:
    traits: 0, macro_rules macros: 0, proc_macros: 0
    lines of code: 7, item trees: 1
    usages: traits: 0, impl: 0, mods: 0, macro calls: 0, macro rules: 0
  Dependencies:
    lines of code: 1_467_433, item trees: 2_948
    declarations: traits: 848, impl: 9_686, mods: 3_059, macro calls: 5_580, macro rules: 1_054
Item Collection:     2.48s, 11ginstr, 179mb
Crate lang items:    455.83ms, 2474minstr, 31mb
Expression Store Lowering: 393.13µs, 372kinstr, 7kb
  exprs: 6, ??ty: 0 (0%), ?ty: 0 (0%), !ty: 0
  pats: 1, ??ty: 0 (0%), ?ty: 0 (0%), !ty: 0
  panics: 0
Inference:           346.58ms, 1346minstr, 35mb
MIR lowering:        260.57µs, 215kinstr, 113kb
Mir failed bodies: 0 (0%)
Data layouts:        721.00ns, 25kinstr, 0b
Failed data layouts: 0 (100%)
Const evaluation:    28.46µs, 46kinstr, 192b
Failed const evals: 0 (100%)
0/1 0% diagnostics: /tmp/ra/src/main.rs
thread 'main' (1787056) panicked at src/tools/rust-analyzer/crates/hir-ty/src/mir.rs:1329:82:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7ff05f8a6246 - <<std[74eb2aff46e51e81]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[7aff35c028b048a4]::fmt::Display>::fmt
   1:     0x7ff06000ad52 - core[7aff35c028b048a4]::fmt::write
   2:     0x7ff05f8bb38c - <std[74eb2aff46e51e81]::sys::stdio::unix::Stderr as core[7aff35c028b048a4]::io::write::Write>::write_fmt
   3:     0x7ff05f877e7a - std[74eb2aff46e51e81]::panicking::default_hook::{closure#0}
   4:     0x7ff05f8988e3 - std[74eb2aff46e51e81]::panicking::default_hook
   5:     0x7ff05f898d4b - std[74eb2aff46e51e81]::panicking::panic_with_hook
   6:     0x7ff05f877f64 - std[74eb2aff46e51e81]::panicking::panic_handler::{closure#0}
   7:     0x7ff05f86f3e9 - std[74eb2aff46e51e81]::sys::backtrace::__rust_end_short_backtrace::<std[74eb2aff46e51e81]::panicking::panic_handler::{closure#0}, !>
   8:     0x7ff05f87988d - __rustc[49844a0cf2bb6b0d]::rust_begin_unwind
   9:     0x7ff05c633c7c - core[7aff35c028b048a4]::panicking::panic_fmt
  10:     0x7ff05c9f2952 - core[7aff35c028b048a4]::panicking::panic
  11:     0x7ff05d1bda79 - core[7aff35c028b048a4]::option::unwrap_failed
  12:     0x55e11fc7436a - <hir_ty[f58a0abe133f1c00]::mir::PlaceTy>::projection_ty::<la_arena[f716c310310ca8c]::Idx<hir_ty[f58a0abe133f1c00]::mir::Local>>
  13:     0x55e11fda7357 - hir_ty[f58a0abe133f1c00]::mir::borrowck::moved_out_of_ref::{closure#0}
  14:     0x55e11fda9d59 - <<hir_ty[f58a0abe133f1c00]::InferBodyId>::borrowck::_::borrowck_query_Configuration_ as salsa[8774cceebe7971b6]::function::Configuration>::execute::inner_::{closure#0}
  15:     0x55e11ffd5dfb - <<hir_ty[f58a0abe133f1c00]::InferBodyId>::borrowck::_::borrowck_query_Configuration_ as salsa[8774cceebe7971b6]::function::Configuration>::execute
  16:     0x55e11fdf10ba - <salsa[8774cceebe7971b6]::function::IngredientImpl<<hir_ty[f58a0abe133f1c00]::InferBodyId>::borrowck::_::borrowck_query_Configuration_>>::execute
  17:     0x55e11ff05d85 - <hir_ty[f58a0abe133f1c00]::InferBodyId>::borrowck
  18:     0x55e11f878765 - <hir[4ef1887375cd4b44]::DefWithBody>::diagnostics
  19:     0x55e11f82136e - <hir[4ef1887375cd4b44]::ModuleDef>::diagnostics
  20:     0x55e11f835363 - <hir[4ef1887375cd4b44]::Module>::diagnostics
  21:     0x55e1207152ec - ide_diagnostics[22d31180f2d1ac67]::semantic_diagnostics
  22:     0x55e12070f972 - ide_diagnostics[22d31180f2d1ac67]::full_diagnostics
  23:     0x55e120152ba9 - <ide[604e506ad1ac25c5]::Analysis>::full_diagnostics
  24:     0x55e120c00b9b - <rust_analyzer[f1820004a41e425c]::cli::flags::AnalysisStats>::run
  25:     0x55e120e3ffd6 - rust_analyzer[c4fd19d1c3329aa5]::main
  26:     0x55e120e3c373 - std[74eb2aff46e51e81]::sys::backtrace::__rust_begin_short_backtrace::<fn() -> core[7aff35c028b048a4]::result::Result<std[74eb2aff46e51e81]::process::ExitCode, anyhow[f3ff20ce718c24c8]::Error>, core[7aff35c028b048a4]::result::Result<std[74eb2aff46e51e81]::process::ExitCode, anyhow[f3ff20ce718c24c8]::Error>>
  27:     0x55e120e3e0d2 - std[74eb2aff46e51e81]::rt::lang_start::<core[7aff35c028b048a4]::result::Result<std[74eb2aff46e51e81]::process::ExitCode, anyhow[f3ff20ce718c24c8]::Error>>::{closure#0}
  28:     0x7ff061103553 - std[74eb2aff46e51e81]::rt::lang_start_internal
  29:     0x55e120e56b68 - main
  30:     0x7ff05a627741 - <unknown>
  31:     0x7ff05a627879 - __libc_start_main
  32:     0x55e11f73aed9 - <unknown>
  33:                0x0 - <unknown>
    Checking ra v0.1.0 (/tmp/ra)

rust-analyzer 1.99.0-nightly (26ae60a 2026-07-28)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tytype system / type inference / traits / method resolutionC-bugCategory: bugI-panic

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions