Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp9581618rwp; Thu, 20 Jul 2023 07:03:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlEUIPmh0IQMdS3CTpbzYUEDGu7rvhx984c/AUgg/hsiOdgtPN4Gqv+FGNpkBj4ciaoU605f X-Received: by 2002:a17:90b:3d4:b0:262:ec13:d3a with SMTP id go20-20020a17090b03d400b00262ec130d3amr21394125pjb.28.1689861823270; Thu, 20 Jul 2023 07:03:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689861823; cv=none; d=google.com; s=arc-20160816; b=YebzWwjQQnUQf+wRXLqV5+mPyliRxqj6poZbvaSSnj8TfIa00JaoEF/kEP1ruB/3vM mRrwli67MKhqsAsa/QGHAXa2PUyup70DAnbHVD/Gb6FTZfPUzNhOkeUAl3Rtba9Xjtcz HILhB/U+U0Zsj/DmCubHYWV+1gDSioHzzblThvtgBJwP3dKSaMSB0QMQrDnhwxORNyJ2 dUVs2WQ1GohRQyWhmVi3d71cEAPos+8ImNNUfXdgirClDLbpYfmuFtzDyL/ETsV6mKor XHvAcKYFxqVg6FuIyYESBWZMxK486YL5t55VPct7LEDZD+qNajQPQzNWI1S5aL7LzFvB XI0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=LA27fVNYB1otp+ClEEEzqSk28q42Bg4PAc0mA5TaGlo=; fh=tY0sgAiDB/HPwQeJymbixAWC+lTXNVnP4xpob7IwNxA=; b=CZOYUi8kuL9jzCK6d6Y8xpl7T/rEIs2Ax9uV54kkkV/HyXhO5LF2vdhdkSRH/AyGK9 YSiykOX711aphNGLI2uwGfNa/xAdRpExrd625U6kcEKKtGceAxA18J0cb2ky6PBtGsmy SScS+0XsKHbqPeURW8hRsQOd2YAqiCojE4QS8b+55BtkKvpChZTrp3JXYHJTFvWmynks 7iMtIB3XZtJHiUF3avA2xFHIHK2wsP6y9h6xuyEr9TnrDOnxo2zPgnNzQPZFvs551ovW 1G3kc8tHilOXBvjwGYBIeS/vXo39ocwBnenutk9pORZWMTOmNACRDad0fn3kP/epOKjE VzQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=52vDWbc5; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 37-20020a631865000000b0055fd1bfb109si900104pgy.679.2023.07.20.07.03.29; Thu, 20 Jul 2023 07:03:43 -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=@google.com header.s=20221208 header.b=52vDWbc5; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231857AbjGTNZx (ORCPT + 99 others); Thu, 20 Jul 2023 09:25:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231853AbjGTNZr (ORCPT ); Thu, 20 Jul 2023 09:25:47 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EC7E171E for ; Thu, 20 Jul 2023 06:25:46 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-c4cda9d3823so652051276.1 for ; Thu, 20 Jul 2023 06:25:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689859545; x=1690464345; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=LA27fVNYB1otp+ClEEEzqSk28q42Bg4PAc0mA5TaGlo=; b=52vDWbc5PpSlNPdhrV8abc74QuK4CTY94pbrnKg5SIK70W5MFiAlFBeC4hZny7JA1m HZnDo22ZBKAA3EgnTp/qprqTcC+PkUP+dHN22mZ/hlDh2EqLxflfRka32OAhOeA7B4BW gdfLNjfBFOY96pVwigY+G2FJWIx8KfWeZHtV4l6HrJGhPjYyLvOSZz0d8ehJEQp5HJIG WK4/sKKKTCOl/6Cn6eeqK/0aJtNwiCLm9QMtZOuTX2nZ9TSIomx3kC5JjPWFz6UQCNwa NkCJTurFAkMOrZtg+5+qeuAno2hwUzZpIMawITKCbhN+3/cHnBzmEG1NDGiAK00k3/oP MkXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689859545; x=1690464345; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LA27fVNYB1otp+ClEEEzqSk28q42Bg4PAc0mA5TaGlo=; b=hDeEhelmbbEiua6fP00F+VaEswY6HZxoRLqVbIZIGuKooLjcw7SgZYupTrEn0pu0Co 1DTc6FuEIXFM4azLPZ6a482axSjZdhdvXJS1kNeesQ3oqKz4jlEvLTNPmZPQoo2S6NGp je9M9Am6+aTWa+Z/P1oqYVDaYN4TCa0g5MT5M5JTeObnGmJa/qHgMyCxdLSEsP6r1a4I 9nB/Kv0atZEecx7U9xChs5JKw17XM14VuGdQGoIJf2JRs10r13Heu7mn38WNqc+ZFMw0 ze3I3NM6l0UbpV350O0lMifncCEyUEExgnPLfB26LH/c7/O7/vAxGMYFaTqIFXzGJ2WE UM4g== X-Gm-Message-State: ABy/qLb0EQwRRmZUKRM0a4mfPSskRUDpzh1fGYlYNRSVeVttw/PH5il8 WN0vCPSmefD2JBxVVvmRcH9IAoM/239gaBw= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:31:98fb:c0a8:6c8]) (user=aliceryhl job=sendgmr) by 2002:a25:e616:0:b0:c1c:df23:44ee with SMTP id d22-20020a25e616000000b00c1cdf2344eemr47997ybh.0.1689859545678; Thu, 20 Jul 2023 06:25:45 -0700 (PDT) Date: Thu, 20 Jul 2023 13:25:40 +0000 In-Reply-To: <20230719141918.543938-7-benno.lossin@proton.me> Mime-Version: 1.0 References: <20230719141918.543938-7-benno.lossin@proton.me> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230720132540.3543838-1-aliceryhl@google.com> Subject: Re: [PATCH v2 06/12] rust: init: add `..Zeroable::zeroed()` syntax for zeroing all missing fields From: Alice Ryhl To: benno.lossin@proton.me Cc: alex.gaynor@gmail.com, aliceryhl@google.com, bjorn3_gh@protonmail.com, boqun.feng@gmail.com, gary@garyguo.net, lina@asahilina.net, linux-kernel@vger.kernel.org, nmi@metaspace.dk, ojeda@kernel.org, rust-for-linux@vger.kernel.org, wedsonaf@gmail.com Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL 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 Benno Lossin writes: > Add the struct update syntax to the init macros, but only for > `..Zeroable::zeroed()`. Adding this at the end of the struct initializer > allows one to omit fields from the initializer, these fields will be > initialized with 0x00 set to every byte. Only types that implement the > `Zeroable` trait can utilize this. > > Suggested-by: Asahi Lina > Signed-off-by: Benno Lossin Reviewed-by: Alice Ryhl > + (make_initializer: > + @slot($slot:ident), > + @type_name($t:ident), > + @munch_fields(..Zeroable::zeroed() $(,)?), > + @acc($($acc:tt)*), > + ) => { > + // Endpoint, nothing more to munch, create the initializer. Since the users specified > + // `..Zeroable::zeroed()`, the slot will already have been zeroed and all field that have > + // not been overwritten are thus zero and initialized. We still check that all fields are > + // actually accessible by using the struct update syntax ourselves. > + // Since we are in the `if false` branch, this will never get executed. We abuse `slot` to > + // get the correct type inference here: Didn't you just change it to a closure rather than an `if else`? Regardless, I'm happy with this change. Alice