Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp2432786rdg; Mon, 14 Aug 2023 02:14:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVzK5nvHOcvj18nf9VTrrJJPJVyLCuYdec0iOTJscOXhcYyA0X/cwFCvrW365MtzvWzou3 X-Received: by 2002:a17:906:30ce:b0:99b:de2a:d9a6 with SMTP id b14-20020a17090630ce00b0099bde2ad9a6mr7867079ejb.41.1692004453090; Mon, 14 Aug 2023 02:14:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692004453; cv=none; d=google.com; s=arc-20160816; b=ppDR5VWNN9ZR0W/jaQgmbUGZbCavCbWUjQWSH/vH+I+q6BWcbmoZwt7cPvxfpjg1gn vPFtux953SkeKqnUMkX9LusIJlVkalIdc8IzETlLzJjtsLljA3wQxUNw3E3gUuqdLrwM S7aKl8VgQ/AqnhyYA3dP8zgP+1Xou20DjvCVYcaPzxPuAMFHiWYXWAwuj8ICNCpOMZpQ HmbRxF1mGy+JQp+IABnzOk9ybNMBLlqmdyIoZOMb8EmI8lWs4Mtz9/hvHNZ948baB6OR mHKpKpqB/NB+xvkFTekyOwQqUg8oJmmarZwMyP6v/kRkBHfTfUpoA26G1htyKaKzpmkT aRLA== 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=kwnI5+l3SlcIXt3YVOWTO7NQq0uMh4+BFKhqIK/WWV4=; fh=TE4onW3Du2FQ1EsedDK8TzgRHOYndfJXYpOtlseWrM0=; b=Gg+r/tlpQdegJ240eCWXY/j9xaY+uIk2/JCQfEnLwMfPZYDGaIlR4KLPJoWO5fWCBd 4OUnGO9wrq/s5YR4TxznoG+woe0h7Wkco/vMS3RcK5cTwL+lD8cu7NjMmpt6CK1lIGRM iWDsIDTdvCXKl7pb29b/n3g+r/M3vvNzSdrFSWoOEF6teH+mpWbm9fd+SsvXo76CFvyB hxeTrT5/ZFgHS9Fb/gCgB38+GiOvSjzk6IzLZElvfeT/flKVj90g56j7PL/sfv1e+6+E xjM9MuOyXBvb+8ETG/L6wm64FTdNMgUPCFl0t6ZHkenaXAP0QMRyrvUwhmiW460wYxKr Y5LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=WfvQxVkN; 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 jo25-20020a170906f6d900b0099bc106611esi7719016ejb.824.2023.08.14.02.13.49; Mon, 14 Aug 2023 02:14:13 -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=WfvQxVkN; 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 S233134AbjHNIsr (ORCPT + 99 others); Mon, 14 Aug 2023 04:48:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231862AbjHNIsP (ORCPT ); Mon, 14 Aug 2023 04:48:15 -0400 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55A66BB for ; Mon, 14 Aug 2023 01:48:00 -0700 (PDT) Date: Mon, 14 Aug 2023 08:47:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1692002878; x=1692262078; bh=kwnI5+l3SlcIXt3YVOWTO7NQq0uMh4+BFKhqIK/WWV4=; 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=WfvQxVkNyUpKJJPJeXtyGEsl3PEPcbjPmZ8VluT61s46kQCr3Xt9ftuIQDW/MExjb 7W1lqo3DojXVv/la0jVGx/X0G5OL0YcXLGQpEMEo0Qtyfy016ghhJBO6JRVMsoiIOY 9AIHL0zxiESNlq9BQdAQl0jmExBQagTMNNKIDeNl25iJBAWBEOMOwhforqTWTDGTnW TETwDZ+HLzwFDhjXMLi1sFvPyIOAyncw4v2zhqHoG1bwAHbGhSNiS+tqfe97UfFEFG /t4SZm36ff/LfJzsXk2Ud5KLsnDPJzp47y4sLgiv1RspkzIP42uDHRyNec4CfJ7ULv XkixB7uXama/A== 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, patches@lists.linux.dev, Martin Rodriguez Reboredo Subject: [PATCH v4 11/13] rust: init: make `PinInit` a supertrait of `Init` Message-ID: <20230814084602.25699-12-benno.lossin@proton.me> In-Reply-To: <20230814084602.25699-1-benno.lossin@proton.me> References: <20230814084602.25699-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 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`. Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Alice Ryhl Reviewed-by: Gary Guo Signed-off-by: Benno Lossin --- v3 -> v4: - added Reviewed-by from Gary. v2 -> v3: - add blank missing line, - added Reviewed-by's from Martin and Alice. rust/kernel/init.rs | 21 ++++++++------------- rust/kernel/init/__internal.rs | 12 ++++++++++++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs index f91ecd3b1edf..a15fb5ddbc7d 100644 --- a/rust/kernel/init.rs +++ b/rust/kernel/init.rs @@ -807,7 +807,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 @@ -818,18 +818,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 @@ -972,6 +960,13 @@ unsafe fn __init(self, slot: *mut T) -> Result<(), E> = { } } =20 +// 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) } + } +} + /// Smart pointer that can initialize memory in-place. pub trait InPlaceInit: Sized { /// Use the given pin-initializer to pin-initialize a `T` inside of a = new smart pointer of this 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