Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp8276399rwp; Wed, 19 Jul 2023 07:42:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlGqUeQqGIjXsIAAVdZMg/OM82e157rEJPECeixX45J7b/ngg3hqDhrLSNTrcFPM3tyCBugD X-Received: by 2002:a05:6358:4402:b0:134:c850:e8c5 with SMTP id z2-20020a056358440200b00134c850e8c5mr17247142rwc.19.1689777734904; Wed, 19 Jul 2023 07:42:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689777734; cv=none; d=google.com; s=arc-20160816; b=JW+/wEAi64ad+lJuH1GWtP9DERSVdx7oY0k7rlMFPJkyNJAwAfcQT4pCMrR4oR6Jeh H1wxQRprdQd6/6uKBo0uLuN8sHSHFrWggTsu/dGPCu072Kqzb5+YZ2f+5ubC0+ocNPRq JUhH4IcbphFLKIO+rXo7EB47McZLzg3q8K3LjO2iuJsvuXgzzmjffPwyB8NcEQgAxgHV I8K8CWYpaf3QOGQ0jQ32HRTJBhinQDLGZEZei2gjkdI3x4DzVEcPitHNKOa4kyZo1VtI sKxu+dcH0UFCs7w/N4Pizu4qSK34gjX9zxN1mpTWRRCagA58NmpgL5fWNRxicTWWCmJw bTag== 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=PY3Ej/DIQyjr1nZd2KtYmX46DbaLv5+ISgZDgCfGk58=; fh=qm1bOEYzVYZKL4fg86TgWb8D+QJA9mGpUhKFp2A6Xio=; b=ua55SHYCk4h0cdpB6StudtMaeJvFX4EWQHdMARzM26Cj+QnLyqyTyONw8zyBduiCRY ZbR4l1MVGk4erU+7jZD8jDBVFTJ5IXDlebkB87M8Uoc4Ty6SnpaaX6KUaPjRC2wqU6GD RxffoMElgalFWmnOeanX0ds+57qQgIR4K33+9pfIMk9B8fo+hOwYDqIbdjjNdcK6AOZN xq4Wj03lnSuvtZdhczfKcbC9Mpgz+IOwPiTNsXgu3ktPqGixm/Et3qa1eyBS/8lA46UB g3KYDSTkkGOjyObNkJsLdMZOy7z9uG4/U3NlXwI6I0wq2carJAbc+32kMUKzAqUjJlgj wrIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=JbZ3uC2P; 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 s16-20020a656450000000b005573740ea33si3574332pgv.534.2023.07.19.07.42.02; Wed, 19 Jul 2023 07:42:14 -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=JbZ3uC2P; 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 S231556AbjGSOWQ (ORCPT + 99 others); Wed, 19 Jul 2023 10:22:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231551AbjGSOWN (ORCPT ); Wed, 19 Jul 2023 10:22:13 -0400 Received: from mail-40133.protonmail.ch (mail-40133.protonmail.ch [185.70.40.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E01B5198D; Wed, 19 Jul 2023 07:21:54 -0700 (PDT) Date: Wed, 19 Jul 2023 14:21:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1689776494; x=1690035694; bh=PY3Ej/DIQyjr1nZd2KtYmX46DbaLv5+ISgZDgCfGk58=; 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=JbZ3uC2P97beRJVTZB8zzWyQWqTrD2X3DqO614uvYpMuDtjxTr8BcSXwvtmuhFBe6 C7yftw8MTtWqDeWbJA+4c5RRhAxTYBJBRKv8bo8z05YKe/gqdOKV+TKqA4duvrxZIn wcC9LKyrbxSxp8GlSIHztsAgFe51qHjkWNc51k1AS9SUQduqUH4bDCEyqvX0r0qHn3 BpTfDawsATp14Zoz5DH5WH9XkeUOTkkZdyXX59ofNUgelkkhVs9nen57LuxEfgYHx/ 9N0PZbP76v0NSO8drATOMc1SxQnzzngSkeYBtqoEWsV3DZlgaoqkXiEMWEwFgJLER2 6vJwO4xk9yv0A== To: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor From: Benno Lossin Cc: Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Andreas Hindborg , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 10/12] rust: init: make `PinInit` a supertrait of `Init` Message-ID: <20230719141918.543938-11-benno.lossin@proton.me> In-Reply-To: <20230719141918.543938-1-benno.lossin@proton.me> References: <20230719141918.543938-1-benno.lossin@proton.me> 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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Remove the blanket implementation of `PinInit for I where I: Init`. This blanket implementation prevented custom types that implement `PinInit`. Signed-off-by: Benno Lossin --- rust/kernel/init.rs | 20 +++++++------------- rust/kernel/init/__internal.rs | 12 ++++++++++++ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs index fa1ebdbf5f4b..3c7cd36a424b 100644 --- a/rust/kernel/init.rs +++ b/rust/kernel/init.rs @@ -805,7 +805,7 @@ pub unsafe trait PinInit: = Sized { /// /// [`Arc`]: crate::sync::Arc #[must_use =3D "An initializer must be used in order to create its value."= ] -pub unsafe trait Init: Sized { +pub unsafe trait Init: PinInit { /// Initializes `slot`. /// /// # Safety @@ -816,18 +816,6 @@ pub unsafe trait Init: Si= zed { unsafe fn __init(self, slot: *mut T) -> Result<(), E>; } =20 -// SAFETY: Every in-place initializer can also be used as a pin-initialize= r. -unsafe impl PinInit for I -where - I: Init, -{ - unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> { - // SAFETY: `__init` meets the same requirements as `__pinned_init`= , except that it does not - // require `slot` to not move after init. - unsafe { self.__init(slot) } - } -} - /// Creates a new [`PinInit`] from the given closure. /// /// # Safety @@ -968,6 +956,12 @@ unsafe fn __init(self, slot: *mut T) -> Result<(), E> = { Ok(()) } } +// SAFETY: Every type can be initialized by-value. `__pinned_init` calls `= __init`. +unsafe impl PinInit for T { + unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> { + unsafe { self.__init(slot) } + } +} =20 /// Smart pointer that can initialize memory in-place. pub trait InPlaceInit: Sized { diff --git a/rust/kernel/init/__internal.rs b/rust/kernel/init/__internal.r= s index 7abd1fb65e41..12e195061525 100644 --- a/rust/kernel/init/__internal.rs +++ b/rust/kernel/init/__internal.rs @@ -32,6 +32,18 @@ unsafe fn __init(self, slot: *mut T) -> Result<(), E> { } } =20 +// SAFETY: While constructing the `InitClosure`, the user promised that it= upholds the +// `__pinned_init` invariants. +unsafe impl PinInit for InitClosure +where + F: FnOnce(*mut T) -> Result<(), E>, +{ + #[inline] + unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> { + (self.0)(slot) + } +} + /// This trait is only implemented via the `#[pin_data]` proc-macro. It is= used to facilitate /// the pin projections within the initializers. /// --=20 2.41.0