Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2020191rda; Tue, 24 Oct 2023 09:52:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHyJCo7K3Ssbjjbayxu5clP7zOdpGn51/oA6qkIKrAmP4qwTQBjgtfSa3anGQ9yyGCsGnj6 X-Received: by 2002:a17:903:1110:b0:1c8:9832:827f with SMTP id n16-20020a170903111000b001c89832827fmr12114651plh.20.1698166337758; Tue, 24 Oct 2023 09:52:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698166337; cv=none; d=google.com; s=arc-20160816; b=J2G36vzNr1nJodBn0dVQ7CYeNt8izGl+IpyqXvheUV44NVL1YD3o8/GSW4dpraQip1 P4tCvFBO2XhQGicUiajfzW8lUTGMVjAWGhwvZdG1M91xWKax9C01iFFUg1E7xZxsQd2X 1ec54RTbo8DjCD0r9m+VfoBVCT/43IcU0ZR4OfjrXmaR+notGsQH0HTP+YYFPR/VRVmH 8rW7iRUpX4cE+eknAxrwxEet3kDSlIpmsx1+T73+zmeeNOmAe/IOC2AianUQPjTLGCeF wLNdIk8LK9QTH2HuiHb0gM2X+aeNa2GAz9AzTH7e1rRomM+DtILIY5HxreyKdnc6nD3k ARog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature; bh=4KDQl75KbMe5uLN513yRphkBvJX1k6bz7ls81M+yKsc=; fh=/ePYTWl4mpHC0K1UYK1wPw6QwgAEq4FpgZg69DLAnGA=; b=LJ8OB7VtytJ7jxKO3Q3a5rKIBcn8J0Y9VfHsksO2x5a0kDcWDclpwSK9okjtS77HnJ J7wvLjZ4ht1/aj+DyYP4UWHxn/qTFb8oAlVfVixVQp5YAZUXvdazt3399t7FM0gdltCg AvYOoCQjTeKsiv6+qu7EIijDQ902/dUPVZUREnZ8mUw8nDsgTchKZbiLjGY27PFVaEW2 BzHMcRuI8n4rtOSHmZVOL5ih32j69YLKXHcvaVnB14OFA6wjYjedwLX/lVY2nRwI/ttz Pz3ovyANkdvqhSL9dhXktp0GnndDiv7XS6fIXTKNyVNtkRfNINX/LyNmAAgD7X5xb8zD C7Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=LMje8IXs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id q14-20020a170902a3ce00b001c60de17b5esi8594405plb.118.2023.10.24.09.52.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 09:52:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=LMje8IXs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id DA83880401D7; Tue, 24 Oct 2023 09:52:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344009AbjJXQwC (ORCPT + 99 others); Tue, 24 Oct 2023 12:52:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234630AbjJXQv7 (ORCPT ); Tue, 24 Oct 2023 12:51:59 -0400 Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 504FDDA; Tue, 24 Oct 2023 09:51:53 -0700 (PDT) Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-1dd1714b9b6so3200135fac.0; Tue, 24 Oct 2023 09:51:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698166312; x=1698771112; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=4KDQl75KbMe5uLN513yRphkBvJX1k6bz7ls81M+yKsc=; b=LMje8IXszpXduRpCyhKxHO0NmedDYfQjOR2EQx6bdfnhyMiE09KFsy9wWXPEMMjUNQ JiYG7slBWpuXMRlLX0tFkz26/F6/S099zKjkAj3nQGLcum/DOF+AF8ysfht6SYdxQ6Ro UsjQLDbjN7UkV/t08ykqGKYbH7Fcw7cvkOrOBXsuPVWlpFmcgDMcx/guegOe1Vh+Spwb plvS0Kfn8Cas6LWhFCraztIG+KDIsJHwe0jIa6dyHQteL6RWHb0hTHT74xCX3LLIROle Ex5iS6jGwNZr6hHooc9loz0CeJtEy2u1b+WtfZUHWUIHkBkcm6EKXoL2ZAHg4l75/CVC 6aPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698166312; x=1698771112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4KDQl75KbMe5uLN513yRphkBvJX1k6bz7ls81M+yKsc=; b=kvBF30B0hNIj/pqwxEtxP3J4wNxW0PtxjCM0Or35lhOKNDyAs0+uPNX5kjkf4XjAno oeA6jN9aUo3j9d5OWIX6jPoSA6l71bJDkBF7fGBeILbvUaLgYowQaML197I4i/kyJl2P nR5yCFFXCfHlz1XNjGwWuNcZnlTD0jnVTULpUGdxXUu4SwIwvQUnGWaoIUyrNCifiiJX N72OhLbUnsAVna4OUaf4Tlz7/K+SiqWXQqzfF8szapNsh0ILQvH2V31l3Bie6f1jT3LD fpPhoJufgAaVmrBLgJiyiwkspf/5YATgZd4rx1XjYzE4k6X5Bq+bKbvSLkoUG3/rFOJw Va6Q== X-Gm-Message-State: AOJu0Yx9M5++T4gBuje22ggMwSdkKAzwVU/OzElJf8pCt//sgjFLNfoY Ox+cvzpPFz66WyrvVaj9TOE= X-Received: by 2002:a05:6870:ebcb:b0:1ea:1b5e:fed4 with SMTP id cr11-20020a056870ebcb00b001ea1b5efed4mr16886877oab.39.1698166312474; Tue, 24 Oct 2023 09:51:52 -0700 (PDT) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id p7-20020a05620a056700b007788c1a81b6sm3570638qkp.46.2023.10.24.09.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 09:51:51 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailauth.nyi.internal (Postfix) with ESMTP id 1D1AD27C0060; Tue, 24 Oct 2023 12:51:51 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 24 Oct 2023 12:51:51 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrkeekgddutdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpefhtedvgfdtueekvdekieetieetjeeihedvteehuddujedvkedtkeefgedv vdehtdenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgvshhmthhprghuthhh phgvrhhsohhnrghlihhthidqieelvdeghedtieegqddujeejkeehheehvddqsghoqhhunh drfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 24 Oct 2023 12:51:50 -0400 (EDT) Date: Tue, 24 Oct 2023 09:51:10 -0700 From: Boqun Feng To: Trevor Gross Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , Martin Rodriguez Reboredo , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, FUJITA Tomonori Subject: Re: [PATCH] rust: macros: update 'paste!' macro to accept string literals Message-ID: References: <20231008094816.320424-1-tmgross@umich.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231008094816.320424-1-tmgross@umich.edu> X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 24 Oct 2023 09:52:15 -0700 (PDT) On Sun, Oct 08, 2023 at 05:48:18AM -0400, Trevor Gross wrote: > Enable combining identifiers with string literals in the 'paste!' macro. > This allows combining user-specified strings with affixes to create > namespaced identifiers. > > This sample code: > > macro_rules! m { > ($name:lit) => { > paste!(struct [<_some_ $name _struct_>];) > } > } > > m!("foo_bar"); > > Would previously cause a compilation error. It will now generate: > > struct _some_foo_bar_struct_; > > Reported-by: FUJITA Tomonori > Signed-off-by: Trevor Gross This looks good to me, but could you (in a follow-up patch mabye) add an example demonstrating the usage, which could also serve as a test if we can run doctest for macro doc. Thanks! Regards, Boqun > --- > > Original mention of this problem in [1] > > [1]: https://lore.kernel.org/rust-for-linux/20231008.164906.1151622782836568538.fujita.tomonori@gmail.com/ > > rust/macros/paste.rs | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/rust/macros/paste.rs b/rust/macros/paste.rs > index 385a78434224..f40d42b35b58 100644 > --- a/rust/macros/paste.rs > +++ b/rust/macros/paste.rs > @@ -9,7 +9,15 @@ fn concat(tokens: &[TokenTree], group_span: Span) -> TokenTree { > loop { > match tokens.next() { > None => break, > - Some(TokenTree::Literal(lit)) => segments.push((lit.to_string(), lit.span())), > + Some(TokenTree::Literal(lit)) => { > + // Allow us to concat string literals by stripping quotes > + let mut value = lit.to_string(); > + if value.starts_with('"') && value.ends_with('"') { > + value.remove(0); > + value.pop(); > + } > + segments.push((value, lit.span())); > + } > Some(TokenTree::Ident(ident)) => { > let mut value = ident.to_string(); > if value.starts_with("r#") { > -- > 2.34.1 > >