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

Re-implement concat_idents! in libmacros #826

Merged
merged 1 commit into from
Jul 12, 2022

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Jul 11, 2022

This removes an unstable feature used by kernel modules. The new proc
macro also has different behavior with respect to macro hygiene. Unlike
the unstable concat_idents! macro it for example allows referring to
local variables by taking the span of the second macro as span for the
output identifier.

Signed-off-by: Björn Roy Baron bjorn3_gh@protonmail.com

This removes an unstable feature used by kernel modules. The new proc
macro also has different behavior with respect to macro hygiene. Unlike
the unstable concat_idents! macro it for example allows referring to
local variables by taking the span of the second macro as span for the
output identifier.

Signed-off-by: Björn Roy Baron <bjorn3_gh@protonmail.com>
Copy link

@wedsonaf wedsonaf left a comment

Choose a reason for hiding this comment

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

Nice!

///
/// This is useful in macros that need to declare or reference items with names
/// starting with a fixed prefix and ending in a user specified name. The resulting
/// identifier has the span of the second argument.

Choose a reason for hiding this comment

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

Wouldn't be better to have the span of the proc macro invocation?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would be confusing if the caller of concat_idents! is invoked from another macro, but the identifier originates from outside of this macro.

Choose a reason for hiding this comment

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

Oh, I see. In the example below it would point to one of the BR_ identifiers.

This also assumes that we are prefixing identifiers, but I think it's ok as that's the only usage ATM.

@wedsonaf wedsonaf merged commit 9c9d4b9 into Rust-for-Linux:rust Jul 12, 2022
@bjorn3 bjorn3 deleted the concat_idents_macro branch July 12, 2022 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants