Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp14908176rwd; Sun, 25 Jun 2023 06:40:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7rfEeuz2qLU1PmpI25pNZmEgws89zrUOiC9GyiuN+nyU0JceAJ4+4WLf9ESAVZ4/fH3Lp8 X-Received: by 2002:a17:906:58d2:b0:988:76ed:e557 with SMTP id e18-20020a17090658d200b0098876ede557mr17867019ejs.10.1687700438441; Sun, 25 Jun 2023 06:40:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687700438; cv=none; d=google.com; s=arc-20160816; b=OJZc/m7oPSGhKKCqjcgicIM+GoMkuvLFT74l6GJAK1Y555Hzje5vnht8DIZmV08TU6 fZ69M6tEoi3t6/HUPjCeJT1/2TEjVUTFnwsyzNLwmqAwvbRzwQ4hBqDzWFMkelFNYk4/ 6uCWV3JJk8sez04HM/yEskI0xJozIlgMqWEKafkHPNSnxus4d3RtZOEtCrx6gOu/m+oL 2DQCIlxsTxwYRFoQ+cMvboroWgL7DSq1FBQVnuri1QU0SjNYF3yfg2L2/D27tNzBRo43 Ipqc8IBbJKmXVJak3TrQo8six53LuzzUPYlDbUO1sl3JZwpCzAgpl+DLQ5C6YTN06OxM YB3A== 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=6zSwMhwbuqPy3zgYvaxQEVw9DmXm9kLhhzopKBxaS9E=; fh=a/+FqbM69oEBGciU4mmNQVx9WtVX7d/noHqB5UvbtmA=; b=DbVJTsaINENh2ppoiruzPo5Nfp6Busj3oRl4M6/6x2pUW2bBRhhW6/HWDVbMRyUDHl 70KpZVRqGkZkV3/BdeykIFeG7SiLTdJb2qXbkKXv9X+bWa3obDvOzPSbX8pn7Ska5cq4 jIYftxNUsMeC6J8zS9DdIHe5wP88ZHdSDw0dfZOMTB+Nnq6T4KhqESneWIl1BSJgh+es pZM0ep2cRsnWT5oFMyM6nHdl5sr+SiEaE/g1/gltrL4UIk9GyPN+CmYO7yspSvMcVM10 1nXG0Gz6NL7yxMwHQ8pY7egn5XrtYCdVcGnwBhI+CnaXyYqCMUMrq8CpOUVK5m5hKtvd 4nuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=AuvQvn5c; 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 f22-20020a170906049600b00988a4a7abc8si1746370eja.75.2023.06.25.06.40.12; Sun, 25 Jun 2023 06:40:38 -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=AuvQvn5c; 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 S230058AbjFYNHW (ORCPT + 99 others); Sun, 25 Jun 2023 09:07:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231523AbjFYNHV (ORCPT ); Sun, 25 Jun 2023 09:07:21 -0400 Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31B841B7 for ; Sun, 25 Jun 2023 06:07:17 -0700 (PDT) Date: Sun, 25 Jun 2023 13:07:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1687698435; x=1687957635; bh=6zSwMhwbuqPy3zgYvaxQEVw9DmXm9kLhhzopKBxaS9E=; 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=AuvQvn5cTfmNK3KGLVxo3I53MuaDjk9Hk80Mf9CDCVwEeI5aIRt2pOa4f04m4Ps4/ o2dSuRaYC7Geud2F7xxJGf6xfxW45v0FVeut+KPrHyA2ttGjIP6+4YonQP/SOlk2St 6KjEJyvlC2/CxOpaYxH2o0ZMLOiemAk+dUUNLtN6FZPmnwS3sCBgk5xhhO/itJ+QES Kufxa3wjInKIVcRoS8CeYbeLB8VUXRJAaj+JAcAEJ45mdEsxxMuh3RAvRqwVZmpeBy /ErxuACLB396S9jhWBFnXVU+FZ+teYVyfq0U1IZZiFlBT52ReYvEryI4clWgK0RbsE SAIU1ld8ZXBsw== To: =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= From: Benno Lossin Cc: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor , Boqun Feng , Gary Guo , Alice Ryhl , Andreas Hindborg , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Asahi Lina Subject: Re: [PATCH 5/7] rust: init: add `..Zeroable::zeroed()` syntax for zeroing all missing fields Message-ID: <6f4e1d68-f828-8990-4859-8ab24907fa46@proton.me> In-Reply-To: References: <20230624092330.157338-1-benno.lossin@proton.me> <20230624092330.157338-5-benno.lossin@proton.me> Feedback-ID: 71780778:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On 25.06.23 14:56, Bj=C3=B6rn Roy Baron wrote: > On Saturday, June 24th, 2023 at 23:14, Benno Lossin wrote: >>>> + // Ensure that the struct is indeed `Zeroable= `. >>>> + is_zeroable(slot); >>>> + // SAFETY: The type implements `Zeroable` by= the check above. >>>> + unsafe { ::core::ptr::write_bytes(slot, 0, 1)= }; >>>> + $init_zeroed // this will be `()` if set. >>> >>> How does this work? Shouldn't there be a ; after $init_zeroed to consum= e the () value? >> >> It is the last expression of a block and since it is `()` it is ok >> (adding a ; would also be ok, but it is not necessary). > > I'm surprised it is considered the last expression of a block. Unlike wit= h {} using $()? will still > allow variables defined inside this as if they were outside of it. Also I= can't reproduce this > behavior with: > > macro_rules! foo { > ($($a:expr)?) =3D> { > $($a)? > bar(); > } > } > > fn main() { > foo!(()); > } > > Is there something I'm missing? > > Cheers, > Bj=C3=B6rn Not sure what you mean with "allow variables defined inside this as if they were outside of it". But note that in the macro `$init_zeroed` is the last expression of a block. Here is a small example: ``` macro_rules! foo { ($($a:expr)?) =3D> {{ $( bar(); $a )? }}; } fn bar() {} fn main() { foo!(()); foo!(); } ``` it expands to this: ``` fn main() { { bar(); () }; {}; } ``` -- Cheers, Benno