From: Finn Behrens <fin@nyantec.com>
To: Asahi Lina <lina@asahilina.net>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
asahi@lists.linux.dev
Subject: Re: [PATCH 1/3] rust: macros: Make expect_punct() return the Punct directly
Date: Tue, 28 Feb 2023 10:29:59 +0100 [thread overview]
Message-ID: <A74F7C50-1F28-4416-8E99-27B9F63A352B@nyantec.com> (raw)
In-Reply-To: <20230224-rust-macros-v1-1-b39fae46e102@asahilina.net>
On 24 Feb 2023, at 8:25, Asahi Lina wrote:
> This makes it mirror the way expect_ident() works, and means we can more
> easily push the result back into the token stream.
>
> Signed-off-by: Asahi Lina <lina@asahilina.net>
Reviewed-by: Finn Behrens <fin@nyantec.com>
> ---
> rust/macros/concat_idents.rs | 2 +-
> rust/macros/helpers.rs | 6 +++---
> rust/macros/module.rs | 4 ++--
> 3 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/rust/macros/concat_idents.rs b/rust/macros/concat_idents.rs
> index 7e4b450f3a50..6d955d65016e 100644
> --- a/rust/macros/concat_idents.rs
> +++ b/rust/macros/concat_idents.rs
> @@ -15,7 +15,7 @@ fn expect_ident(it: &mut token_stream::IntoIter) -> Ident {
> pub(crate) fn concat_idents(ts: TokenStream) -> TokenStream {
> let mut it = ts.into_iter();
> let a = expect_ident(&mut it);
> - assert_eq!(expect_punct(&mut it), ',');
> + assert_eq!(expect_punct(&mut it).as_char(), ',');
> let b = expect_ident(&mut it);
> assert!(it.next().is_none(), "only two idents can be concatenated");
> let res = Ident::new(&format!("{a}{b}"), b.span());
> diff --git a/rust/macros/helpers.rs b/rust/macros/helpers.rs
> index cf7ad950dc1e..65706ecc007e 100644
> --- a/rust/macros/helpers.rs
> +++ b/rust/macros/helpers.rs
> @@ -1,6 +1,6 @@
> // SPDX-License-Identifier: GPL-2.0
>
> -use proc_macro::{token_stream, TokenTree};
> +use proc_macro::{token_stream, Punct, TokenTree};
>
> pub(crate) fn try_ident(it: &mut token_stream::IntoIter) -> Option<String> {
> if let Some(TokenTree::Ident(ident)) = it.next() {
> @@ -38,9 +38,9 @@ pub(crate) fn expect_ident(it: &mut token_stream::IntoIter) -> String {
> try_ident(it).expect("Expected Ident")
> }
>
> -pub(crate) fn expect_punct(it: &mut token_stream::IntoIter) -> char {
> +pub(crate) fn expect_punct(it: &mut token_stream::IntoIter) -> Punct {
> if let TokenTree::Punct(punct) = it.next().expect("Reached end of token stream for Punct") {
> - punct.as_char()
> + punct
> } else {
> panic!("Expected Punct");
> }
> diff --git a/rust/macros/module.rs b/rust/macros/module.rs
> index a7e363c2b044..07503b242d2d 100644
> --- a/rust/macros/module.rs
> +++ b/rust/macros/module.rs
> @@ -104,7 +104,7 @@ impl ModuleInfo {
> );
> }
>
> - assert_eq!(expect_punct(it), ':');
> + assert_eq!(expect_punct(it).as_char(), ':');
>
> match key.as_str() {
> "type" => info.type_ = expect_ident(it),
> @@ -119,7 +119,7 @@ impl ModuleInfo {
> ),
> }
>
> - assert_eq!(expect_punct(it), ',');
> + assert_eq!(expect_punct(it).as_char(), ',');
>
> seen_keys.push(key);
> }
>
> --
> 2.35.1
next prev parent reply other threads:[~2023-02-28 9:30 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-24 7:25 [PATCH 0/3] rust: Miscellaneous macro improvements Asahi Lina
2023-02-24 7:25 ` [PATCH 1/3] rust: macros: Make expect_punct() return the Punct directly Asahi Lina
2023-02-25 0:29 ` Gary Guo
2023-02-28 9:29 ` Finn Behrens [this message]
2023-03-01 17:16 ` Vincenzo Palazzo
2023-02-24 7:25 ` [PATCH 2/3] rust: macros: concat_idents: Allow :: paths in the first argument Asahi Lina
2023-02-25 0:31 ` Gary Guo
2023-03-07 20:22 ` Miguel Ojeda
2023-03-08 20:57 ` Miguel Ojeda
2023-03-01 17:18 ` Vincenzo Palazzo
2023-02-24 7:25 ` [PATCH 3/3] rust: macros: Allow specifying multiple module aliases Asahi Lina
2023-02-24 7:38 ` Greg KH
2023-02-24 12:41 ` Asahi Lina
2023-02-24 12:49 ` Greg KH
2023-03-01 17:19 ` Vincenzo Palazzo
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=A74F7C50-1F28-4416-8E99-27B9F63A352B@nyantec.com \
--to=fin@nyantec.com \
--cc=alex.gaynor@gmail.com \
--cc=asahi@lists.linux.dev \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=lina@asahilina.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=wedsonaf@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;
as well as URLs for NNTP newsgroup(s).