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
- Use a stock official toolchain (rustup) rather than a custom-built compiler.
- Fix the #[cfg_attr(...)] syntax that surfaced the error path (form must be #[cfg_attr(condition, attr)]).
- If building the compiler, ensure the cfg_attr template includes its docs URL.
- Report the issue against the custom rustc build.
Defensive patterns
Strategy: fallback
Prevention
- Use a stock official rustup toolchain instead of a custom-built compiler.
- Fix the #[cfg_attr(condition, attr)] syntax that surfaces the error path.
- If building the compiler, ensure the cfg_attr AttributeTemplate carries its docs URL.
- Report misbuilt-compiler issues against the custom build, not upstream.
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
- features not available at this point in the compiler
- alt layout should always work
- alt layout should have a niche like the regular one
- `Self` generic param is not found while expected
- must be at least one segment
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/5d5f0058f6b28c98.
Report an issue: GitHub.