Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2257350rwl; Thu, 30 Mar 2023 08:02:46 -0700 (PDT) X-Google-Smtp-Source: AKy350a3INZnNVju7p6GdE/EETf12yt+18WKmNxm+MrPhC5yrHwup05Omb6h+Bl5Ba1GBShLoc3A X-Received: by 2002:a17:902:e54c:b0:1a2:1a52:14b3 with SMTP id n12-20020a170902e54c00b001a21a5214b3mr2657855plf.4.1680188566178; Thu, 30 Mar 2023 08:02:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680188566; cv=none; d=google.com; s=arc-20160816; b=HX26VeTwh3qbICrE3AXit6L3db6SCTrkkAaUbe1zmfREYEuvrisDC8++9/QpdVO4jw MnGagqVrXKjVVKVryAAGW6YRp6aBWdeyQZZ4SFY0edC9qhK6tcFMvZ4xfnFhVzrYzmKY YK23/Ew505k6j1gSJXAVXe+MXtM8mF6u7Jt7LVfGON5Ig8rnG3r7aaxnq65mrcIMBuu3 RZyp9dxAkKMAY2BIm7dvwcbLMnKv57x9KmA+e0cW8W0tOfI5W1WmBrmMBfvX4T++6SFe noRfmCrw4TSJfts5XobTzf8V9okcF6bnnhgOY/61oBPqL4BtvGFipPIHdtslCU5kccKZ iNpg== 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=XkIIRswdtZjN/RQYs9WPqwblrbMN+FP/NLq72KD8BRw=; b=nQMe2ZbiD2fTAvhGTwgyHtEqyV9UT865+T6r23cEhgLxhf00J+v5kWJIwzaqdSbszF 8xIsbvJcNGG/0S94eoi/+8JbKnTOieDaGKXRQ2pK7FwwrPR0jG7phVc9R7l5b5jL6b9M VHlU5/btOg/czpEpraQRB50ghcyA2L9XA02RlMjMyX4yJNPxx6Gn/n3RlJgXw7hg75SN vsPLRjh/0OejnDBj4/0vdinAKP+sihC9rpMmyBG48TIeB4BTFqkXuLmpvCJtFrFVv4sx UBp23cpzNiBlAzxDdV6FTFwnSshKKAGtKcjv7x9COW8UJMaQe7ZS1N+jEz5JErZAKcue 1ciQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ryhl.io header.s=fm2 header.b=fHzuj0sg; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=DqbTkCuo; 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 nv2-20020a17090b1b4200b00233ce098f21si4453944pjb.135.2023.03.30.08.01.16; Thu, 30 Mar 2023 08:02:46 -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=fHzuj0sg; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=DqbTkCuo; 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 S232664AbjC3PAm (ORCPT + 99 others); Thu, 30 Mar 2023 11:00:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232645AbjC3PAl (ORCPT ); Thu, 30 Mar 2023 11:00:41 -0400 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E3DAA2; Thu, 30 Mar 2023 08:00:40 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id C2BA73200948; Thu, 30 Mar 2023 11:00:38 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 30 Mar 2023 11:00:39 -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= 1680188438; x=1680274838; bh=XkIIRswdtZjN/RQYs9WPqwblrbMN+FP/NLq 72KD8BRw=; b=fHzuj0sg/OTRdHaJNnNJn+W7xiyLvh7M+J7WJX7C3FU4JoGeyAr T3PAgf5yhPayyxE+292EVwpLALkDjzfqaLmk/ssbt0Nb7ZLNi3pZUGxQDL6NXu6T 8EbGPiPsL8C/N8/gMEedoPw7x5gSS0Y69/jM0/70vW4Y5ktgyMfrbvfmnKULB81G tcmf6eEmY9f56JYwfdiGhAzl8BNYHMKui7KNwgdxw47GFuileOmhJX4hHvndVUJE k4nlCezqK0cLdXceGBOQv4OPfpKoDhF4hOBDpTgW+6/2yTzQKNbZbiglPXQw7Iyc DQldq0wMrAV47YYNXYvcuOzkg/BfWizjULw== 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= 1680188438; x=1680274838; bh=XkIIRswdtZjN/RQYs9WPqwblrbMN+FP/NLq 72KD8BRw=; b=DqbTkCuokA5SSxmsX0iyYwlNtU0y5H+QE4fssY+o4WRd44vk6ES 2gsARYZTXVDwwP8N3vjzRcygQUqNnUTX+DLs0bbG6rTOJceJaWJN+YXOOvPhwXoB YVacXor7I7FFSNtwR78Sl6vyw4/aj0qQzuJXhajsIbQLB5P6BqT/s4Q4bXhd5JD5 B8vPDepEC4YpsW3TqLEz8sOjcNRrASucWY19/911Po6XuBs+Uv5ESTS89KBjQ7p4 FwoqCEEpyet6I6TTGiZxGp4SXGCbz1FiJJWj6nCYYyy2xfX90dXTna3vay+24bSf qZ1Lu83iGonV1f/OuuAohO3fAWuVRBlJhFw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdehkedgkedvucetufdoteggodetrfdotf 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 11:00:35 -0400 (EDT) Message-ID: Date: Thu, 30 Mar 2023 17:00:48 +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 To: y86-dev@protonmail.com 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> From: Alice Ryhl In-Reply-To: <20230329223239.138757-9-y86-dev@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 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? Also, maybe a `<-` rather than `=` would be more consistent? Anyway, I don't think this should block the PR. We can revisit it later if it becomes a problem.