rust-lang/rust · error

Use of unknown address space {c:?}

Error message

Use of unknown address space {c:?}

What it means

pointer_size_in(c) resolves the pointer size for address space c. It short-circuits the default space, then scans address_space_info; if c is neither default nor registered it panics. Address spaces are registered during TargetDataLayout::parse from 'p<addr>:size:align' tokens in the data-layout string, so an unregistered space means the target spec never declared it.

Source

Thrown at compiler/rustc_abi/src/lib.rs:740

    }

    /// Get the pointer size in the default data address space.
    #[inline]
    pub fn pointer_size(&self) -> Size {
        self.default_address_space_pointer_spec.pointer_size
    }

    /// Get the pointer size in a specific address space.
    #[inline]
    pub fn pointer_size_in(&self, c: AddressSpace) -> Size {
        if c == self.default_address_space {
            return self.default_address_space_pointer_spec.pointer_size;
        }

        if let Some(e) = self.address_space_info.iter().find(|(a, _)| a == &c) {
            e.1.pointer_size
        } else {
            panic!("Use of unknown address space {c:?}");
        }
    }

    /// Get the pointer index in the default data address space.
    #[inline]
    pub fn pointer_offset(&self) -> Size {
        self.default_address_space_pointer_spec.pointer_offset
    }

    /// Get the pointer index in a specific address space.
    #[inline]
    pub fn pointer_offset_in(&self, c: AddressSpace) -> Size {
        if c == self.default_address_space {
            return self.default_address_space_pointer_spec.pointer_offset;
        }

        if let Some(e) = self.address_space_info.iter().find(|(a, _)| a == &c) {
            e.1.pointer_offset

View on GitHub (pinned to 22057b88b0)

Solutions

  1. Inspect the target's data layout (rustc --print target-spec-json, the 'data-layout' field) and confirm whether the address space is declared.
  2. Add the missing 'p<N>:size:align' entry to the target spec's data-layout so the address space is registered.
  3. Ensure the AddressSpace value you pass matches a declared space (e.g. AddressSpace::ZERO or GPU_WORKGROUP), not an ad-hoc constant.

Example fix

// before: target data-layout missing address space 3
//   data-layout = "e-m:e-p:64:64-i64:64"
// calling pointer_size_in(AddressSpace(3)) panics

// after: declare address space 3 in the spec
//   data-layout = "e-m:e-p:64:64-p3:32:32-i64:64"
Defensive patterns

Strategy: validation

Validate before calling

// pointer_size_in(c) panics when c is neither the default address space nor
// present in address_space_info. Because address_space_info is private, the
// caller must track declared address spaces from the data-layout string.
use rustc_abi::{AddressSpace, TargetDataLayout};

/// Collect every address space mentioned in a data-layout string ('p', 'p<as>',
/// 'G', 'A' tokens) so callers can validate before invoking *_in(c).
fn known_address_spaces(
    data_layout: &str,
    default_address_space: AddressSpace,
) -> std::collections::HashSet<AddressSpace> {
    let mut set = std::collections::HashSet::new();
    set.insert(default_address_space);
    for token in data_layout.split('-') {
        if let Some(rest) = token.strip_prefix('p') {
            // 'p' alone => AddressSpace::ZERO; 'pN' => address space N
            let addr = if rest.is_empty() { 0 }
                else if let Some(digits) = rest.strip_prefix('f') { digits.parse().unwrap_or(0) }
                else { rest.parse().unwrap_or(0) };
            set.insert(AddressSpace::from(addr));
        }
    }
    set
}

let known = known_address_spaces(&data_layout_str, dl.default_address_space);
if c != dl.default_address_space && !known.contains(&c) {
    return Err(format!("pointer_size_in: unknown address space {c:?}"));
}
let sz = dl.pointer_size_in(c);

Type guard

fn is_known_address_space(
    dl: &rustc_abi::TargetDataLayout,
    known: &std::collections::HashSet<rustc_abi::AddressSpace>,
    c: rustc_abi::AddressSpace,
) -> bool {
    c == dl.default_address_space || known.contains(&c)
}

Prevention

When it happens

Trigger: Calling pointer_size_in (or any query that delegates to it: size bound, alignment, offset) with an AddressSpace value that has no 'p<addr>:size:align' entry in the target's data-layout string and is not the default space.

Common situations: Custom target spec missing address-space declarations; GPU/CHERI code referencing an address space the target did not declare; mismatch between the target that produced the MIR (e.g. rustc) and the one consuming it (e.g. miri, cg_clif); constructing AddressSpace literals ad hoc instead of using the target's declared spaces.

Related errors


AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03). Data as JSON: /data/errors/dca36e8ab670160b.json. Report an issue: GitHub.