Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1332070rdb; Sun, 8 Oct 2023 02:56:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbvvATjCSadYhlm32vTv+axlLBfubiRnyCqEqa+m4VmR8mWOCnMg3MP6ahooi6HLdeyWwt X-Received: by 2002:a17:90a:f406:b0:273:f887:be17 with SMTP id ch6-20020a17090af40600b00273f887be17mr12148145pjb.47.1696758981379; Sun, 08 Oct 2023 02:56:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696758981; cv=none; d=google.com; s=arc-20160816; b=0PujwuiCAM+BOgIaillI+3ujJbbYRywWP15Wl3dyBnV7MSZXGjpWE4ML3bQcmMJI/G 6MKHmFIS/jJ3J1DVdW+QGXMoi+B73xq+0f4mNWJ6CPOOim1HglIaotpoSMYJ+6dC9EIA 1aJMdL7CAr6zQhYcUJ7I6gPVxGDriKvD1S2uMc9v1w/GnQkbofH+SicZWS+YFHWS8ukG b4XoNxDfnJoFJ4akIcLW0OMaSqejb3oi+SE5ys6qi6VcL2eXzdSCUzMX6khlL+w6zomy um45Y9KUl79mgpeoBNujfPJ9XRHWJH5Aslk8+INRZ9pG0rGC16+caiPvxLtHSC/Efamh D39g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=I+o9SIX4PotCqWF/xeatcNnnqUwJ9aNzchabhWdrqjA=; fh=paHpB5QxaFjz5LzUU5O6Ouzrt1NoZWFpFO44CbZeugo=; b=CG5kTvDOn59/nsXrG3seeZ0YIi7C4dps/tAk9cofPok0FcvuLOU8zPbVAxtUzvHt0o 6UarASY47TYxq0tRh/Lxhqf2iKuZAyKU6fw12m3C4KgLZ9Zwoamnprnq9kZXR9QY8RsG UmuY0YQCQiyFppHw2gaRc9gEy8D0Qg0rfKfvyq+lM2ymWnkYz67JdHnMT8XVvjgYNmn/ nmGLtOY9bbMRmhR8lNnr4FenndFgR77/tRjh9/XDEw6TiTsGsrYsNgogoADJhuiz+y/L ZpAPUBbOO5KW/H8/cp6ISdz8Ziaal5Hk7tJvPBMsd10jIeDafKHIEhe+yF6/mx7dD1HZ zbeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@umich.edu header.s=relay-2018-08-29 header.b=q5dVvz0U; 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=NONE dis=NONE) header.from=umich.edu Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id gm16-20020a17090b101000b0027924ff5de3si9626763pjb.68.2023.10.08.02.56.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 02:56:21 -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=@umich.edu header.s=relay-2018-08-29 header.b=q5dVvz0U; 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=NONE dis=NONE) header.from=umich.edu Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 8E389803DAD5; Sun, 8 Oct 2023 02:56:18 -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 S1344604AbjJHJ4H (ORCPT + 99 others); Sun, 8 Oct 2023 05:56:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344601AbjJHJ4G (ORCPT ); Sun, 8 Oct 2023 05:56:06 -0400 X-Greylist: delayed 283 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 08 Oct 2023 02:56:04 PDT Received: from short-nisien.relay-egress.a.mail.umich.edu (relay-egress-host.us-east-2.a.mail.umich.edu [18.216.144.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D220EB; Sun, 8 Oct 2023 02:56:04 -0700 (PDT) Received: from exalted-banshee.authn-relay.a.mail.umich.edu (ip-10-0-74-179.us-east-2.compute.internal [10.0.74.179]) by short-nisien.relay-egress.a.mail.umich.edu with ESMTPS id 65227B97.15EC55FA.7AE301A9.81919; Sun, 08 Oct 2023 05:51:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=umich.edu; s=relay-2018-08-29; t=1696758678; bh=I+o9SIX4PotCqWF/xeatcNnnqUwJ9aNzchabhWdrqjA=; h=From:To:Cc:Subject:Date; b=q5dVvz0UBP3d3l2RanJF9SMVehhIpvDqS+ES4mXq2bIa7WowwiVEGUP4oHkSj9r7h gOvtKBiDiv2LsAsHuT+UVcucyxzL6uiTAdICEwCVuGMDxQLl25uN/Yzr1USAJ1FxPG iSoIoW9N+LYweqBTUGJev5/5wn+sfABzdExCXhUtIa7LAtow7W4B0/V+wPaYicAGmI 1md/jPLut7YAdXfT/iUGcHL7/YZJ/cVD+ZqpC4JF09PLwrqI3nOYo8gVK+UlGEdzXb q3qh0AI/Zb/Mws7VxOAm6XXVYj9YHA9SekhoEDIvXxxhWElVju16pzMhUQRB87v0tY ykDi2Dy3GS8rg== Authentication-Results: exalted-banshee.authn-relay.a.mail.umich.edu; iprev=pass policy.iprev=76.141.129.158 (c-76-141-129-158.hsd1.il.comcast.net); auth=pass smtp.auth=tmgross Received: from localhost.localdomain (c-76-141-129-158.hsd1.il.comcast.net [76.141.129.158]) by exalted-banshee.authn-relay.a.mail.umich.edu with ESMTPSA id 65227B96.46860EC.3A6166B1.881404; Sun, 08 Oct 2023 05:51:18 -0400 From: Trevor Gross To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho Cc: Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Martin Rodriguez Reboredo , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, FUJITA Tomonori , Trevor Gross Subject: [PATCH] rust: macros: update 'paste!' macro to accept string literals Date: Sun, 8 Oct 2023 05:48:18 -0400 Message-Id: <20231008094816.320424-1-tmgross@umich.edu> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no 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]); Sun, 08 Oct 2023 02:56:18 -0700 (PDT) X-Spam-Level: ** 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 --- 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