From: Alice Ryhl <aliceryhl@google.com>
To: ethan.twardy@gmail.com
Cc: a.hindborg@samsung.com, alex.gaynor@gmail.com,
aliceryhl@google.com, aswinunni01@gmail.com,
benno.lossin@proton.me, bjorn3_gh@protonmail.com,
boqun.feng@gmail.com, gary@garyguo.net,
linux-kernel@vger.kernel.org, ojeda@kernel.org,
rust-for-linux@vger.kernel.org, tmgross@umich.edu,
wedsonaf@gmail.com, yakoyoku@gmail.com
Subject: Re: [PATCH 3/4] rust: macros: Enable use from macro_rules!
Date: Mon, 24 Jun 2024 08:43:31 +0000 [thread overview]
Message-ID: <20240624084331.2864993-1-aliceryhl@google.com> (raw)
In-Reply-To: <20240624030327.90301-4-ethan.twardy@gmail.com>
Ethan D. Twardy <ethan.twardy@gmail.com> writes:
> According to the rustdoc for the proc_macro crate[1], tokens captured
> from a "macro variable" (e.g. from within macro_rules!) may be delimited
> by invisible tokens and be contained within a proc_macro::Group.
> Previously, this scenario was not handled by macros::paste, which caused
> a proc-macro panic when the corresponding tests are enabled. Enable the
> tests, and handle this case by making macros::paste::concat recursive.
The actual change looks good to me.
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
However, I have a bunch of formatting nits:
> [1]: https://doc.rust-lang.org/stable/proc_macro/enum.Delimiter.html
>
> Signed-off-by: Ethan D. Twardy <ethan.twardy@gmail.com>
Normally this would be formatted as:
Link: https://doc.rust-lang.org/stable/proc_macro/enum.Delimiter.html [1]
Signed-off-by: Ethan D. Twardy <ethan.twardy@gmail.com>
> diff --git a/rust/macros/lib.rs b/rust/macros/lib.rs
> index d8bd34c0ba89..8afed8facb21 100644
> --- a/rust/macros/lib.rs
> +++ b/rust/macros/lib.rs
> @@ -269,12 +269,26 @@ pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
> ///
> /// # Example
> ///
> -/// ```ignore
> -/// use kernel::macro::paste;
> +/// ```
> +/// # const binder_driver_return_protocol_BR_OK: u32 = 0;
> +/// # const binder_driver_return_protocol_BR_ERROR: u32 = 1;
> +/// # const binder_driver_return_protocol_BR_TRANSACTION: u32 = 2;
> +/// # const binder_driver_return_protocol_BR_REPLY: u32 = 3;
> +/// # const binder_driver_return_protocol_BR_DEAD_REPLY: u32 = 4;
> +/// # const binder_driver_return_protocol_BR_TRANSACTION_COMPLETE: u32 = 5;
> +/// # const binder_driver_return_protocol_BR_INCREFS: u32 = 6;
> +/// # const binder_driver_return_protocol_BR_ACQUIRE: u32 = 7;
> +/// # const binder_driver_return_protocol_BR_RELEASE: u32 = 8;
> +/// # const binder_driver_return_protocol_BR_DECREFS: u32 = 9;
> +/// # const binder_driver_return_protocol_BR_NOOP: u32 = 10;
> +/// # const binder_driver_return_protocol_BR_SPAWN_LOOPER: u32 = 11;
> +/// # const binder_driver_return_protocol_BR_DEAD_BINDER: u32 = 12;
> +/// # const binder_driver_return_protocol_BR_CLEAR_DEATH_NOTIFICATION_DONE: u32 = 13;
> +/// # const binder_driver_return_protocol_BR_FAILED_REPLY: u32 = 14;
> ///
> /// macro_rules! pub_no_prefix {
> /// ($prefix:ident, $($newname:ident),+) => {
There's a non-hidden empty line between the last constant and
`macro_rules! pub_no_prefix`. You should either hide the empty line or
get rid of it, because it will look weird when the example is rendered.
> -/// paste! {
> +/// kernel::macros::paste! {
Another option would be to keep the import so that the empty line
separates the import from the macro declaration.
> /// $(pub(crate) const $newname: u32 = [<$prefix $newname>];)+
> /// }
> /// };
> @@ -313,13 +327,29 @@ pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
> /// * `lower`: change the identifier to lower case.
> /// * `upper`: change the identifier to upper case.
> ///
> -/// ```ignore
> -/// use kernel::macro::paste;
> +/// ```rust
> +/// # const binder_driver_return_protocol_BR_OK: u32 = 0;
> +/// # const binder_driver_return_protocol_BR_ERROR: u32 = 1;
> +/// # const binder_driver_return_protocol_BR_TRANSACTION: u32 = 2;
> +/// # const binder_driver_return_protocol_BR_REPLY: u32 = 3;
> +/// # const binder_driver_return_protocol_BR_DEAD_REPLY: u32 = 4;
> +/// # const binder_driver_return_protocol_BR_TRANSACTION_COMPLETE: u32 = 5;
> +/// # const binder_driver_return_protocol_BR_INCREFS: u32 = 6;
> +/// # const binder_driver_return_protocol_BR_ACQUIRE: u32 = 7;
> +/// # const binder_driver_return_protocol_BR_RELEASE: u32 = 8;
> +/// # const binder_driver_return_protocol_BR_DECREFS: u32 = 9;
> +/// # const binder_driver_return_protocol_BR_NOOP: u32 = 10;
> +/// # const binder_driver_return_protocol_BR_SPAWN_LOOPER: u32 = 11;
> +/// # const binder_driver_return_protocol_BR_DEAD_BINDER: u32 = 12;
> +/// # const binder_driver_return_protocol_BR_CLEAR_DEATH_NOTIFICATION_DONE: u32 = 13;
> +/// # const binder_driver_return_protocol_BR_FAILED_REPLY: u32 = 14;
> ///
> /// macro_rules! pub_no_prefix {
> /// ($prefix:ident, $($newname:ident),+) => {
Same here.
> /// kernel::macros::paste! {
> -/// $(pub(crate) const fn [<$newname:lower:span>]: u32 = [<$prefix $newname:span>];)+
> +/// $(pub(crate) const fn [<$newname:lower:span>]() -> u32 {
> +/// [<$prefix $newname:span>]
> +/// })+
I would probably indent [<$prefix $newname:span>] one more time.
Alice
next prev parent reply other threads:[~2024-06-24 8:43 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-24 3:03 [PATCH 0/4] Enable rustdoc tests for the macros crate Ethan D. Twardy
2024-06-24 3:03 ` [PATCH 1/4] kbuild: rust: Expand rusttest target for macros Ethan D. Twardy
2024-06-26 4:20 ` kernel test robot
2024-06-24 3:03 ` [PATCH 2/4] rust: Enable test for macros::module Ethan D. Twardy
2024-06-24 8:32 ` Alice Ryhl
2024-06-26 23:05 ` Ethan D. Twardy
2024-06-24 3:03 ` [PATCH 3/4] rust: macros: Enable use from macro_rules! Ethan D. Twardy
2024-06-24 8:43 ` Alice Ryhl [this message]
2024-06-26 23:08 ` Ethan D. Twardy
2024-06-24 3:03 ` [PATCH 4/4] rust: macros: Enable the rest of the tests Ethan D. Twardy
2024-06-24 8:47 ` Alice Ryhl
2024-06-26 23:12 ` Ethan D. Twardy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240624084331.2864993-1-aliceryhl@google.com \
--to=aliceryhl@google.com \
--cc=a.hindborg@samsung.com \
--cc=alex.gaynor@gmail.com \
--cc=aswinunni01@gmail.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=ethan.twardy@gmail.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=wedsonaf@gmail.com \
--cc=yakoyoku@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox