rust-lang/rust · error

Since this `SanitizerSet` is returned from an iterator, exac

Error message

Since this `SanitizerSet` is returned from an iterator, exactly one field is set

What it means

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.

Source

Thrown at compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs:765

                            sym::thread,
                            sym::hwaddress,
                            sym::kernel_hwaddress,
                            sym::realtime,
                        ],
                    );
                }
            }
        }

        // The sanitizer attribute is only allowed on statics, if only address bits are set
        let all_set_except_address =
            (on_set | off_set) & !(SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS);
        if cx.target == Target::Static
            && let Some(set) = all_set_except_address.iter().next()
        {
            cx.emit_err(SanitizeInvalidStatic {
                span: cx.attr_span,
                field: set.as_str().expect("Since this `SanitizerSet` is returned from an iterator, exactly one field is set")
            });
        }

        Some(AttributeKind::Sanitize { on_set, off_set, rtsan, span: cx.attr_span })
    }
}

pub(crate) struct ThreadLocalParser;

impl NoArgsAttributeParser for ThreadLocalParser {
    const PATH: &[Symbol] = &[sym::thread_local];
    const ALLOWED_TARGETS: AllowedTargets<'_> =
        AllowedTargets::AllowList(&[Allow(Target::Static), Allow(Target::ForeignStatic)]);
    const STABILITY: AttributeStability = unstable!(thread_local);
    const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::ThreadLocal;
}

pub(crate) struct RustcPassIndirectlyInNonRusticAbisParser;

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. File a rustc ICE; include the sanitizer attribute that triggered it.
  2. Remove the sanitizer attribute from the static, or use only address/kernel-address sanitizers on statics.
  3. Move the sanitized value off a static (e.g. into a function-local or a thread_local).
  4. Bisect with cargo bisect-rustc.
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/c36738d120e34396. Report an issue: GitHub.