Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp149943rwl; Thu, 30 Mar 2023 13:37:21 -0700 (PDT) X-Google-Smtp-Source: AKy350ZgEqFl/mh4sjrsvcgYFem2/gd3MRhhwCzkWrKgckXKe+3Kp1GqCdgHGohydQPkfEbH9uzJ X-Received: by 2002:a17:906:190:b0:8eb:fb1a:6970 with SMTP id 16-20020a170906019000b008ebfb1a6970mr2368541ejb.1.1680208641544; Thu, 30 Mar 2023 13:37:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680208641; cv=none; d=google.com; s=arc-20160816; b=s2RNkke7EoiRTRPDb1BUhTNHtenJ6NPeZgx+AN6BWHw3TwljRmlojb/bxMl1DKM15P jQLl1sXXPnDBD342BIBzxn0E69mU+7Pl2k7g1i9A8t6V4+Gj4I3BlWLrtR7BB8fWa0s4 nIbW+YWznBkxdRtumJhhOnjpEgAivqdTokOL9jlT1QxIZMMLaXkohXBigabL0tPBPum8 yhT6WBHBD4qVtrhgK+YZRGmXhg0xg4+4yNta/MnE2TYVKUxVjr3omV7WIh3chvPNALm3 0IHXM4wLsc+RnGC1TZXoVeWd1pnwlV1ZoFR8tDUzTs9CvBntahwxJUWP0leEuqxv9BUo rrhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:feedback-id:dkim-signature:dkim-signature; bh=vQs4ynDb5KaPKtPAzLl0Rc9EXZoECrk6bMrSAt43TCw=; b=pAN8SwRMbtpvB/ld8Z6QkqTBqHZ0hiXdGlbGEteyx7SyDEy+SK+b/fbHEH8VcbsnSg AVnDQw5dHpCP13gFwmSW9v/ybAUg5HVXVXy4X38sJciLKUMEef7V9pKMyxYCG1xAs/Ec zY9YqlSGne1jkkyPSrb8kN8bYOakXE1vEv3+4z+VKXh6sR59EHLopfRH+651nnkOqrZn FhNebgHrAduIaVLc+tl0rBPFJ6D2lzVwtBaJ+Wr1vCocfIwUqTxmlrsqR1IhWfMVytw7 lkPqvMKH56QNAJDv7SmJoveq3LsG+CmE7cNGEf+aAcsmOQgeLXujBoqGPS3dijemCze3 0EOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ryhl.io header.s=fm2 header.b=DV2BCGAE; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=bRz94HWq; 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=NONE sp=NONE dis=NONE) header.from=ryhl.io Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e26-20020a17090681da00b009334769e7ebsi374995ejx.790.2023.03.30.13.36.56; Thu, 30 Mar 2023 13:37: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=@ryhl.io header.s=fm2 header.b=DV2BCGAE; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=bRz94HWq; 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=NONE sp=NONE dis=NONE) header.from=ryhl.io Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229794AbjC3U2c (ORCPT + 99 others); Thu, 30 Mar 2023 16:28:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbjC3U2b (ORCPT ); Thu, 30 Mar 2023 16:28:31 -0400 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46FF7C9; Thu, 30 Mar 2023 13:28:30 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 1907D3200959; Thu, 30 Mar 2023 16:28:29 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 30 Mar 2023 16:28:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ryhl.io; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1680208108; x=1680294508; bh=vQs4ynDb5KaPKtPAzLl0Rc9EXZoECrk6bMr SAt43TCw=; b=DV2BCGAEYE89/0qB9BCxZL65j8OujS0AqVHYgP6geTlizxxKs+a n+h1/Rq0qDKGEvXlhQ3O/WNsnR1iUWY5opFs1bthRv66hQkp2mSUsBFhJ365fqrc uWVQjDkLbzhI9GwllS5MMma21dc+SJjKS91l+tC9sSGHCPWo+8H6n/Vxj9+whEwL q/U2I1Cy3UsFHQyuS8n8rolINuuX/p0H5US0IQtqQh4QJRA3IUX6RgaOWaYVkxQA nda80+Px8RfxpltFBmJn98UEWFHA8DLkegrG7PBbgVMF/vH9fzzreLw3H6EASD79 z3Mf3fHhdb1gpToC6TpqWN2+xHZPmk8jrwg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1680208108; x=1680294508; bh=vQs4ynDb5KaPKtPAzLl0Rc9EXZoECrk6bMr SAt43TCw=; b=bRz94HWqUtIeSEAzn9WBi4BZ43hv/ArbNIhDIIKZl6nL1zBd+Mp Ny0EEMvuLcADVBfXvTvp4W4uT+lwMvjIz0CqAGyLB2j0hItCZIGMgUPK+6v8lzim bNwZV/CR4DhR+pQDW08TC71bTSu//+oOs6BcbDH5gN248SatJxg/YxaDUB28s38Z Z+4sG4kLIFAajLDA1HQEuat345FU4SBVXUdnmubK0VvGgAYTmLdAeBtCBtPS1xYE ss5nvUNvlxpc+q6yCElrDpKQhZNFkw3y/cn8PbyvXVD0yrvzYHKR38Cy+ucnLDj3 iHzRN/qeEno8Zs8jHNmGDCCAkqGJS02kfCA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdehledgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtfeejnecuhfhrohhmpeetlhhi tggvucfthihhlhcuoegrlhhitggvsehrhihhlhdrihhoqeenucggtffrrghtthgvrhhnpe ehudduvdetkedvkedtudeludfgfffhudegjeeguedvvedtteevjeehheeiffefgeenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhitggvse hrhihhlhdrihho X-ME-Proxy: Feedback-ID: i56684263:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 30 Mar 2023 16:28:26 -0400 (EDT) Message-ID: Date: Thu, 30 Mar 2023 22:28:25 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH v3 08/13] rust: init: add `stack_pin_init!` macro Content-Language: en-US-large To: Benno Lossin Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , =?UTF-8?Q?Bj=c3=b6rn_Roy_Baron?= , Gary Guo References: <20230329223239.138757-1-y86-dev@protonmail.com> <20230329223239.138757-9-y86-dev@protonmail.com> <4b048bfc-e4fe-8c2f-ebfe-9b6a410cd8b8@protonmail.com> From: Alice Ryhl In-Reply-To: <4b048bfc-e4fe-8c2f-ebfe-9b6a410cd8b8@protonmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS 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 3/30/23 17:19, Benno Lossin wrote: > On 30.03.23 17:00, Alice Ryhl wrote: >> On 3/30/23 00:33, y86-dev@protonmail.com wrote: >>> From: Benno Lossin >>> >>> The `stack_pin_init!` macro allows pin-initializing a value on the >>> stack. It accepts a `impl PinInit` to initialize a `T`. It allows >>> propagating any errors via `?` or handling it normally via `match`. >>> >>> Signed-off-by: Benno Lossin >> >> Reviewed-by: Alice Ryhl >> >>> --- >>> +#[macro_export] >>> +macro_rules! stack_pin_init { >>> + (let $var:ident $(: $t:ty)? = $val:expr) => { >>> + let mut $var = $crate::init::__internal::StackInit$(::<$t>)?::uninit(); >>> + let mut $var = { >>> + let val = $val; >>> + unsafe { $crate::init::__internal::StackInit::init(&mut $var, val) } >>> + }; >>> + }; >>> + (let $var:ident $(: $t:ty)? =? $val:expr) => { >>> + let mut $var = $crate::init::__internal::StackInit$(::<$t>)?::uninit(); >>> + let mut $var = { >>> + let val = $val; >>> + unsafe { $crate::init::__internal::StackInit::init(&mut $var, val)? } >>> + }; >>> + }; >>> +} >> >> This will be inconvenient to use if the initializer is infallible and is >> used inside an infallible function. However, I'm not sure what a better >> alternative would be. Perhaps we should have three variants? > > That could be an option, any ideas for the syntax though? Or should it > be a different macro like `stack_pin_init!` and `try_stack_pin_init!`? You've also split up the other macros into a fallible and infallible version, so I think the same would be fine here. Perhaps use `stack_pin_try_init!` as the name? >> Also, maybe a `<-` rather than `=` would be more consistent? > > That is sadly not possible, since `<-` is not allowed after `ty` fragments. > >> Anyway, I don't think this should block the PR. We can revisit it later >> if it becomes a problem. > > Sure. > > -- > Cheers, > Benno > >