tracel-ai/burn · error · syn::Error

at most one `..` per pattern

Error message

at most one `..` per pattern

What it means

This is a compile-time (proc-macro parse) error from burn's shape assertion macros. The `..` rest slot in the shape pattern acts as a catch-all for any number of dimensions, so allowing more than one would be ambiguous. The derive parser counts the `..` slots in the bracket list and rejects the macro invocation with this syn error pointing at the second `..`.

Source

Thrown at crates/burn-derive/src/shape/mod.rs:66

impl Parse for ShapeInput {
    fn parse(input: ParseStream) -> syn::Result<Self> {
        let krate: Path = input.parse()?;
        input.parse::<Token![,]>()?;
        let call = input.fork().parse::<TokenStream>()?.to_string();
        let tensor: Expr = input.parse()?;
        input.parse::<Token![,]>()?;
        let content;
        bracketed!(content in input);
        let slots: Vec<Slot> = Punctuated::<Slot, Token![,]>::parse_terminated(&content)?
            .into_iter()
            .collect();
        let mut rests = slots.iter().filter_map(|slot| match slot {
            Slot::Rest(token) => Some(token),
            _ => None,
        });
        rests.next();
        if let Some(second) = rests.next() {
            return Err(syn::Error::new(
                second.span(),
                "at most one `..` per pattern",
            ));
        }
        Ok(ShapeInput {
            krate,
            call,
            tensor,
            slots,
        })
    }
}

/// Which macro is expanding. It decides the name in messages and the debug gating.
#[derive(Clone, Copy)]
pub(crate) enum Mode {
    Assert,
    DebugAssert,

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Remove all but one `..` from the shape pattern, keeping a single rest slot
  2. Replace one `..` with an explicit dimension size or a named `_` wildcard slot
  3. If both ends must be unconstrained, use `_` for the known-position dims and keep only one `..`

Example fix

// before
assert_shape!(tensor, [.., 3, ..]);
// after
assert_shape!(tensor, [_, 3, ..]);
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Invoking a burn shape macro (assert_shape / debug_assert_shape style) with a slot list containing two or more `..` entries, e.g. `[.., 3, ..]` or `[.., ..]`. The error span points at the second `..`.

Common situations: Writing a pattern meant to say 'first dim anything, last dim anything' using `..` on both ends instead of naming dimensions; copying PyTorch-style ellipsis patterns that permit multiple ellipses; typos where a stray comma leaves an extra `..`.

Related errors


AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05). Data as JSON: /api/errors/6621677024b9075f. Report an issue: GitHub.