Skip to content

derive: Implement reconstruct_path helper for cmp#4395

Open
Pasta-coder wants to merge 1 commit intoRust-GCC:masterfrom
Pasta-coder:fix/derive-cmp-reconstruct
Open

derive: Implement reconstruct_path helper for cmp#4395
Pasta-coder wants to merge 1 commit intoRust-GCC:masterfrom
Pasta-coder:fix/derive-cmp-reconstruct

Conversation

@Pasta-coder
Copy link
Contributor

This patch introduces a local helper to clone
PathInExpression objects. This allows removing duplicate calls to , fulfilling the TODOs in EnumMatchBuilder.
This ensures the self and other paths are identical without reconstructing them from strings twice.

gcc/rust/ChangeLog:

* expand/rust-derive-cmp-common.cc (reconstruct_path): New helper.
(EnumMatchBuilder::tuple): Use reconstruct_path.
(EnumMatchBuilder::strukt): Use reconstruct_path.

Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

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

So I'm not necessarily against these changes, but the goal with this comment here was to do something like #3799 but for other base classes. I think we can merge this but I'd rather see the entire thing being implemented

@Pasta-coder
Copy link
Contributor Author

thank you for the review .

will modify accordingly .

@Pasta-coder Pasta-coder marked this pull request as draft January 18, 2026 05:21
@Pasta-coder Pasta-coder force-pushed the fix/derive-cmp-reconstruct branch 4 times, most recently from 35e4800 to 84223c7 Compare February 1, 2026 19:03
@Pasta-coder Pasta-coder marked this pull request as ready for review February 1, 2026 21:13
@Pasta-coder
Copy link
Contributor Author

Pasta-coder commented Feb 1, 2026

@CohenArthur Thanks for the review !

I've refactored the implementation to follow the established reconstruct() pattern across the entire Path hierarchy, similar to what was done for types in #3799 .

thankyou .

@Pasta-coder Pasta-coder marked this pull request as draft February 4, 2026 20:40
@Pasta-coder Pasta-coder force-pushed the fix/derive-cmp-reconstruct branch from 84223c7 to 78363a6 Compare February 5, 2026 08:23
@Pasta-coder Pasta-coder marked this pull request as ready for review February 5, 2026 11:44
@Pasta-coder Pasta-coder marked this pull request as draft February 5, 2026 16:38
@Pasta-coder Pasta-coder force-pushed the fix/derive-cmp-reconstruct branch 3 times, most recently from c85f3df to 7e759df Compare February 6, 2026 08:03
This patch implements the `reconstruct` pattern for the `Path` hierarchy and its
constituents (segments, generic args, qualified paths).

Previously, derive expansion macros (like `derive(PartialEq)`) had to manually
rebuild paths field-by-field to ensure fresh NodeIDs. This change moves that
logic into the AST classes themselves, allowing paths to be deeply reconstructed
uniformly. This ensures that expanded code has unique NodeIDs, which is critical
for correct name resolution.

gcc/rust/ChangeLog:

	* ast/rust-path.h (GenericArgsBinding::reconstruct): New method.
	(GenericArg::reconstruct): New method.
	(GenericArgs::reconstruct): New method.
	(PathExprSegment::reconstruct): New method.
	(PathInExpression::reconstruct): New method.
	(TypePathSegmentGeneric::reconstruct_impl): New method.
	(TypePathFunction::reconstruct): New method.
	(TypePathSegmentFunction::reconstruct_impl): New method.
	(QualifiedPathType::reconstruct): New method.
	(QualifiedPathInExpression::reconstruct): New method.
	(QualifiedPathInType::reconstruct_impl): New method.
	* expand/rust-derive-cmp-common.cc (EnumMatchBuilder::tuple): Use path.reconstruct().
	(EnumMatchBuilder::strukt): Use path.reconstruct().

Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
@Pasta-coder Pasta-coder force-pushed the fix/derive-cmp-reconstruct branch from 7e759df to 7b27b33 Compare February 6, 2026 09:11
@Pasta-coder
Copy link
Contributor Author

The changes implement reconstruct() methods for all Path-related classes in rust-path.h, eliminating the need for manual field-by-field reconstruction in derive macros. This ensures consistent NodeID generation and removes the redundant path construction .

also tagging @powerboat9 to get reviews .

thankyou .

@Pasta-coder Pasta-coder marked this pull request as ready for review February 6, 2026 11:39
@Pasta-coder
Copy link
Contributor Author

@P-E-P please review .

thankyou .

Note: Since Path inherits from Pattern, I will be updating these implementations in my PR (#4431) to override the new Pattern::reconstruct_impl virtual method. This PR establishes the logic, and #4431 will adapt it to the full architecture.

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.

3 participants