rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alice Ryhl <alice@ryhl.io>
To: Benno Lossin <benno.lossin@proton.me>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	patches@lists.linux.dev, "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>
Subject: Re: [PATCH 2/4] rust: macros: refactor generics parsing of `#[pin_data]` into its own function
Date: Wed, 17 May 2023 22:44:39 +0200	[thread overview]
Message-ID: <3532c544-7804-3dba-225e-69a7fb8418c4@ryhl.io> (raw)
In-Reply-To: <20230424081112.99890-2-benno.lossin@proton.me>

On 4/24/23 10:11, Benno Lossin wrote:
> Other macros might also want to parse generics. Additionally this makes
> the code easier to read, as the next commit will introduce more code in
> `#[pin_data]`. Also add more comments to explain how parsing generics
> work.
> 
> Signed-off-by: Benno Lossin <benno.lossin@proton.me>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>

> +/// Parses the given `TokenStream` into `Generics` and the rest.
> +///
> +/// The generics are not present in the rest, but a where clause might remain.
> +pub(crate) fn parse_generics(input: TokenStream) -> (Generics, Vec<TokenTree>) {
> +    // `impl_generics`, the declared generics with their bounds.
> +    let mut impl_generics = vec![];
> +    // Only the names of the generics, without any bounds.
> +    let mut ty_generics = vec![];
> +    // Tokens not related to the generics e.g. the `where` token and definition.
> +    let mut rest = vec![];
> +    // The current level of `<`.
> +    let mut nesting = 0;
> +    let mut toks = input.into_iter();
> +    // If we are at the beginning of a generic parameter.
> +    let mut at_start = true;
> +    for tt in &mut toks {
> +        match tt.clone() {

Do you need the call to `clone` here? Not a big deal either way.

  parent reply	other threads:[~2023-05-17 20:44 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-24  8:11 [PATCH 1/4] rust: macros: fix usage of `#[allow]` in `quote!` Benno Lossin
2023-04-24  8:11 ` [PATCH 2/4] rust: macros: refactor generics parsing of `#[pin_data]` into its own function Benno Lossin
2023-04-24 13:01   ` Martin Rodriguez Reboredo
2023-05-17 20:44   ` Alice Ryhl [this message]
2023-05-23 16:04   ` Gary Guo
2023-04-24  8:11 ` [PATCH 3/4] rust: macros: replace Self with the concrete type in #[pin_data] Benno Lossin
2023-04-24 14:21   ` Martin Rodriguez Reboredo
2023-05-17 20:46   ` Alice Ryhl
2023-05-23 16:12   ` Gary Guo
2023-04-24  8:11 ` [PATCH 4/4] rust: init: update macro expansion example in docs Benno Lossin
2023-04-24 14:24   ` Martin Rodriguez Reboredo
2023-05-17 20:48   ` Alice Ryhl
2023-05-23 16:15   ` Gary Guo
2023-04-24 12:59 ` [PATCH 1/4] rust: macros: fix usage of `#[allow]` in `quote!` Martin Rodriguez Reboredo
2023-05-17 20:41 ` Alice Ryhl
2023-05-23 16:02 ` Gary Guo
2023-05-31 17:07 ` Miguel Ojeda

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=3532c544-7804-3dba-225e-69a7fb8418c4@ryhl.io \
    --to=alice@ryhl.io \
    --cc=alex.gaynor@gmail.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=patches@lists.linux.dev \
    --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).