Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp15005448rwd; Sun, 25 Jun 2023 08:19:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ57n9O6x/jKAY4J5OJ1IFuyKWt6ebWSIgqIkSKxOBMlLYYbSSbMwsOT+q4u6F5eyqiXHMTE X-Received: by 2002:a17:906:58d2:b0:988:76ed:e557 with SMTP id e18-20020a17090658d200b0098876ede557mr18048292ejs.10.1687706355412; Sun, 25 Jun 2023 08:19:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687706355; cv=none; d=google.com; s=arc-20160816; b=YEeiZ7UupCWKHdMJHtx0iY3D7f79oL2kZS208UU76sXRJiv4O20Hro3MgyA7Gf9S4v ZmikJq5bCxXdFcOcMXN7dNG1ZgvNnvfAcW/vJitMtQV3bb5clFCIIJw8AX2hcTtR/WaA fat2jfrQmsvw3zW5s4nGYtF82vDz9wz6gCA+HLlfnNv32HrV2+jlqjKVq2/KnCKKUeXF ZF6R9dH3NijJJsclkRPOQocjWM7y6oPR8BelcDEm2gm4y871PHtDTjLb3ICtktqIxsLS C2riO7fb8EG5JngwoH8bwZSjReG5SoYFiu4uqr94tXEU53+QI4nxOeiZfKpb9Wn0YjVL tTYQ== 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=inMyYrOTZsqu+PuRu8d57Qiq8p3tOvJbGALKqIAke6I=; fh=G5JJZHPpWxnD6ZFNcd5f5J3pAM1l8A+sr+uFjGq+s0E=; b=Phe66x13lQ+FZIZLkaajhHI2Vr387RFIEtHfgZUF2SNoqO7z2Q00yj2oMdb6oI6XSo YJbA1TBteXk2+lhOe/zM/ZXD6vDeAM74q1qoXES5jRRlDo8myYfjF1nvcKdfLWv1c+Fm le22lJ7qlP2Jdp9pCIHaUB7GO3D4YCphW1DxJ6EiQBMcGGmtM73ihqstr2YT14gXDfAf yD+06rNlLAVIyh1jwcVEoi+BUSXPmOovoVyBfMzh6r7LC/Vyx+0yYg02UU1cZAbRRdnv vXecPcmOEiZS3XzSfawQHJME4gtMUM/bjUsgggzaDaxeiN5ZyVCet9Y2sGs3HdwfDM8P GKFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=nWmcbiPc; 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=protonmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s23-20020a1709066c9700b0098896420108si1862393ejr.170.2023.06.25.08.18.50; Sun, 25 Jun 2023 08:19:15 -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=@protonmail.com header.s=protonmail3 header.b=nWmcbiPc; 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=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230127AbjFYOSD (ORCPT + 99 others); Sun, 25 Jun 2023 10:18:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230145AbjFYOSA (ORCPT ); Sun, 25 Jun 2023 10:18:00 -0400 Received: from mail-4319.protonmail.ch (mail-4319.protonmail.ch [185.70.43.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 047DCE54 for ; Sun, 25 Jun 2023 07:17:56 -0700 (PDT) Date: Sun, 25 Jun 2023 14:17:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1687702674; x=1687961874; bh=inMyYrOTZsqu+PuRu8d57Qiq8p3tOvJbGALKqIAke6I=; 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=nWmcbiPcF+KrhUXh5wyp5V46TYfMXv6kItl9dia5OypB2Ps1ksl9NG2V/w8VOJfd5 JegCvE0pTbT2m1UFoUuXI78YSE9MwN3ULj8PZz7Aj9eK6pGhv5aZ/Zm+rEg2wgG8/V RIZWhbLvl3B8ciuiMWSZ++2h8CNa9ubdJO2mFzvGaJ+B7wMlDoqn7AtfHRJpehN1jF hvMd7TyY1f38DtdQKMmxoj4brQOfx8PWrxG6jU5lxlgXED45VcGuCaOWA8nh1kjtHW T1qAxLWqJLUM+app+ftODyh97umBEQm81lfoqbdQtX0l8PwrwmiVbY6/VRJUMj58mo 863jN9exy7tjQ== To: Benno Lossin From: =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= 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: <8lCE3SyChVVb2HphigkwKsxv7etgmS0N3AzcDyYtCEoqcFEKvY-5ILkOrWUr_vnWrvsWrAHXVfwcWARfsiMHC8Yc03sND-PuuK-2z9j4z6I=@protonmail.com> In-Reply-To: <6f4e1d68-f828-8990-4859-8ab24907fa46@proton.me> References: <20230624092330.157338-1-benno.lossin@proton.me> <20230624092330.157338-5-benno.lossin@proton.me> <6f4e1d68-f828-8990-4859-8ab24907fa46@proton.me> Feedback-ID: 27884398:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Sunday, June 25th, 2023 at 15:07, Benno Lossin = wrote: > On 25.06.23 14:56, Bj=C3=B6rn Roy Baron wrote: > > On Saturday, June 24th, 2023 at 23:14, Benno Lossin wrote: >=20 > >>>> + // Ensure that the struct is indeed `Zeroab= le`. > >>>> + 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 cons= ume 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 w= ith {} 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 >=20 > 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: $(let $this =3D unsafe { ::core::ptr::NonNull::new_unchecked(slot) };)? com= es after this code in the same block that contains struct __InitOk;. And after that = another $crate::__init_internal!() invocation. That is why I don't get that this is= allowed at all. >=20 > ``` > macro_rules! foo { > ($($a:expr)?) =3D> {{ > $( > bar(); > $a > )? > }}; > } >=20 > fn bar() {} >=20 > fn main() { > foo!(()); > foo!(); > } > ``` >=20 > it expands to this: > ``` > fn main() { > { > bar(); > () > }; > {}; > } > ``` >=20 > -- > Cheers, > Benno >