{"id":"bc32535b38fd4ffc","repo":"rust-lang/rust","slug":"numscalablevectors-n-for-n-8-is-illformed","errorCode":null,"errorMessage":"`NumScalableVectors(N)` for N>8 is illformed","messagePattern":"`NumScalableVectors\\(N\\)` for N>8 is illformed","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_abi/src/lib.rs","lineNumber":1774,"sourceCode":"            _ => None,\n        }\n    }\n}\n\n#[cfg(feature = \"nightly\")]\nimpl IntoDiagArg for NumScalableVectors {\n    fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {\n        DiagArgValue::Str(std::borrow::Cow::Borrowed(match self.0 {\n            0 => panic!(\"`NumScalableVectors(0)` is illformed\"),\n            1 => \"one\",\n            2 => \"two\",\n            3 => \"three\",\n            4 => \"four\",\n            5 => \"five\",\n            6 => \"six\",\n            7 => \"seven\",\n            8 => \"eight\",\n            _ => panic!(\"`NumScalableVectors(N)` for N>8 is illformed\"),\n        }))\n    }\n}\n\n/// The way we represent values to the backend\n///\n/// Previously this was conflated with the \"ABI\" a type is given, as in the platform-specific ABI.\n/// In reality, this implies little about that, but is mostly used to describe the syntactic form\n/// emitted for the backend, as most backends handle SSA values and blobs of memory differently.\n/// The psABI may need consideration in doing so, but this enum does not constitute a promise for\n/// how the value will be lowered to the calling convention, in itself.\n///\n/// Generally, a codegen backend will prefer to handle smaller values as a scalar or short vector,\n/// and larger values will usually prefer to be represented as memory.\n#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]\n#[cfg_attr(feature = \"nightly\", derive(StableHash))]\npub enum BackendRepr {\n    Scalar(Scalar),","sourceCodeStart":1756,"sourceCodeEnd":1792,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_abi/src/lib.rs#L1756-L1792","documentation":"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`.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Clamp/validate the count to `1..=8` when constructing `NumScalableVectors`; use `from_field_count` / `for_non_tuple` rather than the raw tuple constructor.","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.","Add a debug assertion at every internal site that produces a `NumScalableVectors` to catch the violation before it reaches diagnostics."],"exampleFix":"// before\nlet n = NumScalableVectors(12); // for a 12-vector tuple\n\n// after - reject up front, or extend the ordinal table\nlet n = NumScalableVectors::from_field_count(12)\n    .ok_or_else(|| LayoutError::Unknown(\n        \"scalable-vector tuples support only 2..8 fields\".into()))?;","handlingStrategy":"validation","validationCode":"// NumScalableVectors(N>8) is illformed. from_field_count covers 2..8;\n// combine with for_non_tuple() to admit 1..=8.\nfn from_count(n: usize) -> Option<rustc_abi::NumScalableVectors> {\n    match n {\n        1 => Some(rustc_abi::NumScalableVectors::for_non_tuple()),\n        2..=8 => rustc_abi::NumScalableVectors::from_field_count(n),\n        _ => None,\n    }\n}","typeGuard":"fn is_wellformed(nsv: rustc_abi::NumScalableVectors) -> bool {\n    nsv.0 >= 1 && nsv.0 <= 8\n}","tryCatchPattern":"// Same as [26]: panic occurs in IntoDiagArg formatting. Validate at build time.","preventionTips":["Cap tuple-of-scalable-vectors field counts at 8; values above are unsupported by the diagnostic formatter.","If your ABI permits more, propose extending the match arms rather than bypassing the panic.","Reject counts >8 from untrusted input before constructing the value."],"tags":["rustc-abi","scalable-vector","simd","invariant","panic","diagnostic"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}