Received: by 2002:a05:6358:51dd:b0:131:369:b2a3 with SMTP id 29csp309928rwl; Wed, 9 Aug 2023 15:07:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHRyJ1UEUTRTPreUeNRqfBEO8evVPzNPkHtvk3ci0Ec47qsdxG4ZJFHe+tSwW8j/qs0MU3L X-Received: by 2002:aca:120e:0:b0:3a6:f7d7:4cfe with SMTP id 14-20020aca120e000000b003a6f7d74cfemr623818ois.50.1691618873984; Wed, 09 Aug 2023 15:07:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691618873; cv=none; d=google.com; s=arc-20160816; b=kni3JEUA/VHeDiNfRGXnxBqY2XBZCwmYL1ybfh4eLSXUXwv9v+sjO6GIvJatsZn7Eo QFkblE0TaOY5eyX7e+2ohTRBsokaYOnLNmCHgSMlOheRnRtl556xweFe3j4+joNO5maR kdwYw8WdjN0rNVDGVd6CKuLI+t4J8v2Phy40Zb6So1jlM+HIzBpbPnqlF/EAhK1C8Wcy liZfU+5/HyBIoB6VcLXjqZDCDL3VhO4xQIR3v8XWKRYNAvWKdF5DJlQuvzIrAUHEMvkV 2lN+oM9uxQaL2J+aV1p/RcD5TR/B1gDKPFb2Ki5BCmEy0+GFlvOvxu2Y+9jRMxWzkHN2 NSIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date:subject :cc:to:from:user-agent:references:dkim-signature; bh=ZoIERmiBBLKkASybWOp4oJC+EW2j6JMye2Kl5N+XUR0=; fh=zcbbu2W8lEXyZTjwTTfK/VU+cUiNldSl5CAExBpP3Z8=; b=OtEJobJFNknMEApRvcgGgRpiLiQHhruJQ5OSm0cyq3ul5f8Kv+lOJeKER4JcWRhTbP L+x+Xwbnk8CP3Nmgn9iSzRLiA16xBMS6sZjYPlpDQk1sG5N73ez1INx6a2EPVIChII24 DgmpxsdK3NGw1KCToD7FNYn0+Wi+FRWZx2doxz4l0qnQCsKTABMP5tMSXEzFG9Y69X7K XM4L3pruMbWTIN84JlP6i05AWkN7D0+VDteVFBGOfbsVwsGVV60jBSHopRQYI3eNnXf1 0sf32J3qydp0YOMgHQ6emN9oL+pPYkGDwrrd30p/DOwk0zujRtQZ5yr0V3++VHTbJ1AG S1TQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=VLT0qvyq; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gp5-20020a17090adf0500b0026947ac1bb8si156617pjb.1.2023.08.09.15.07.41; Wed, 09 Aug 2023 15:07:53 -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=@metaspace-dk.20221208.gappssmtp.com header.s=20221208 header.b=VLT0qvyq; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229730AbjHITEW (ORCPT + 99 others); Wed, 9 Aug 2023 15:04:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229641AbjHITEW (ORCPT ); Wed, 9 Aug 2023 15:04:22 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D212C10DC for ; Wed, 9 Aug 2023 12:04:20 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2b9d07a8d84so2340151fa.3 for ; Wed, 09 Aug 2023 12:04:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20221208.gappssmtp.com; s=20221208; t=1691607859; x=1692212659; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:from:to:cc:subject:date:message-id:reply-to; bh=ZoIERmiBBLKkASybWOp4oJC+EW2j6JMye2Kl5N+XUR0=; b=VLT0qvyqjtSurIhfdjo4yMyPCJM+MS69Re4nEISv9Jv3SDZ/zNH8KUhkHdlgJTZ0O+ Y+vyD+AnoJon212RIUQAzYQIjMeN6s8DJhdilY4b1xQDJDu6TFyD0nx/qCg6bUCFrNRD 8uPgmvS157KGcKk2PFBnaK7gdPUQkI/42+gDUVWu+LFDBhNr+0X5jn/NEpc7MxnMpbMd qpVtXud28EKPgtZDW6EFoawt+0h8kztN/WrcjKF9d42Jy30IKcgMCtP+OdBVXyk7PDAK /mUiu0Tz3Z75EeRRwsWg9de7YEO5mbX8dfkNEPgkEIi8RyjCLcI2vYGyv/d67MIiaopy nZMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691607859; x=1692212659; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ZoIERmiBBLKkASybWOp4oJC+EW2j6JMye2Kl5N+XUR0=; b=IVZ6qqfNNtiHoJe01ml7Sx47t9Vu5xdtnrxGxkSMIovIJEFy3bWIjZEeRWcQVqX9az cCb+6qJtEozmSxNkl90RH7ydG4zE1YVFPbMr1gjKYF81u3Q0+31xWMn47zMK/d0HWi/d 84SpCItWdk4sKVii5vHEn3CDjIjg/9y4ZNSd4xl2ptXLQAsucc/bMDDs3z0kWTldd3JG eZ9nE+albECFQvdwtzJ3MrC/crbThMLLRpBvceApnDyqsppVlaSNTjZaGvINXAgP+U+p GgvjxXB+k5lug6uFSo/HoS2T530mbsKcr9GfsbhIOukRumfWBIdIT6vD5qE4rWMSZWK3 zrBg== X-Gm-Message-State: AOJu0YxOyZodvDFLnJswxbNKp9LQRPMh+tc5pzcs2dah0W158fb8bs2X qbuZFBL88ZvHeNLxzMbA5qalLQ== X-Received: by 2002:a05:651c:238:b0:2b9:5eae:814f with SMTP id z24-20020a05651c023800b002b95eae814fmr54552ljn.50.1691607858808; Wed, 09 Aug 2023 12:04:18 -0700 (PDT) Received: from localhost ([79.142.230.34]) by smtp.gmail.com with ESMTPSA id g13-20020a170906394d00b009931a3adf64sm8588962eje.17.2023.08.09.12.04.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Aug 2023 12:04:18 -0700 (PDT) References: <20230808025404.2053471-1-changxian.cqs@antgroup.com> User-agent: mu4e 1.10.5; emacs 28.2.50 From: "Andreas Hindborg (Samsung)" To: Qingsong Chen 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 , Benno Lossin , Sergio =?utf-8?Q?Gonz=C3=A1lez?= Collado , rust-for-linux@vger.kernel.org Subject: Re: [PATCH v3] rust: macros: vtable: fix `HAS_*` redefinition (`gen_const_name`) Date: Wed, 09 Aug 2023 21:03:08 +0200 In-reply-to: <20230808025404.2053471-1-changxian.cqs@antgroup.com> Message-ID: <87bkfgghqm.fsf@metaspace.dk> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED 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 "Qingsong Chen" writes: > If we define the same function name twice in a trait (using `#[cfg]`), > the `vtable` macro will redefine its `gen_const_name`, e.g. this will > define `HAS_BAR` twice: > > #[vtable] > pub trait Foo { > #[cfg(CONFIG_X)] > fn bar(); > > #[cfg(not(CONFIG_X))] > fn bar(x: usize); > } > > Fixes: b44becc5ee80 ("rust: macros: add `#[vtable]` proc macro") > Signed-off-by: Qingsong Chen Reviewed-by: Andreas Hindborg > --- > v1 -> v2: > - Use `BTreeSet` and existing `consts` as suggested by Alice and Gary. > - Reword commit messages as suggested by Miguel. > v2 -> v3: > - No need to replace `HashSet` with `BTreeSet`, since `consts` is never > iterated on. > > rust/macros/vtable.rs | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/rust/macros/vtable.rs b/rust/macros/vtable.rs > index 34d5e7fb5768..ee06044fcd4f 100644 > --- a/rust/macros/vtable.rs > +++ b/rust/macros/vtable.rs > @@ -74,6 +74,7 @@ pub(crate) fn vtable(_attr: TokenStream, ts: TokenStream) -> TokenStream { > const {gen_const_name}: bool = false;", > ) > .unwrap(); > + consts.insert(gen_const_name); > } > } else { > const_items = "const USE_VTABLE_ATTR: () = ();".to_owned();