From nobody Sun Feb 8 16:32:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62A3DEB64DA for ; Mon, 26 Jun 2023 07:43:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229898AbjFZHnB (ORCPT ); Mon, 26 Jun 2023 03:43:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229717AbjFZHm6 (ORCPT ); Mon, 26 Jun 2023 03:42:58 -0400 Received: from out0-222.mail.aliyun.com (out0-222.mail.aliyun.com [140.205.0.222]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D06771AC; Mon, 26 Jun 2023 00:42:56 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047205;MF=changxian.cqs@antgroup.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---.Te0ogGy_1687765369; Received: from localhost(mailfrom:changxian.cqs@antgroup.com fp:SMTPD_---.Te0ogGy_1687765369) by smtp.aliyun-inc.com; Mon, 26 Jun 2023 15:42:49 +0800 From: "Qingsong Chen" To: linux-kernel@vger.kernel.org Cc: "=?UTF-8?B?55Sw5rSq5Lqu?=" , "Qingsong Chen" , "Miguel Ojeda" , "Alex Gaynor" , "Wedson Almeida Filho" , "Boqun Feng" , "Gary Guo" , "=?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?=" , "Benno Lossin" , "=?UTF-8?q?Sergio=20Gonz=C3=A1lez=20Collado?=" , Subject: [PATCH 1/1] rust: macros: fix redefine const_name in `vtable` Date: Mon, 26 Jun 2023 15:42:42 +0800 Message-Id: <20230626074242.3945398-2-changxian.cqs@antgroup.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230626074242.3945398-1-changxian.cqs@antgroup.com> References: <20230626074242.3945398-1-changxian.cqs@antgroup.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If the trait has same function name, the `vtable` macro will redefine its `gen_const_name`, e.g.: ```rust #[vtable] pub trait Foo { #[cfg(CONFIG_X)] fn bar(); #[cfg(not(CONFIG_X))] fn bar(x: usize); } ``` Use `HashSet` to avoid this. Signed-off-by: Qingsong Chen Reviewed-by: Benno Lossin Reviewed-by: Gary Guo Reviewed-by: Martin Rodriguez Reboredo --- rust/macros/vtable.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/macros/vtable.rs b/rust/macros/vtable.rs index 34d5e7fb5768..08eb0355f99b 100644 --- a/rust/macros/vtable.rs +++ b/rust/macros/vtable.rs @@ -27,7 +27,7 @@ pub(crate) fn vtable(_attr: TokenStream, ts: TokenStream)= -> TokenStream { }; =20 let mut body_it =3D body.stream().into_iter(); - let mut functions =3D Vec::new(); + let mut functions =3D HashSet::new(); let mut consts =3D HashSet::new(); while let Some(token) =3D body_it.next() { match token { @@ -37,7 +37,7 @@ pub(crate) fn vtable(_attr: TokenStream, ts: TokenStream)= -> TokenStream { // Possibly we've encountered a fn pointer type instea= d. _ =3D> continue, }; - functions.push(fn_name); + functions.insert(fn_name); } TokenTree::Ident(ident) if ident.to_string() =3D=3D "const" = =3D> { let const_name =3D match body_it.next() { --=20 2.40.1