{"id":"fe64066683565374","repo":"rust-lang/rust","slug":"ptr-sized-integer-unknown-pointer-bit-size-bits","errorCode":null,"errorMessage":"ptr_sized_integer: unknown pointer bit size {bits}","messagePattern":"ptr_sized_integer: unknown pointer bit size (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_abi/src/lib.rs","lineNumber":685,"sourceCode":"    /// so we adopt such a more-constrained size bound due to its technical limitations.\n    #[inline]\n    pub fn obj_size_bound_in(&self, address_space: AddressSpace) -> u64 {\n        match self.pointer_size_in(address_space).bits() {\n            16 => 1 << 15,\n            32 => 1 << 31,\n            64 => 1 << 61,\n            bits => panic!(\"obj_size_bound: unknown pointer bit size {bits}\"),\n        }\n    }\n\n    #[inline]\n    pub fn ptr_sized_integer(&self) -> Integer {\n        use Integer::*;\n        match self.pointer_offset().bits() {\n            16 => I16,\n            32 => I32,\n            64 => I64,\n            bits => panic!(\"ptr_sized_integer: unknown pointer bit size {bits}\"),\n        }\n    }\n\n    #[inline]\n    pub fn ptr_sized_integer_in(&self, address_space: AddressSpace) -> Integer {\n        use Integer::*;\n        match self.pointer_offset_in(address_space).bits() {\n            16 => I16,\n            32 => I32,\n            64 => I64,\n            bits => panic!(\"ptr_sized_integer: unknown pointer bit size {bits}\"),\n        }\n    }\n\n    /// psABI-mandated alignment for a vector type, if any\n    #[inline]\n    fn c_vector_align(&self, vec_size: Size) -> Option<Align> {\n        self.vector_align","sourceCodeStart":667,"sourceCodeEnd":703,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_abi/src/lib.rs#L667-L703","documentation":"ptr_sized_integer maps the default pointer width to the matching codegen Integer (I16/I32/I64), used for ptrtoint/inttoptr and size_t-like temporaries. Widths outside 16/32/64 are unsupported and panic, since there is no wider StandardInteger to represent them.","triggerScenarios":"Calling ptr_sized_integer() on a TargetDataLayout whose pointer_offset (derived from pointer_size) is not 16/32/64 bits — e.g. an experimental 128-bit-pointer target or a malformed data-layout 'p' token.","commonSituations":"Experimental targets (CHERI, research ISAs), hand-built layouts in miri/cg_clif, or a target spec typo producing an odd pointer width during codegen of pointer-sized integers (usize/isize).","solutions":["Check the target's pointer_width and data-layout 'p:size:align' token via rustc --print target-spec-json.","If the width is intentional, extend the match in ptr_sized_integer and ptr_sized_integer_in (and add a matching Integer variant if needed).","Fix the malformed target spec that produced the unsupported width."],"exampleFix":"// before\nmatch self.pointer_offset().bits() {\n    16 => I16,\n    32 => I32,\n    64 => I64,\n    bits => panic!(\"ptr_sized_integer: unknown pointer bit size {bits}\"),\n}\n\n// after: add the missing width (requires an I128 variant / codegen support)\nmatch self.pointer_offset().bits() {\n    16 => I16,\n    32 => I32,\n    64 => I64,\n    128 => I128,\n    bits => panic!(\"ptr_sized_integer: unknown pointer bit size {bits}\"),\n}","handlingStrategy":"validation","validationCode":"// ptr_sized_integer() panics on pointer_offset bits outside {16,32,64}.\nuse rustc_abi::TargetDataLayout;\n\nfn check_ptr_sized_integer(dl: &TargetDataLayout) -> Result<(), String> {\n    match dl.pointer_offset().bits() {\n        16 | 32 | 64 => Ok(()),\n        bits => Err(format!(\"ptr_sized_integer: unsupported pointer bit size {bits}\")),\n    }\n}\n\ncheck_ptr_sized_integer(&dl)?;\nlet int = dl.ptr_sized_integer();","typeGuard":"// Predicate: does this layout have a supported pointer-sized integer?\nfn has_ptr_sized_integer(dl: &rustc_abi::TargetDataLayout) -> bool {\n    matches!(dl.pointer_offset().bits(), 16 | 32 | 64)\n}","tryCatchPattern":null,"preventionTips":["ptr_sized_integer keys off pointer_offset, not pointer_size — validate the offset field, which a hand-built PointerSpec can set to an unsupported value independently of size.","Do not construct TargetDataLayout with PointerSpec.pointer_offset other than 16/32/64; obtain layouts from parsed target specs.","If you accept user-supplied data-layout strings, validate the 'p' token's offset component before adopting the layout.","Run this check once when you ingest the layout, not at every ptr_sized_integer call site."],"tags":["rustc","abi","target-spec","pointer","codegen"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}