{"id":"b17e92ae757edde3","repo":"rust-lang/rust","slug":"is-signed-on-non-scalar-abi-self","errorCode":null,"errorMessage":"`is_signed` on non-scalar ABI {self:?}","messagePattern":"`is_signed` on non-scalar ABI (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_abi/src/lib.rs","lineNumber":1851,"sourceCode":"            // need to be revisited and will depend on what `is_unsized` is used for.\n            | BackendRepr::SimdScalableVector { .. }\n            | BackendRepr::SimdVector { .. } => false,\n            BackendRepr::Memory { sized } => !sized,\n        }\n    }\n\n    #[inline]\n    pub fn is_sized(&self) -> bool {\n        !self.is_unsized()\n    }\n\n    /// Returns `true` if this is a single signed integer scalar.\n    /// Sanity check: panics if this is not a scalar type (see PR #70189).\n    #[inline]\n    pub fn is_signed(&self) -> bool {\n        match self {\n            BackendRepr::Scalar(scal) => scal.is_signed(),\n            _ => panic!(\"`is_signed` on non-scalar ABI {self:?}\"),\n        }\n    }\n\n    /// Returns `true` if this is specifically a [`Self::Scalar`] type.\n    ///\n    /// This excludes SIMD types.\n    #[inline]\n    pub fn is_scalar(&self) -> bool {\n        matches!(*self, BackendRepr::Scalar(_))\n    }\n\n    /// Returns `true` if this is a scalar type or SIMD type.\n    #[inline]\n    pub fn is_scalar_or_simd(&self) -> bool {\n        matches!(\n            *self,\n            BackendRepr::Scalar(_)\n                | BackendRepr::SimdVector { .. }","sourceCodeStart":1833,"sourceCodeEnd":1869,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_abi/src/lib.rs#L1833-L1869","documentation":"Thrown by `BackendRepr::is_signed` at compiler/rustc_abi/src/lib.rs:1851 (sanity check from PR #70189). The method only makes sense for `BackendRepr::Scalar(_)`, because only a single scalar has a well-defined signed/unsigned integer kind. Calling it on `ScalarPair`, `SimdVector`, `SimdScalableVector`, or `Memory` is a category error — those representations have no single sign.","triggerScenarios":"Calling `backend_repr.is_signed()` (or `.is_scalar_signed()`) on a non-scalar `BackendRepr`. Typically reached when generic ABI code assumes the representation is a scalar integer without first checking `is_scalar()`.","commonSituations":"Calling-convention lowering that asks `is_signed()` on a `ScalarPair` (e.g. a `i64` returned with a tag), or on a `Memory` repr for a struct that happens to contain a signed integer. Also seen when a refactor widens the type flowing into a scalar-only helper.","solutions":["Guard the call with `is_scalar()`: `if repr.is_scalar() { repr.is_signed() } else { /* fall back to memory/pair handling */ }`.","Prefer matching explicitly on the `BackendRepr` variant so each case is handled, rather than relying on `is_signed()`'s implicit scalar assumption.","If a signed-ness check is genuinely needed for compound reprs, push the question down to the element `Scalar` rather than the top-level `BackendRepr`."],"exampleFix":"// before\nif backend_repr.is_signed() { emit_signed(...) } else { emit_unsigned(...) }\n\n// after\nmatch backend_repr {\n    BackendRepr::Scalar(s) if s.is_signed() => emit_signed(...),\n    BackendRepr::Scalar(_) => emit_unsigned(...),\n    _ => emit_aggregate(...),\n}","handlingStrategy":"type-guard","validationCode":"// is_signed panics on any non-Scalar BackendRepr. Use is_scalar() first.\nfn backend_is_signed(repr: &rustc_abi::BackendRepr) -> Option<bool> {\n    repr.is_scalar().then(|| {\n        if let rustc_abi::BackendRepr::Scalar(s) = repr { s.is_signed() } else { unreachable!() }\n    })\n}","typeGuard":"fn is_signed_scalar(repr: &rustc_abi::BackendRepr) -> bool {\n    matches!(repr, rustc_abi::BackendRepr::Scalar(s) if s.is_signed())\n}","tryCatchPattern":"// The panic is a sanity check (see PR #70189). Do not catch; fix the caller\n// to verify is_scalar() before invoking is_signed().","preventionTips":["The doc comment calls this a sanity check: it only makes sense to ask signedness of a scalar.","Always pair is_signed() behind an is_scalar() gate, or pattern-match BackendRepr::Scalar(_) explicitly.","For SIMD/Pair/Memory/SimdVector variants, signedness is not a property of the repr."],"tags":["rustc-abi","backendrepr","scalar","signedness","panic","abi"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}