rust-lang/rust · error
ptr_sized_integer: unknown pointer bit size {bits}
Error message
ptr_sized_integer: unknown pointer bit size {bits} What it means
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.
Source
Thrown at compiler/rustc_abi/src/lib.rs:685
/// so we adopt such a more-constrained size bound due to its technical limitations.
#[inline]
pub fn obj_size_bound_in(&self, address_space: AddressSpace) -> u64 {
match self.pointer_size_in(address_space).bits() {
16 => 1 << 15,
32 => 1 << 31,
64 => 1 << 61,
bits => panic!("obj_size_bound: unknown pointer bit size {bits}"),
}
}
#[inline]
pub fn ptr_sized_integer(&self) -> Integer {
use Integer::*;
match self.pointer_offset().bits() {
16 => I16,
32 => I32,
64 => I64,
bits => panic!("ptr_sized_integer: unknown pointer bit size {bits}"),
}
}
#[inline]
pub fn ptr_sized_integer_in(&self, address_space: AddressSpace) -> Integer {
use Integer::*;
match self.pointer_offset_in(address_space).bits() {
16 => I16,
32 => I32,
64 => I64,
bits => panic!("ptr_sized_integer: unknown pointer bit size {bits}"),
}
}
/// psABI-mandated alignment for a vector type, if any
#[inline]
fn c_vector_align(&self, vec_size: Size) -> Option<Align> {
self.vector_alignView on GitHub (pinned to 22057b88b0)
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.
Example fix
// before
match self.pointer_offset().bits() {
16 => I16,
32 => I32,
64 => I64,
bits => panic!("ptr_sized_integer: unknown pointer bit size {bits}"),
}
// after: add the missing width (requires an I128 variant / codegen support)
match self.pointer_offset().bits() {
16 => I16,
32 => I32,
64 => I64,
128 => I128,
bits => panic!("ptr_sized_integer: unknown pointer bit size {bits}"),
} Defensive patterns
Strategy: validation
Validate before calling
// ptr_sized_integer() panics on pointer_offset bits outside {16,32,64}.
use rustc_abi::TargetDataLayout;
fn check_ptr_sized_integer(dl: &TargetDataLayout) -> Result<(), String> {
match dl.pointer_offset().bits() {
16 | 32 | 64 => Ok(()),
bits => Err(format!("ptr_sized_integer: unsupported pointer bit size {bits}")),
}
}
check_ptr_sized_integer(&dl)?;
let int = dl.ptr_sized_integer(); Type guard
// Predicate: does this layout have a supported pointer-sized integer?
fn has_ptr_sized_integer(dl: &rustc_abi::TargetDataLayout) -> bool {
matches!(dl.pointer_offset().bits(), 16 | 32 | 64)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- obj_size_bound: unknown pointer bit size {bits}
- unsupported integer: {self:?}
- unsupported float: {self:?}
- Use of unknown address space {c:?}
- `homogeneous_aggregate` should not be called for scalable ve
AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03).
Data as JSON: /data/errors/fe64066683565374.json.
Report an issue: GitHub.