Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp18984742rwd; Wed, 28 Jun 2023 03:32:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4h9ksWONnluyZFUoZoieyaJUQj8RmrGzIUL//Ptclvil9BxGVv6nf132Otel9Te+s+Kanu X-Received: by 2002:aa7:d51a:0:b0:51a:4451:564d with SMTP id y26-20020aa7d51a000000b0051a4451564dmr898149edq.18.1687948329115; Wed, 28 Jun 2023 03:32:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687948329; cv=none; d=google.com; s=arc-20160816; b=K7+WlaQRyMXtYIUuoDyZo5kSqJInjaKspJOIInZd1lcvoXamcyDOSrPuJcnMVYnrfl 2aqoyTCqsxJByAUb+s9eZpoSRJOUyuFKUm17gQUI2OxnfoLWKyR8iZebt7Ke08O0Hh3F 1NGdku1eqq9ULa5eRKVHiRmEPR1N1yG5b6ztOoyWLvvkzbqJGmkiEFRZdliBDIWio1mL yvckxyMiKnVSp4s9ivBwjTBd7/k1Y2GySrf88ESJ9D4jyab+lTeIXSpmuBv1J/FkMMYj 7sYfAoVsUMJI2LbMQ+AYx62FEsoXnO+ngqXE/+NZsE7AMprA5D1x1BquJJYHyz43YBwk 1LvA== 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 :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :dkim-signature:date; bh=xre7AR6dyMRE6Z/GQMstLM6DJEOLT2mAAHNybbT1ScI=; fh=DAzdmQeV549EsKMeieFXKKBgjCWQi256OEWbfP5gIlM=; b=ozKdIRNUowx2UET7eYPWqifmy4BZ72nxXk/G3os4MinNJmOE/0zzKnLj00w0nI7gOR TpQ4C+4dWwiEqKJ3SvhWEPgOSVkQ4BM+TF6LepME+7BslDa5WhN9Rk2S0+71Q3H8DjOJ 3++meg481fo/MJwev+KvbDfnJTxoTy9aPh9PXfbhPILmHMZlFnopCgow0DNevQrCtm2k SjFheA2sCASp/41yhuS38XmoaIe/Wg7Ak9Nzv0So6FuSeFB1HNrdVGSFzTBzb64pLPTa XX3vCZkqpYMv7T/ia3bUI6Ps7m7AG1awrU9kUr4aVh6AHuv2Lo2k5jeSbFp/IrTUg9Qk 8s8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b="eswIO/t0"; 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=proton.me Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r14-20020aa7d14e000000b00519608a014bsi4882888edo.125.2023.06.28.03.31.44; Wed, 28 Jun 2023 03:32:09 -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=@proton.me header.s=protonmail header.b="eswIO/t0"; 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=proton.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232358AbjF1KIX (ORCPT + 99 others); Wed, 28 Jun 2023 06:08:23 -0400 Received: from mail-4316.protonmail.ch ([185.70.43.16]:50913 "EHLO mail-4316.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234900AbjF1J7c (ORCPT ); Wed, 28 Jun 2023 05:59:32 -0400 Date: Wed, 28 Jun 2023 09:59:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1687946370; x=1688205570; bh=xre7AR6dyMRE6Z/GQMstLM6DJEOLT2mAAHNybbT1ScI=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=eswIO/t0iPgLkux0PKMOQGjp9hJEXHjvsb3Vmj7imNRmF+VAQi0wjq5DssEXPsPKs sGU6i/s9vPqr4YqNE4345RQHEnX6fIlR884+0g/+pKQ30B16p8KbTTudUpVig1l8Ml Ur89BeNlSqujAYvWIGcUkAn1rAchN9iBwEyqOuRNBvhS+mevtJpgHI8FclvKI1oRT8 j47CawYJRNUGHCkJ+PzTxiUn2Eq7VZMFNLiJvToKbaDnskZ/25b6X8ORQWx8VrqkfK qTctCVvNixQSYayR9An+LiHWfwOVXOO4an/5uIvRqyzMBLOEewWj+06FcG1fDMl4QS DwMbM9KCrPWkA== To: Qingsong Chen From: Benno Lossin Cc: linux-kernel@vger.kernel.org, =?utf-8?B?55Sw5rSq5Lqu?= , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , =?utf-8?Q?Sergio_Gonz=C3=A1lez_Collado?= , rust-for-linux@vger.kernel.org Subject: Re: [PATCH 1/1] rust: macros: fix redefine const_name in `vtable` Message-ID: <-tQGhW-nja4JfdjHgbQgLqvDMc8gxJRsUFsk-cA9n7Q7w5g93rowJacyTT9G1T1_92g1DW1Y7OxjyndTEOYr32vp25DL--rX3W_56M1I8hY=@proton.me> In-Reply-To: <20230626074242.3945398-2-changxian.cqs@antgroup.com> References: <20230626074242.3945398-1-changxian.cqs@antgroup.com> <20230626074242.3945398-2-changxian.cqs@antgroup.com> Feedback-ID: 71780778:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 26.06.23 09:42, Qingsong Chen wrote: > 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(); >=20 > #[cfg(not(CONFIG_X))] > fn bar(x: usize); > } > ``` > Use `HashSet` to avoid this. >=20 > Signed-off-by: Qingsong Chen Reviewed-by: Benno Lossin > --- > rust/macros/vtable.rs | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) >=20 > 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: TokenStrea= m) -> 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: TokenStrea= m) -> TokenStream { > // Possibly we've encountered a fn pointer type ins= tead. > _ =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() { > -- > 2.40.1 >