Skip to content

Add base feature gating for derive(CoercePointee) - #4841

Open
CohenArthur wants to merge 3 commits into
masterfrom
derive-coerce-pointee-base-impl
Open

CohenArthur wants to merge 3 commits into
masterfrom
derive-coerce-pointee-base-impl

Conversation

@CohenArthur

Copy link
Copy Markdown
Member

This PR adds more functionality to the BuiltinAttributeChecker class and allows it to
store the list of parsed crate features. The class will then keep an instance of FeatureGate,
and will be able to gate nightly attributes should it need to. This is particularly useful for
checking unstable built-in derives before they get desugared and removed by macro expansion.

We then gate derive(CoercePointee) behind #![feature(derive_coerce_pointee) and start adding the
infrastructure required to support the derive.

gcc/rust/ChangeLog:

	* checks/errors/feature/rust-feature-gate.cc (FeatureGate::visit): Add missing call to
	default visitor for ExternType items.
@CohenArthur CohenArthur added the rust-for-linux Issue related to the compilation of the Linux kernel and its crates label Sep 3, 2026
…gate.

This commit adds more functionality to the BuiltinAttributeChecker class and allows it to
store the list of parsed crate features. The class will then keep an instance of FeatureGate,
and will be able to gate nightly attributes should it need to. This is particularly useful for
checking unstable built-in derives *before* they get desugared and removed by macro expansion.

gcc/rust/ChangeLog:

	* checks/errors/feature/rust-feature-gate.h: Make `gate` public.
	* checks/errors/rust-builtin-attribute-checker.cc: Make all handlers private methods
	instead.
	(lookup_handler): Transform the function to make it return pointer to member functions
	instead.
	(BuiltinAttributeChecker::BuiltinAttributeChecker): Add new argument to constructor to
	take in parsed CrateFeatures&.
	(BuiltinAttributeChecker::visit): Adapt attribute visitor to new lookup_handler function.
	* checks/errors/rust-builtin-attribute-checker.h: Add new declaratiosn for handlers.
	* rust-session-manager.cc (Session::compile_crate): Make BuiltinAttributeChecker run
	before expansion.
Gate derive(CoercePointee) behind `#![feature(derive_coerce_pointee)` and start adding the
infrastructure required to support it.

gcc/rust/ChangeLog:

	* checks/errors/feature/rust-feature-defs.h (FEATURE_ACTIVE): New feature.
	* checks/errors/feature/rust-feature-gate.h: Remove unused method?
	* checks/errors/rust-builtin-attribute-checker.cc (BuiltinAttributeChecker::derive):
	New handler.
	(lookup_handler): Dispatch it.
	* expand/rust-derive.cc (DeriveVisitor::derive): Add base handling for CoercePointee derive.
	* expand/rust-macro-builtins.cc: Add CoercePointee as a built-in derive when compatibility
	mode is greater or equal to 84.
	* expand/rust-macro-builtins.h (enum class): Likewise.
	* resolve/rust-early-name-resolver-2.0.cc (Early::visit_derive_attribute): Special case
	derive(CoercePointee).
	* rust-session-manager.h (should_support_coerce_pointee): New method.

gcc/testsuite/ChangeLog:

	* rust/compile/derive-coerce-pointee1.rs: New test.
	* rust/compile/derive-coerce-pointee2.rs: New test.
	* rust/compile/derive-coerce-pointee3.rs: New test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rust-for-linux Issue related to the compilation of the Linux kernel and its crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant