Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp19113162rwd; Wed, 28 Jun 2023 05:22:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ747yLREXNSPI9CBsJ/Zfv6g2j9sYj4md3O246berKkYHQmrUl/YLVhuPqxAtYTlFu4Wkvy X-Received: by 2002:a05:6a20:42a2:b0:125:1596:d14a with SMTP id o34-20020a056a2042a200b001251596d14amr16248929pzj.21.1687954941866; Wed, 28 Jun 2023 05:22:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687954941; cv=none; d=google.com; s=arc-20160816; b=mDZmM0gv6kEFlMiEvX3iP125GqrY7D4hIUq/vD7ZpBRfricRrhuEgq01D3JwLSftT1 Znk2+gUR0aWAN24LtodsWPvkhE47FTjJJYwhi0IecRbj9fk6/g0A1JL9HP4jzBd0Ou2L FjtRXZI5mTr57xAHfTORQdBHbz9k05GmdfWafWSVsmZ0TnoRyDn5OeQoTnYHmR/2jdgu jgl0rFArmXU8CJ7IfujKy5iHxDxlYjSQuAxR7X0B+OnzOtqUtW2yqLmdG5j+aOXaD4y6 Mc+2sSpeIsg2ampw5j+IyYjsBXhz5fs5fUmIbshx+7ep7gdgM1FOWHPu4ijXf7qn6gIi 2vQw== 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=1XmJXLB2uklIrAaKv9O0vIo0TRiOWO1X6CWSa661Mfg=; fh=6PGpQF/lOUCXjkcbNx07erwMxYTcNYELPQZn7bAf7nY=; b=j14rLJkyqIgdqSNVo0jSp9pToYIuapQU5d+AHgh6IEAvtNcoABSs9zaUXHMAtEZv8d Yae+uczLimW4n/JR9Jk129O9vZCnbtfFkPirIfKakvnkEGzy4J+v1Bwu9aX37s9oM2nk eNPOYhA8g/b54qNb51QTJU1ZmeYh0eriT1Z2DKCP9ZEghyoRB77sHS3xhYz0SQle31Ac 7FkQiqSPyOHcbY4kjAKEGhyxV6cgW7Iy0xPgsz1EaIyfGgX+IVDT2CEUnOoHK7NkK43x vFGcoic8/mEyE8SdU6F0QzbBzejmcgq5dFa46lZGMD3coOTZ0LMB5Pb9spw1XFBqmBMR MMpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=UlBERZzl; 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 cj22-20020a056a00299600b006634db9e11dsi4287090pfb.313.2023.06.28.05.22.08; Wed, 28 Jun 2023 05:22: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=UlBERZzl; 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 S229748AbjF1LmN (ORCPT + 99 others); Wed, 28 Jun 2023 07:42:13 -0400 Received: from mail-4322.protonmail.ch ([185.70.43.22]:55013 "EHLO mail-4322.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230281AbjF1LmK (ORCPT ); Wed, 28 Jun 2023 07:42:10 -0400 Date: Wed, 28 Jun 2023 11:41:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1687952529; x=1688211729; bh=1XmJXLB2uklIrAaKv9O0vIo0TRiOWO1X6CWSa661Mfg=; 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=UlBERZzlcMySexpywP/qfwbhkcuGUTK/3+eki529LjK1ujWoEHEDLIGJhR8G+ofo2 HJ96vvG49aHx/tDb+30C3Cl4gVcd2UPpiQPc8mbZMEWBzojtWtIaLoT+NPnvI27t3I dcsWKLEczhj4NeRxGDcuK6QlC4g/TGLF5erWdd0b//47PyfwUYVIX+2LS8n6++LVWx tXM1cTk0Cz5qPn+7rKokJTd2Yf9LVVjjDEjbSO9XVK8Qt5tob1alGLuGlE1RKFuPnI 6uAqN2CQA66+U8jLcfXAaFqVoi5x4vIL/7kY9K9RZtxsZlH5ArVPIjZ7cyoxjsnnyz aEzhhUSlftGqA== To: Gary Guo From: Benno Lossin Cc: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor , Boqun Feng , =?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 3/7] rust: init: make guards in the init macros hygienic Message-ID: In-Reply-To: <20230625215453.25aa38a0.gary@garyguo.net> References: <20230624092330.157338-1-benno.lossin@proton.me> <20230624092330.157338-3-benno.lossin@proton.me> <20230625215453.25aa38a0.gary@garyguo.net> Feedback-ID: 71780778:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 25.06.23 22:54, Gary Guo wrote: > On Sat, 24 Jun 2023 09:25:10 +0000 > Benno Lossin wrote: >=20 >> Use hygienic identifiers for the guards instead of the field names. This >> makes the init macros feel more like normal struct initializers, since >> assigning identifiers with the name of a field does not create >> conflicts. >> Also change the internals of the guards, no need to make the `forget` >> function `unsafe`, since users cannot access the guards anyways. Now the >> guards are carried directly on the stack and have no extra `Cell` >> field that marks if they have been forgotten or not, instead they are >> just forgotten via `mem::forget`. >=20 > The code LGTM, so: >=20 > Reviewed-by: Gary Guo >=20 > Although this will cause the new expansion we have to be no longer > compatible with a totally-proc-macro impl, if we want to do everything > in proc macro in the future. >=20 > If we have the paste macro upstream ( > https://github.com/nbdd0121/linux/commit/fff00461b0be7fd3ec218dcc428f2588= 6b5ec04a > ) then we can replace the `guard` with `paste!([<$field>])` and keep > the expansion identical. >=20 I tried it and it seems to work, but I am not sure why the hygiene is set correctly. Could you maybe explain why this works? ``` $crate::__internal::paste!{ let [<$field>] =3D unsafe { $crate::__internal::DropGuard::new(::core::ptr::addr_of_mut= !((*$slot).$field)) }; $crate::__init_internal!(init_slot($use_data): @data($data), @slot($slot), @guards([<$field>], $($guards,)*), @munch_fields($($rest)*), ); } ``` i.e. why can't a user access the guard? I think it is because the hygiene o= f the `[<>]` is used, but not sure why that works. --=20 Cheers, Benno