{"record":{"id":"4135dd64e53018ef","repo":"rust-lang/rust","slug":"expected-monomorphic-const-in-codegen-4135dd","errorCode":null,"errorMessage":"expected monomorphic const in codegen","messagePattern":"expected monomorphic const in codegen","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_codegen_cranelift/src/debuginfo/types.rs","lineNumber":47,"sourceCode":"        tcx: TyCtxt<'tcx>,\n        type_dbg: &mut TypeDebugContext<'tcx>,\n        ty: Ty<'tcx>,\n    ) -> UnitEntryId {\n        if let Some(&type_id) = type_dbg.type_map.get(&ty) {\n            return type_id;\n        }\n\n        let type_id = match ty.kind() {\n            ty::Never | ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) => {\n                self.basic_type(tcx, ty)\n            }\n            ty::Tuple(elems) if elems.is_empty() => self.basic_type(tcx, ty),\n            ty::Array(elem_ty, len) => self.array_type(\n                tcx,\n                type_dbg,\n                ty,\n                *elem_ty,\n                len.try_to_target_usize(tcx).expect(\"expected monomorphic const in codegen\"),\n            ),\n            // ty::Slice(_) | ty::Str\n            // ty::Dynamic\n            // ty::Foreign\n            ty::RawPtr(pointee_type, _) | ty::Ref(_, pointee_type, _) => {\n                self.pointer_type(tcx, type_dbg, ty, *pointee_type)\n            }\n            // ty::Adt(def, args) if def.is_box() && args.get(1).map_or(true, |arg| cx.layout_of(arg.expect_ty()).is_1zst())\n            // ty::FnDef(..) | ty::FnPtr(..)\n            // ty::Closure(..)\n            // ty::Adt(def, ..)\n            ty::Tuple(components) => self.tuple_type(tcx, type_dbg, ty, components),\n            // ty::Param(_)\n            // FIXME implement remaining types and add unreachable!() to the fallback branch\n            _ => self.placeholder_for_type(tcx, type_dbg, ty),\n        };\n\n        type_dbg.type_map.insert(ty, type_id);","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_codegen_cranelift/src/debuginfo/types.rs#L29-L65","documentation":"This fires in Cranelift codegen's debug info generation for `ty::Array(elem_ty, len)`. The array length const is resolved via `len.try_to_target_usize(tcx).expect(\"expected monomorphic const in codegen\")`. By codegen time, the array length should be a concrete usize. If it's still generic or unevaluated, this panics. Same monomorphization invariant as [270] and [272], but in the debug-info type-emit path.","triggerScenarios":"Generating debug info (`-g` / `-Cdebuginfo=2`) for a function containing an array with a generic or unevaluated const length. The type-debug context tries to emit the DWARF array type with its length, but the const isn't monomorphized.","commonSituations":"Compiling with debug info enabled on code using generic const array lengths (`[T; N]`). The type-debug path (`debug_type`) is only hit when emitting debug info, so this is specifically a debug-info-enabled compilation issue. Can be avoided by disabling debug info as a workaround.","solutions":["Disable debug info: compile with `-Cdebuginfo=0` or no `-g` flag.","Avoid generic const array lengths in code compiled with debug info.","File an ICE bug report — the const should be monomorphized regardless of debug info.","Update nightly — the debuginfo codegen path may be fixed to handle this.","Try the LLVM backend to determine if this is cg_clif-specific."],"exampleFix":"# before (debug info + generic array length → panic)\nRUSTFLAGS='-Cdebuginfo=2' cargo build\n\n# after (disable debug info to avoid the debug_type path)\nRUSTFLAGS='-Cdebuginfo=0' cargo build","handlingStrategy":"validation","validationCode":"// Check that debug info is disabled when compiling generic array code\n// with cg_clif:\n// In .cargo/config.toml:\n// [build]\n// rustflags = [\"-Cdebuginfo=0\"]\n// Or in CI:\n// export RUSTFLAGS='-Cdebuginfo=0'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Disable debug info (-Cdebuginfo=0) when compiling generic array code with cg_clif.","Avoid generic const array lengths in debug-info-enabled builds.","Use the LLVM backend for debug builds if this ICE is cg_clif-specific.","Report debuginfo codegen ICEs with the array type that triggers them."],"tags":["rustc","cranelift","codegen","ice","debuginfo","monomorphization","const-eval","array","compiler-internal"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}