Skip to content

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

Merged
CohenArthur merged 2 commits into
masterfrom
derive-coerce-pointee-base-impl
Sep 28, 2026
Merged

CohenArthur merged 2 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.

@CohenArthur CohenArthur added the rust-for-linux Issue related to the compilation of the Linux kernel and its crates label Sep 3, 2026
@CohenArthur
CohenArthur force-pushed the derive-coerce-pointee-base-impl branch from 159f32a to 696df5c Compare September 18, 2026 16:36
@P-E-P
P-E-P self-requested a review September 28, 2026 08:23
Comment thread gcc/rust/expand/rust-macro-builtins.cc Outdated
{"Ord", BuiltinMacro::Ord},
{"PartialOrd", BuiltinMacro::PartialOrd},
{"Hash", BuiltinMacro::Hash},
// FIXME: Only in compatibility mode >= 1.84

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment confuses me. Should we forbid this builtin macro outside of the feature gating mechanisms ? If so we should probably implement a filtering function and restrict their access completely.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can probably remove the comment tbh. At this point the check will happen anyways and the macro won't resolve if we're not in compatibility mode.

gcc/rust/ChangeLog:

	* checks/errors/feature/rust-feature-gate.cc (FeatureGate::visit): Add missing call to
	default visitor for ExternType items.
Gate derive(CoercePointee) behind `#![feature(derive_coerce_pointee)` and start adding the
infrastructure required to support it. Warn that it doesn't do anything yet.

gcc/rust/ChangeLog:

	* checks/errors/feature/rust-feature-defs.h (FEATURE_ACTIVE): New feature.
	* expand/rust-derive.cc (DeriveVisitor::derive): Add base handling for CoercePointee derive.
	* expand/rust-macro-builtins.cc: Add CoercePointee as a built-in derive
	* 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.
	* expand/rust-derive-coerce-pointee.cc: New file.
	* expand/rust-derive-coerce-pointee.h: New file.
	* Make-lang.in: Compile it.

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.
@CohenArthur
CohenArthur force-pushed the derive-coerce-pointee-base-impl branch from 696df5c to cc0597d Compare September 28, 2026 15:43
@CohenArthur
CohenArthur added this pull request to the merge queue Sep 28, 2026
Merged via the queue into master with commit 0fed9b4 Sep 28, 2026
13 checks passed
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.

2 participants