rust-lang/rust · error

cfg_attr has docs

Error message

cfg_attr has docs

What it means

cfg.rs:333: when emitting a cfg_attr parse error, the compiler appends a docs link from CFG_ATTR_TEMPLATE.docs.expect("cfg_attr has docs"). CFG_ATTR_TEMPLATE is a static AttributeTemplate built into the compiler; its `docs` field is populated at compiler-build time. A panic means the template was misconfigured when the compiler was compiled.

Source

Thrown at compiler/rustc_attr_parsing/src/attributes/cfg.rs:333

            match parse_in(&sess.psess, tokens.clone(), "`cfg_attr` input", |p| {
                parse_cfg_attr_internal(p, sess, features, lint_node_id, cfg_attr)
            }) {
                Ok(r) => return Some(r),
                Err(e) => {
                    let suggestions = CFG_ATTR_TEMPLATE.suggestions(
                        ParsedDescription::Attribute,
                        cfg_attr.get_normal_item().unsafety,
                        sym::cfg_attr,
                    );
                    e.with_span_suggestions(
                        cfg_attr.get_normal_item().span,
                        "must be of the form",
                        suggestions,
                        Applicability::HasPlaceholders,
                    )
                    .with_note(format!(
                        "for more information, visit <{}>",
                        CFG_ATTR_TEMPLATE.docs.expect("cfg_attr has docs")
                    ))
                    .emit();
                }
            }
        }
        _ => {
            let (span, reason) = if let ast::AttrArgs::Delimited(ast::DelimArgs { dspan, .. }) =
                cfg_attr.get_normal_item().args
            {
                (dspan.entire(), AttributeParseErrorReason::ExpectedAtLeastOneArgument)
            } else {
                (cfg_attr.get_normal_item().span, AttributeParseErrorReason::ExpectedList)
            };

            sess.dcx().emit_err(AttributeParseError {
                span,
                inner_span: cfg_attr.get_normal_item().span,
                template: CFG_ATTR_TEMPLATE,

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. Use a stock official toolchain (rustup) rather than a custom-built compiler.
  2. Fix the #[cfg_attr(...)] syntax that surfaced the error path (form must be #[cfg_attr(condition, attr)]).
  3. If building the compiler, ensure the cfg_attr template includes its docs URL.
  4. Report the issue against the custom rustc build.
Defensive patterns

Strategy: fallback

Prevention

When it happens

Trigger: A malformed #[cfg_attr(...)] triggers the error path that reads the template's docs link, but the static template has docs == None. This is a compiler-build configuration bug, not triggered by user code specifically.

Common situations: A rustc build where the cfg_attr AttributeTemplate was constructed without a docs URL; essentially impossible in a stock toolchain, only in a misbuilt/custom compiler.

Related errors


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