vosen/ZLUDA · error

Unexpected key `{}`, expected `repr` or `space

Error message

Unexpected key `{}`, expected `repr` or `space

What it means

A proc-macro parse error from `parse_block`: inside an instruction/operand attribute body, a key was encountered that is not `repr` or `space` (the message string is itself truncated, missing its closing backtick). The macro expects each entry in that block to use one of these two keys and fails compilation at the offending key's span otherwise. Keys like `dst` are accepted in sibling branches but not in this one.

Source

Thrown at ptx_parser_macros_impl/src/lib.rs:599

                Ok(if lookahead.peek(Token![type]) {
                    content.parse::<Token![type]>()?;
                    content.parse::<Token![:]>()?;
                    ExprOrPath::Type(content.parse::<Expr>()?)
                } else if lookahead.peek(Ident) {
                    let name_ident = content.parse::<Ident>()?;
                    content.parse::<Token![:]>()?;
                    match &*name_ident.to_string() {
                        "relaxed_type_check" => {
                            ExprOrPath::RelaxedTypeCheck(content.parse::<LitBool>()?.value)
                        }
                        "repr" => ExprOrPath::Repr(content.parse::<Type>()?),
                        "space" => ExprOrPath::Space(content.parse::<Expr>()?),
                        "dst" => {
                            let ident = content.parse::<LitBool>()?;
                            ExprOrPath::Dst(ident.value)
                        }
                        name => {
                            return Err(syn::Error::new(
                                name_ident.span(),
                                format!("Unexpected key `{}`, expected `repr` or `space", name),
                            ))
                        }
                    }
                } else {
                    return Err(lookahead.error());
                })
            })?;
        let mut repr = None;
        let mut type_ = None;
        let mut space = None;
        let mut is_dst = None;
        let mut relaxed_type_check = false;
        for exp_or_path in all_fields {
            match exp_or_path {
                ExprOrPath::Repr(r) => repr = Some(r),
                ExprOrPath::Type(t) => type_ = Some(t),

View on GitHub (pinned to 9c8b43f242)

Solutions

  1. Replace the key with `repr` or `space` as appropriate for that block
  2. Fix spelling and casing of the key
  3. Move the attribute to the correct nesting level if the key (e.g. `dst`) is valid elsewhere in the DSL
  4. Compare against working examples in the ptx_parser test suite or macro docs

Example fix

// before
Operand { kind: reg }
// after
Operand { repr: reg }
Defensive patterns

Strategy: type-guard

Type guard

// Compile-time guard: only these keys are valid in this block position:
const VALID_BLOCK_KEYS: &[&str] = &["repr", "space"];

Prevention

When it happens

Trigger: Writing e.g. `#[instruction { reg: u32 }]`, `type: ...`, or any other key in the block position handled by `parse_block`'s `ExprOrPath` parsing, where only `repr: <expr>` or `space: <expr>` are recognized.

Common situations: Typos (`reprs:`, `spce:`), mixing up which block level a key belongs to (using `dst` or `type` where only `repr`/`space` are valid), or following outdated DSL examples from an earlier macro version.

Understand the failure class

Background: "invalid argument", "unknown mode", "not supported": invalid enum-like argument errors explained — this error's family across 19 libraries.

Related errors


AI-assisted analysis of vosen/ZLUDA@9c8b43f242 (2026-09-06). Data as JSON: /api/errors/dab374f207bb26a5. Report an issue: GitHub.