Messages in this thread | | | Date | Wed, 17 May 2023 22:44:39 +0200 | Subject | Re: [PATCH 2/4] rust: macros: refactor generics parsing of `#[pin_data]` into its own function | From | Alice Ryhl <> |
| |
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.
| |