Skip to content

Improve feature collection and permit macro attribute input#4425

Open
P-E-P wants to merge 7 commits intoRust-GCC:masterfrom
P-E-P:feature_collector
Open

Improve feature collection and permit macro attribute input#4425
P-E-P wants to merge 7 commits intoRust-GCC:masterfrom
P-E-P:feature_collector

Conversation

@P-E-P
Copy link
Member

@P-E-P P-E-P commented Feb 6, 2026

No description provided.

@P-E-P P-E-P force-pushed the feature_collector branch 2 times, most recently from d6e2638 to 946e07e Compare February 6, 2026 22:26
@P-E-P P-E-P marked this pull request as ready for review February 6, 2026 22:30
@P-E-P P-E-P force-pushed the feature_collector branch from c748a69 to 5b8cec3 Compare February 7, 2026 02:01
P-E-P added 7 commits February 7, 2026 03:02
Rename is_builtin to identify_builtin and change prototype to return the
builtin when found.

gcc/rust/ChangeLog:

	* util/rust-attributes.cc (is_builtin): Rename from here ...
	(identify_builtin): ... to here.
	(is_proc_macro_type): Handle new return value.
	(AttributeChecker::check_inner_attribute): Likewise.
	(AttributeChecker::check_attribute): Likewise.
	(AttributeChecker::visit): Likewise.
	* util/rust-attributes.h (identify_builtin): Update function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Feature collection should happen before expansion because some feature
gating happens with macros. This commit does no move the feature
collection before the expansion pass, it simply split the collection part
from the gating part.

gcc/rust/ChangeLog:

	* Make-lang.in: Add new feature collector file.
	* checks/errors/feature/rust-feature-gate.cc (FeatureGate::visit):
	Remove feature collection from gating visitor.
	(FeatureGate::gate): Use features from the crate feature entity instead
	of old class members.
	* checks/errors/feature/rust-feature-gate.h: Get features from a
	separate CrateFeatures struct instead of keeping them in the class.
	* rust-session-manager.cc (Session::compile_crate): Collect features
	before gating them.
	* util/rust-attribute-values.h: Add feature attribute value.
	* checks/errors/feature/rust-feature-collector.cc: New file.
	* checks/errors/feature/rust-feature-collector.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ChangeLog:

	* expand/rust-cfg-strip.cc (CfgStrip::fails_cfg): Remove function.
	* expand/rust-cfg-strip.h: Remove function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Features are now collected early rather than later during the feature
gating visitor. This requires the introduction of an early cfg strip
in order to collect #![cfg(xxxx), feature(yyyy)] correctly.

gcc/rust/ChangeLog:

	* Make-lang.in: Add rust-early-cfg-strip object file.
	* expand/rust-cfg-strip.h (expand_cfg_attrs): Declare function prototype.
	* rust-session-manager.cc (Session::compile_crate): Reorder feature
	collection and add early cfg strip.
	* expand/rust-early-cfg-strip.cc: New file.
	* expand/rust-early-cfg-strip.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
rust-for-linux uses some nightly features that appeared with rust 1.50.

gcc/rust/ChangeLog:

	* checks/errors/feature/contrib/fetch: Bump version from 1.49.0 to
	1.50.0. Change brace expansion to explicit file fetch.
	* checks/errors/feature/rust-feature-defs.h: Regenerate.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Some nightly features change the parser's behavior, it may accepts syntax
that should be rejected when the feature is missing. But the complete
list of enabled features can only be found once the parsing is complete.
We should therefore not emit any error at parse time and instead collect
a potential error and emit it later during the feature gating step.

gcc/rust/ChangeLog:

	* checks/errors/feature/rust-feature-gate.cc (FeatureGate::check):
	Check all parse time errors.
	* checks/errors/feature/rust-feature-gate.h: Update function prototype
	with parse time errors.
	* parse/rust-parse-impl-attribute.hxx: Collect potential gating error
	with non literal attribute values. Remove error emission.
	* parse/rust-parse.h: Add a function to gather potential feature gating
	errors as well as a getter for collected errors.
	* rust-session-manager.cc (Session::compile_crate): Retrieve potential
	feature gating errors and check them later during the feature gating
	step.
	* util/rust-attributes.cc (check_export_name_attribute): Change
	attribute checking error emission to prevent errors with macro inputs.

gcc/testsuite/ChangeLog:

	* rust/compile/doc_macro.rs: Enable feature to use a macro within an
	attribute input.
	* rust/compile/parse_time_feature_gate.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
We use multiple parsers and can't retrieve all early feature gating
errors within the usual gating pass. This commit introduces a store to
collect all early gating errors in the same place from multiple parsers.
The features are then checked as usual within the feature gate checker.

gcc/rust/ChangeLog:

	* checks/errors/feature/rust-feature-gate.cc (EarlyFeatureGateStore::get):
	Add function to retrieve singleton instance.
	(EarlyFeatureGateStore::add): New function to add an error and the
	corresponding feature in the store.
	(EarlyFeatureGateStore::get_error): Add new function to retrieve the
	oldest error.
	(FeatureGate::check): Update the function to retrieve the errors from
	the store instead of getting it from the parameters.
	* checks/errors/feature/rust-feature-gate.h (class EarlyFeatureGateStore):
	Add a new class to collect all early feature gating errors.
	* parse/rust-parse.h: Use store instead of keeping the errors within
	the parser instance.
	* rust-session-manager.cc (Session::compile_crate): Remove old early
	error collection from the main parser.
	* rust-system.h: Include queue header.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-3661.rs: Add key_value_attribute feature to
	prevent error on stringify macro.
	* rust/compile/early_feature_gate_in_macro.rs: Add test to highlight
	early feature gate error collection within macros.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
@P-E-P P-E-P force-pushed the feature_collector branch from 5b8cec3 to bd9918d Compare February 7, 2026 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant