Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp29614345rwd; Wed, 5 Jul 2023 14:49:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlFgSUyglio0Ak5pAghDoorqUYzYkh6oSTlxkUBR3bSYCcJOjwDpexjJgpCgivtVvQ9W+vNf X-Received: by 2002:a17:903:2584:b0:1b8:5fb4:1c82 with SMTP id jb4-20020a170903258400b001b85fb41c82mr166115plb.50.1688593761878; Wed, 05 Jul 2023 14:49:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688593761; cv=none; d=google.com; s=arc-20160816; b=rcYT/W7pcy5yF/ttICziYjPqTQFvy2pXHCgXMEl0EQDTcMLVy1wI5TiZFQDAahBmoN Zr0zgSJJ6SmRHeSxzCOokOJq9TWsIsV0wJCMOsJ0+2BluiKWjb+TwCVU6Sbfp7RfE1lj 09K+He86WqB/7cWGVA+jn8bKrBzcremjYGes6VcEc/G8GHkbtOeyVbEzWp7yVzSfBBal hNh2qRVIwe8VPHdOEB6V7WNTwJHs92gfyt5U6vXdDoil2oL/b+/PV6wqtjDT1nj/pMkj i5/Zfr7GIdckNBT1tmODDQKkcS49K8Y88OujqjgB/25bzkGQxiADyd7ARMZB1Ei1bYgZ JJxg== 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=BsxqveEuWUXuxAC8tXYge4xIJEmM7wZqtaoyhSMuH9A=; fh=5JajFViB/LF/KOzrPZbG/NXXI1ajnKEUytYkmEiO3YI=; b=SW97lPMA2voR2jqrgmmdkI6R0iXMn4KcoX+oj5Ja2MtyzjHc2XE5v/+8b51VjiTzmt vNf2orJ0dHxEjHtDkKfzirpp01djDBY01McxtZHl7UDs8eUkjC+52AeABBUrvK4hDMNv HtP2lgG0OWC3WHoW3im9KkVi0q+ZnZP1t2bYTKGbVnvNsGrllGZ+9cf2ywNrEy1YD69A APWOIEMUsGpucQTRCIMC35YPYqsDG3S13mWWqOhYr4bT+RvP+wiveH+Xw04UP5ZYXflG FB3JBioVvPLzRBW9CG7cgtq2sw0tapMIsxsq7LEW6ps6kgM6uzUGX+vHGga+O2aKwIN6 Eetg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=baIRJTcH; 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 5-20020a170902e9c500b001b841d54b7csi14520573plk.206.2023.07.05.14.49.05; Wed, 05 Jul 2023 14:49:21 -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=baIRJTcH; 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 S229532AbjGEVol (ORCPT + 99 others); Wed, 5 Jul 2023 17:44:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230049AbjGEVok (ORCPT ); Wed, 5 Jul 2023 17:44:40 -0400 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 782C81997 for ; Wed, 5 Jul 2023 14:44:35 -0700 (PDT) Date: Wed, 05 Jul 2023 21:44:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1688593472; x=1688852672; bh=BsxqveEuWUXuxAC8tXYge4xIJEmM7wZqtaoyhSMuH9A=; 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=baIRJTcH2TwferdGWwGYFCBD1n1CVqnDMs2JrPsYN/pvdhesSH6w+Dmfhv+k8oH9/ NKeofawqRPpIs83RXdQnWPh6ohYYEyhgVPBCwEgiystbjTKRKuHqQexMCv1TiX1UG4 Tgtp5ho7hM7kZn1iUqUZxxbx9ibm2g7J7rQTPN5rQPh5WtZX+uChurmXa1whzABgDB 2H9MX/vSorp0UGtZUcI4Iy8OMj7MVwK+3BeMiuYGoT4owXPFMWvLd9EObqLlSrYUpw E+AxKNF9n+uTyOwhLSPW7lxQFvpXr4V1Zb7J754LOnyT4v5+LzyMAbCJvcDd8AVFNj T8YY0VDnxlUoA== To: Gary Guo From: Benno Lossin Cc: Boqun Feng , Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , 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: In-Reply-To: <20230705184836.363c8c8b.gary@garyguo.net> References: <20230624092330.157338-1-benno.lossin@proton.me> <20230624092330.157338-5-benno.lossin@proton.me> <20230705184836.363c8c8b.gary@garyguo.net> 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=-1.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,URIBL_BLOCKED autolearn=no 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 05.07.23 19:48, Gary Guo wrote: > On Mon, 3 Jul 2023 11:15:55 -0700 > Boqun Feng wrote: >=20 >> On Sat, Jun 24, 2023 at 09:25:19AM +0000, Benno Lossin wrote: >> [...] >> (this is `init_slot`) >>> @@ -1064,7 +1152,7 @@ macro_rules! __init_internal { >>> @data($data:ident), >>> @slot($slot:ident), >>> @guards($($guards:ident,)*), >>> - @munch_fields($(,)?), >>> + @munch_fields($(..Zeroable::zeroed())? $(,)?), >> >> since you append an unconditional comma ',' to init_slot and >> make_initializer when "calling" them in with_update_parsed, shouldn't >> this be: >> >> + @munch_fields($(..Zeroable::zeroed(),)? $(,)?), >> >> , and.. >> >>> ) =3D> { >>> // Endpoint of munching, no fields are left. If execution rea= ches this point, all fields >>> // have been initialized. Therefore we can now dismiss the gu= ards by forgetting them. >>> @@ -1157,6 +1245,30 @@ macro_rules! __init_internal { >>> @munch_fields($($rest)*), >>> ); >>> }; >>> + (make_initializer: >>> + @slot($slot:ident), >>> + @type_name($t:ident), >>> + @munch_fields(..Zeroable::zeroed() $(,)?), >> >> this should be: >> >> + @munch_fields(..Zeroable::zeroed() , $(,)?), >> >> Otherwise the example before `pin_init!()` wouldn't compile: >> >> =09/// pin_init!(Buf { >> =09/// buf: [1; 64], >> =09/// ..Zeroable::zeroed(), >> =09/// }); >=20 > Comma is not allowed after base struct. Yes this is a mistake in the example, will fix. --=20 Cheers, Benno >=20 >> >> Regards, >> Boqun >> >>> + @acc($($acc:tt)*), >>> + ) =3D> { >>> + // Endpoint, nothing more to munch, create the initializer. Si= nce the users specified >>> + // `..Zeroable::zeroed()`, the slot will already have been zer= oed and all field that have >>> + // not been overwritten are thus zero and initialized. We stil= l check that all fields are >>> + // actually accessible by using the struct update syntax ourse= lves. >>> + // Since we are in the `if false` branch, this will never get = executed. We abuse `slot` to >>> + // get the correct type inference here: >>> + unsafe { >>> + let mut zeroed =3D ::core::mem::zeroed(); >>> + // We have to use type inference her to make zeroed have t= he correct type. This does >>> + // not get executed, so it has no effect. >>> + ::core::ptr::write($slot, zeroed); >>> + zeroed =3D ::core::mem::zeroed(); >>> + ::core::ptr::write($slot, $t { >>> + $($acc)* >>> + ..zeroed >>> + }); >>> + } >>> + }; >>> (make_initializer: >>> @slot($slot:ident), >>> @type_name($t:ident), >>> -- >>> 2.41.0 >>> >>> >