Updates

GCC's gccrs adds constexpr crate_name and crate_type to rust-attributes.h

gccrs added constexpr values for crate_name and crate_type and introduced a new gcc/rust/util/rust-attributes.h (270 lines) containing an AttributeChecker and many AST visit() declarations.

Nina Kowalski2 min read
Published
Listen to this article0:00 min
Share this article:
GCC's gccrs adds constexpr crate_name and crate_type to rust-attributes.h
AI-generated illustration

A commit note posted to the GCC patch mailing list on February 26, 2026 reports that the gccrs repository "added constexpr values for crate_name and crate_type into its internal rust‑attribute values header and updated rust‑session‑manager cod". The accompanying diff shows a new header file added at gcc/rust/util/rust-attributes.h with git metadata "new file mode 100644", "index 00000000000..3ac93ff5908" and "@@ -0,0 +1,270 @@", indicating 270 lines in the addition.

The diff excerpt includes the standard GNU license header, starting with "// Copyright (C) 2020-2022 Free Software Foundation, Inc.", and the body of the new header declares an AttributeChecker type and several public and private methods. Verbatim fragments in the patch show "AttributeChecker ();", "void go (AST::Crate &crate);", "void check_attribute (const AST::Attribute &attribute);" and "void check_attributes (const AST::AttrVec &attributes);". The snippet also closes namespaces with the lines "+} // namespace Analysis +} // namespace Rust", indicating the AttributeChecker and visitors live under Rust::Analysis in the new file.

Beyond the AttributeChecker, the rust-attributes.h excerpt contains many AST visitor declarations. The provided additions include lines such as "void visit (AST::Token &tok);", "void visit (AST::DelimTokenTree &delim_tok_tree);", "void visit (AST::AttrInputMetaItemContainer &input);", "void visit (AST::IdentifierExpr &ident_expr);", "void visit (AST::Lifetime &lifetime);", "void visit (AST::LifetimeParam &lifetime_param);", "void visit (AST::ConstGenericParam &const_param);" and later "void visit (AST::Method &method);", "void visit (AST::Module &module);", "void visit (AST::ExternCrate &crate);", "void visit (AST::UseTreeGlob &use_tree);", "void visit (AST::UseDeclaration &use_decl);", "void visit (AST::Function &function);", "void visit (AST::TypeAlias &type_alias);", "void visit (AST::StructStruct &struct_item);", "void visit (AST::Enum &enum_item);", "void visit (AST::Union &union_item);" and "void visit (AST::ConstantItem &const_item);". Those lines in the diff show a broad surface for attribute validation across tokens, paths, items and module-level constructs.

The commit note claims constexpr entries for crate_name and crate_type, but the provided diff excerpt does not include explicit constexpr declarations for those attribute names and the commit note text itself is truncated at the end of the line as "cod". The Rust language documentation excerpt included with the materials states plainly: "The `crate_type` and `crate_name` attributes cannot be used with `cfg_attr`." The docs further specify that "When the configuration predicate is true, `cfg_attr` expands out to the attributes listed after the predicate" and illustrate expansion with the example "#[cfg_attr(feature = "magic", sparkles, crackles)] fn bewitched() {} // When the `magic` feature flag is enabled, the above will expand to: #[sparkles] #[crackles] fn bewitched() {}".

Taken together, the patch-level evidence and the commit note indicate gccrs has added a new rust-attributes.h at gcc/rust/util with an AttributeChecker and many visit() methods, and the commit note asserts constexpr values for crate_name and crate_type were added. The provided excerpts do not show the actual constexpr lines nor the full rust-session-manager change, and the commit-note fragment ends with "updated rust‑session‑manager cod". The full patch on the GCC patch mailing list or the gccrs repository will contain the complete rust-attributes.h and the rust-session-manager updates needed to confirm how crate_name and crate_type are represented and whether gccrs implements any checks tied to Rust's cfg_attr constraints.

Know something we missed? Have a correction or additional information?

Submit a Tip
Your Topic
Today's stories
Updated daily by AI

Name any topic. Get daily articles.

You pick the subject, AI does the rest.

Start Now - Free

Ready in 2 minutes

Discussion

More Rust Programming News