Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp30983rwd; Wed, 17 May 2023 14:09:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5agbH8QjYw6XaQ6ngSXJiAT0719tiwZQYZxXC/Xn6KpgtMCiWfCEqT+JwR07ONE8GFjFLh X-Received: by 2002:a05:6a20:3947:b0:104:b21f:26b0 with SMTP id r7-20020a056a20394700b00104b21f26b0mr24810636pzg.47.1684357779012; Wed, 17 May 2023 14:09:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684357778; cv=none; d=google.com; s=arc-20160816; b=lp7S2M7V8LOMZ/NY9skdNZis8bt+7aDaKy2fAWfSfId8Hlj+4CQsjxJC0uM/1pE3Ll BuUisZ18YBFfHPau1dAWGR6X5nn0cYz9TAZ1xY7RQ3nPDp2qK8VdLWxIhs6CNiZ54uK6 aJ5wte1687qp5XlNPuOqyvvm4LLuW14ni3Yqh7DOHr6f8DiZTUuwgz+FkyVOp5udiuRG lQ4WtoGGr+4ickxuXG+G9kRZ3jy/YxxDAYJeg7QyktzCZIVVaVL0zPO1yVFomLjliZ30 yPcVZVXq+sJo4tycYx3CZKyTgmmGk0yAjbH2xtruHeSDVnFOWf229sH2X9K8p6d1Xlu7 F5FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:feedback-id:dkim-signature:dkim-signature; bh=HovA2aBrCor3Q17F+fDmTxCq7878dGESxOgv5brW2DI=; b=QO3dQI8kHlU8ed/HC1wIoKwSY47Z9zaJfwaiawTmZTZb4XtOQXvOchjOu6ta1k9NNx kPgXVsiqj9s0Jvzgz/1a277iQGCchPCPnzRwz0paHEauiZ/ZujROe0msFYgNHzDDm54V GmF6An4v5wbQONlffFc3LPTDh8Reni9oOq7isK0XgjRR3YErkaSB8uB/orLWgE7ON3as pPzM8p3EW2XrfBo6V+0u5T3V+O0hMYZow6wSmD+Lnn8kTqR+epUtyuTe+8hgP1adgmop rAJ265Mic3ZXakkUnbb3oR6DHZ1N25viuBWTQVlwUo/y7p2ROlIaLf1v1tmrfB8+5616 JcsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ryhl.io header.s=fm1 header.b=ZsffjI3u; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=WC8QymsV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ryhl.io Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o10-20020a637e4a000000b00524b3efc310si21353280pgn.83.2023.05.17.14.09.06; Wed, 17 May 2023 14:09:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ryhl.io header.s=fm1 header.b=ZsffjI3u; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=WC8QymsV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ryhl.io Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229789AbjEQUoN (ORCPT + 99 others); Wed, 17 May 2023 16:44:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbjEQUoM (ORCPT ); Wed, 17 May 2023 16:44:12 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 747543C26; Wed, 17 May 2023 13:44:10 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id E51BB5C0127; Wed, 17 May 2023 16:44:09 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 17 May 2023 16:44:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ryhl.io; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm1; t= 1684356249; x=1684442649; bh=HovA2aBrCor3Q17F+fDmTxCq7878dGESxOg v5brW2DI=; b=ZsffjI3uEeF+t/uzV2g3STC5DstwGCRuQEDKvVkH7ZOALum0286 SXFdXre5fbazLr+N3CPihlLFPyHoiW9zMhiP/VUZuwAfe1uxXS3cxU0xu4rdSasV n2Ml7dc2eIlQBLYJlXKPlzOR92/UZgFZ7BOwldk57/nC+oMA2tTzsvfEoRX+SK7Z xZ4HJ9tUxNOZg6007DNZ2kmaJBWynfvtA289w65CwW7sgAuDMJckQUk4/lfvPf73 vhpSepxIc/w1jSu6n9hGB7ep+y1QqTlpVRRUqDbp77PwXyoQc8FYuN3hnmWx/+Gf VzANIxFRVOW1GUY2FpPAo+iqXZ9vL+Z+fRA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1684356249; x=1684442649; bh=HovA2aBrCor3Q17F+fDmTxCq7878dGESxOg v5brW2DI=; b=WC8QymsV4iKtF3Cia6Ed9KgbRCQCvKqdutOhGkeTjlQkqe3cl/i wmGh2lKvTq6OUV93dETusKxDT2WmHQtogUgf+P8ubZZPOskKllDfrjLTmqoAtgHw lWNY8HVbX0NSE0sgDVc/6Uw6cL176hsc1hEzn+NxYyWvkDamujt/qFArdWRtdqLU XmnuKHvVUGkQFeQVXflv1xwk4CcvuhzhxIR5BQQP/YEOEagLzAwefQGGUQiOeXAA fDBHMV1XzFqKrnuTzGhNO/qtqisDvzqSq9hsKNY6RLEtfAUbD9Uf3IJd/tAxtPly aVt6B0CgJIP6ueagrsVzeO6hh1YRXJSmpZA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeeiuddgudehvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuvfevfhfhjggtgfesthejredttdefjeenucfhrhhomheptehl ihgtvgcutfihhhhluceorghlihgtvgesrhihhhhlrdhioheqnecuggftrfgrthhtvghrnh epheduuddvteekvdektdduledugfffhfdugeejgeeuvdevtdetveejheehiefffeegnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlihgtvg esrhihhhhlrdhioh X-ME-Proxy: Feedback-ID: i56684263:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 17 May 2023 16:44:08 -0400 (EDT) Message-ID: <3532c544-7804-3dba-225e-69a7fb8418c4@ryhl.io> Date: Wed, 17 May 2023 22:44:39 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: Re: [PATCH 2/4] rust: macros: refactor generics parsing of `#[pin_data]` into its own function Content-Language: en-US To: Benno Lossin Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=c3=b6rn_Roy_Baron?= References: <20230424081112.99890-1-benno.lossin@proton.me> <20230424081112.99890-2-benno.lossin@proton.me> From: Alice Ryhl In-Reply-To: <20230424081112.99890-2-benno.lossin@proton.me> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Alice Ryhl > +/// 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) { > + // `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.