Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept macro_rules name for a macro rule. #2675

Merged
merged 3 commits into from
Oct 17, 2023

Conversation

P-E-P
Copy link
Member

@P-E-P P-E-P commented Oct 10, 2023

This fix allows the user to use the name macro_rules for it's macros.

Fixes #2651

P-E-P added 2 commits October 10, 2023 15:51
Change the constraints around macro rules declaration in order to allow
macro_rules named macro as well as tighter constraint around macro rules
definitions.

gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (Parser::is_macro_rules_def): Add a function
	that checks tokens given by the lexer represents an accurate macro
	definition. This will reduce code duplication.
	(Parser::parse_item): Replace condition with call to new checking
	function.
	(Parser::parse_stmt): Likewise.
	* parse/rust-parse.h: Add function prototype for is_macro_rules_def.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
This new test highlight the fix for Rust-GCC#2651.

gcc/testsuite/ChangeLog:

	* rust/compile/macro_rules_macro_rules.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
@P-E-P P-E-P added this to the GCC 14.1 release milestone Oct 10, 2023
@P-E-P P-E-P requested a review from CohenArthur October 10, 2023 14:23
@P-E-P P-E-P self-assigned this Oct 10, 2023
@P-E-P P-E-P marked this pull request as ready for review October 10, 2023 14:25
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.

this is good, I am a bit scared about this test case which is valid Rust:

macro_rules! macro_rules {
    () => {}
}

macro_rules! foo {
    () => {}
}

foo!();

fn main() {}

but I don't know if we handle it properly

@P-E-P
Copy link
Member Author

P-E-P commented Oct 17, 2023

macro_rules! macro_rules {
    () => {}
}

macro_rules! foo {
    () => {}
}

foo!();

fn main() {}

We do. I can add your test to the testsuite it it puts your mind at rest.

@CohenArthur
Copy link
Member

macro_rules! macro_rules {
    () => {}
}

macro_rules! foo {
    () => {}
}

foo!();

fn main() {}

We do. I can add your test to the testsuite it it puts your mind at rest.

yeah I think that'd be good :) thanks!

Macro rules named macro_rules may cause some problems if not handled
correctly. This new test ensure we always compile those macros named
macro_rules correctly as well as other macro definitions.

gcc/testsuite/ChangeLog:

	* rust/compile/macro57.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
@P-E-P P-E-P enabled auto-merge October 17, 2023 13:31
@P-E-P P-E-P added this pull request to the merge queue Oct 17, 2023
Merged via the queue into Rust-GCC:master with commit c3b68b5 Oct 17, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Macro rule with macro_rules name
2 participants