{"record":{"id":"c36738d120e34396","repo":"rust-lang/rust","slug":"since-this-sanitizerset-is-returned-from-an-iter","errorCode":null,"errorMessage":"Since this `SanitizerSet` is returned from an iterator, exactly one field is set","messagePattern":"Since this `SanitizerSet` is returned from an iterator, exactly one field is set","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs","lineNumber":765,"sourceCode":"                            sym::thread,\n                            sym::hwaddress,\n                            sym::kernel_hwaddress,\n                            sym::realtime,\n                        ],\n                    );\n                }\n            }\n        }\n\n        // The sanitizer attribute is only allowed on statics, if only address bits are set\n        let all_set_except_address =\n            (on_set | off_set) & !(SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS);\n        if cx.target == Target::Static\n            && let Some(set) = all_set_except_address.iter().next()\n        {\n            cx.emit_err(SanitizeInvalidStatic {\n                span: cx.attr_span,\n                field: set.as_str().expect(\"Since this `SanitizerSet` is returned from an iterator, exactly one field is set\")\n            });\n        }\n\n        Some(AttributeKind::Sanitize { on_set, off_set, rtsan, span: cx.attr_span })\n    }\n}\n\npub(crate) struct ThreadLocalParser;\n\nimpl NoArgsAttributeParser for ThreadLocalParser {\n    const PATH: &[Symbol] = &[sym::thread_local];\n    const ALLOWED_TARGETS: AllowedTargets<'_> =\n        AllowedTargets::AllowList(&[Allow(Target::Static), Allow(Target::ForeignStatic)]);\n    const STABILITY: AttributeStability = unstable!(thread_local);\n    const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::ThreadLocal;\n}\n\npub(crate) struct RustcPassIndirectlyInNonRusticAbisParser;","sourceCodeStart":747,"sourceCodeEnd":783,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs#L747-L783","documentation":"codegen_attrs.rs:765: when a sanitizer attribute is used on a static with disallowed bits, the error emitter takes the first bit from the SanitizerSet iterator and calls set.as_str().expect(\"Since this `SanitizerSet` is returned from an iterator, exactly one field is set\"). The invariant: SanitizerSet::iter() yields one bit at a time, so each yielded set has exactly one field and as_str() is Some.","triggerScenarios":"Using #[sanitize(...)] on a static item with a non-address sanitizer; the iterator-yielded single-bit set is converted to a name. A panic would mean as_str() lacks a name for a known sanitizer bit, a compiler-internal table gap.","commonSituations":"Nightly code combining sanitizer attributes with statics; a regression where a sanitizer bit is added to the set but not to the as_str() table.","solutions":["File a rustc ICE; include the sanitizer attribute that triggered it.","Remove the sanitizer attribute from the static, or use only address/kernel-address sanitizers on statics.","Move the sanitized value off a static (e.g. into a function-local or a thread_local).","Bisect with cargo bisect-rustc."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not place non-address sanitizer attributes on static items; only address/kernel-address sanitizers are valid there.","Move sanitized values off statics into function-locals or thread_local when possible.","File a rustc ICE with the sanitizer attribute that triggered it.","Bisect with cargo bisect-rustc to find a sanitizer-table regression."],"tags":["rust","sanitizer","attributes","ice"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}