rust-lang/rust · error

`NumScalableVectors(N)` for N>8 is illformed

Error message

`NumScalableVectors(N)` for N>8 is illformed

What it means

Thrown at compiler/rustc_abi/src/lib.rs:1774 inside `NumScalableVectors::into_diag_arg`. The match arms only spell out English ordinals up to `8` ("eight"); any value above 8 has no rendering and is treated as ill-formed. The constructor `from_field_count` correspondingly only accepts `2..8`, and `for_non_tuple` yields `1`, so the valid range is exactly `1..=8`.

Source

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

            _ => None,
        }
    }
}

#[cfg(feature = "nightly")]
impl IntoDiagArg for NumScalableVectors {
    fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
        DiagArgValue::Str(std::borrow::Cow::Borrowed(match self.0 {
            0 => panic!("`NumScalableVectors(0)` is illformed"),
            1 => "one",
            2 => "two",
            3 => "three",
            4 => "four",
            5 => "five",
            6 => "six",
            7 => "seven",
            8 => "eight",
            _ => panic!("`NumScalableVectors(N)` for N>8 is illformed"),
        }))
    }
}

/// The way we represent values to the backend
///
/// Previously this was conflated with the "ABI" a type is given, as in the platform-specific ABI.
/// In reality, this implies little about that, but is mostly used to describe the syntactic form
/// emitted for the backend, as most backends handle SSA values and blobs of memory differently.
/// The psABI may need consideration in doing so, but this enum does not constitute a promise for
/// how the value will be lowered to the calling convention, in itself.
///
/// Generally, a codegen backend will prefer to handle smaller values as a scalar or short vector,
/// and larger values will usually prefer to be represented as memory.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
#[cfg_attr(feature = "nightly", derive(StableHash))]
pub enum BackendRepr {
    Scalar(Scalar),

View on GitHub (pinned to 22057b88b0)

Solutions

  1. Clamp/validate the count to `1..=8` when constructing `NumScalableVectors`; use `from_field_count` / `for_non_tuple` rather than the raw tuple constructor.
  2. If you are extending the language to support larger scalable-vector tuples, add the missing ordinal arms to `into_diag_arg` and widen `from_field_count`'s range in the same change.
  3. Add a debug assertion at every internal site that produces a `NumScalableVectors` to catch the violation before it reaches diagnostics.

Example fix

// before
let n = NumScalableVectors(12); // for a 12-vector tuple

// after - reject up front, or extend the ordinal table
let n = NumScalableVectors::from_field_count(12)
    .ok_or_else(|| LayoutError::Unknown(
        "scalable-vector tuples support only 2..8 fields".into()))?;
Defensive patterns

Strategy: validation

Validate before calling

// NumScalableVectors(N>8) is illformed. from_field_count covers 2..8;
// combine with for_non_tuple() to admit 1..=8.
fn from_count(n: usize) -> Option<rustc_abi::NumScalableVectors> {
    match n {
        1 => Some(rustc_abi::NumScalableVectors::for_non_tuple()),
        2..=8 => rustc_abi::NumScalableVectors::from_field_count(n),
        _ => None,
    }
}

Type guard

fn is_wellformed(nsv: rustc_abi::NumScalableVectors) -> bool {
    nsv.0 >= 1 && nsv.0 <= 8
}

Try / catch

// Same as [26]: panic occurs in IntoDiagArg formatting. Validate at build time.

Prevention

When it happens

Trigger: Calling `into_diag_arg` (transitively, by emitting a diagnostic that references a `SimdScalableVector` repr) on a `NumScalableVectors` constructed with a value > 8. This requires bypassing the provided constructors, since they never yield such a value.

Common situations: Hand-built `BackendRepr::SimdScalableVector { number_of_vectors: NumScalableVectors(N), .. }` in tests, fuzzers, or third-party consumers (rust-analyzer, miri, cranelift) that did not respect the 1..=8 bound. Can also follow from a future change that raises the tuple-size limit without extending the ordinal table here.

Related errors


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