From patchwork Fri Feb 24 07:25:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asahi Lina X-Patchwork-Id: 61141 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp755927wrd; Thu, 23 Feb 2023 23:28:31 -0800 (PST) X-Google-Smtp-Source: AK7set8NaP9Ihpv3e8bnCTzYIETSeB8GXq1gv33BoICFXc6galISZpHZZFdTvZ8z3Y9Y/UL5gcgj X-Received: by 2002:a05:6402:756:b0:4af:6c25:f028 with SMTP id p22-20020a056402075600b004af6c25f028mr4383361edy.5.1677223711775; Thu, 23 Feb 2023 23:28:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677223711; cv=none; d=google.com; s=arc-20160816; b=HBeu9WCpfNrG2j4dRXZ46Yl9e4xn1hxS1Mscqxxv9wVsozJxwa2a91/dCvU/N/temS ixu+HGmt+jstcq20epFyxOS6SWGzU/ZUIBf0QCH9PRtISact5fsdn13Xhn6IkwDs91Kv 6wGGaFiVIuy10GQa77M1Ux4eBvLfr7+ecb6v/v8fTLFOYUWVh+byMEAWBwscjsGg41r0 StpqWm1VIcs9DOo2+NidiZrZwoalYuk2ghj6AY3yGcq0YhGULWuhUT8fvYj5kkymgHHN zJHdk0hGW9J2m5Ug9/QdZ/fmow2cE8Rp/SL5KkJoXQd81i9SczetqN3HseJD9WBWoNT2 tHVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=etp2s21GqytsFuILfRXE+GeGiTX1uDJS5GaqzRiKWmA=; b=r/hKQHAxfY9br+WurRKPR+PSgMnhcqa2zwdBo2IZJtPMa8W5sVpeDrGCLgBIiXKFuE Svx8NLZwxZjrZlDnV2J7zoLz+aghLbTdpk5ldOxmOp4ca2lHRk8coJJBnuUGKnY8zsBb gKa/4qHKHcuYgD/x4PBOnZbmbIZJBXK/sJXUCst28BIuAbH1zZbHJEcFYYL2BH9NjWNh Cc1bAeHr79uIiBKGgHyDq2ivkmsDsrA8toHbjb8NIhjFmRq+H6VWL/gltkglJuSJv2UP 4448cOEHOZIa/tuv6A/FXkEA0lltaURqoVM4jmEaN57J2GKBVWRnIlQVGFCjLQPUkxIq MhoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@asahilina.net header.s=default header.b=KJoHBpU9; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=asahilina.net Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k11-20020a056402048b00b004acc454abe7si11519720edv.260.2023.02.23.23.28.09; Thu, 23 Feb 2023 23:28:31 -0800 (PST) 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=@asahilina.net header.s=default header.b=KJoHBpU9; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=asahilina.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229731AbjBXH0i (ORCPT + 99 others); Fri, 24 Feb 2023 02:26:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbjBXH0f (ORCPT ); Fri, 24 Feb 2023 02:26:35 -0500 Received: from mail.marcansoft.com (marcansoft.com [212.63.210.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 722301EBDF; Thu, 23 Feb 2023 23:26:34 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: linasend@asahilina.net) by mail.marcansoft.com (Postfix) with ESMTPSA id 6B55D424B9; Fri, 24 Feb 2023 07:26:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=asahilina.net; s=default; t=1677223593; bh=znEXimllrWJvfY/ohmIs0JciCK61gw0J+CRFrn2gudU=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=KJoHBpU9113mO+mdOiaJNn+0HklOkWluH51fJFbKl8NYFDEBkIICjJyoRhOLobouU QzH3np0L6dmJO+aRIahBLIEY3Iby8a9Hzx1zmLHjELLA9UPfIIAYhX+HS+Sty9fe12 EjEwDHNE2btQIyFRnNHPbOb89uShMQmcL8qVqLsTSJMr0JV9CRux2yS2EBram+jfRw AiFlXtJs3LjNKhuzNRk2X1Qbx6ddH4ZJ/wM1cRlUV5eRq1H9GHSnXEwQaiTU/9hVCL KQozTR6J4ZTU7R9qa3fDLZVf7JR28dXlz7XpAAG9//vGTtCJwiaQX1W8sbrDKdlaVG 7OIvQV1aXpFQg== From: Asahi Lina Date: Fri, 24 Feb 2023 16:25:55 +0900 Subject: [PATCH 1/3] rust: macros: Make expect_punct() return the Punct directly MIME-Version: 1.0 Message-Id: <20230224-rust-macros-v1-1-b39fae46e102@asahilina.net> References: <20230224-rust-macros-v1-0-b39fae46e102@asahilina.net> In-Reply-To: <20230224-rust-macros-v1-0-b39fae46e102@asahilina.net> To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, asahi@lists.linux.dev, Asahi Lina X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1677223586; l=2668; i=lina@asahilina.net; s=20230221; h=from:subject:message-id; bh=znEXimllrWJvfY/ohmIs0JciCK61gw0J+CRFrn2gudU=; b=H/oQs1/Pt+6iQus1S0oDMkRIMRYO/sCD2ik5qRDSJzQ3aWOjUiTjg2D+qmrDeb1VTO+yDB6ZI XGJ6yp2aYR9Aik6WMEy5SEeA1CISZ8nNhb01BFVy76fEoq2IxnOFK4l X-Developer-Key: i=lina@asahilina.net; a=ed25519; pk=Qn8jZuOtR1m5GaiDfTrAoQ4NE1XoYVZ/wmt5YtXWFC4= X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758696530915292846?= X-GMAIL-MSGID: =?utf-8?q?1758696530915292846?= 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 Reviewed-by: Gary Guo Reviewed-by: Finn Behrens Reviewed-by: Vincenzo Palazzo --- 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 { 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); }