From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-244108.protonmail.ch (mail-244108.protonmail.ch [109.224.244.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2415525CC70 for ; Sat, 6 Sep 2025 04:25:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=109.224.244.108 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757132748; cv=none; b=YoHB3rYxW5IJw2ns24JBccmbNvT24qStp5GcheIvUhL+11YkkbH7dFlqOHgbJdIbI/M/w17uQoIXqOAe/DJmzayCGdZJHy4WK7eC73XWkSq4ac8MRqJvIDLwLE8kC26vMa2918BL9l2/KqmiBySzLLrsi1bnr+RmeN7h7aajCjY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757132748; c=relaxed/simple; bh=aFiHOT2N3x862LwImeQcGRwJigmPXJ5Y1d3NRFis4GA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tJxLrxG5ILQyDnfOxcaEV3rhMLBoTuTR9JabXUO+eEMPybdpIa6aHNujFQ11/H1sb9iPbFprpAOPqiV/qd/jJOVaWNIOZIB6PEXfZmP/t/9vH+hno9MF1dSmnWJrxKjXhOd6zLABB117cWdB14aaIztnZxjmTr14Q/Yj3irO+kw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weathered-steel.dev; spf=pass smtp.mailfrom=weathered-steel.dev; dkim=pass (2048-bit key) header.d=weathered-steel.dev header.i=@weathered-steel.dev header.b=l+3LD8jE; arc=none smtp.client-ip=109.224.244.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weathered-steel.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weathered-steel.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=weathered-steel.dev header.i=@weathered-steel.dev header.b="l+3LD8jE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=weathered-steel.dev; s=protonmail3; t=1757132744; x=1757391944; bh=B/IlGHXa/C4Z4Q1Cy9giG+EL76xGZc/bXMPQj4Egy/4=; h=Date:From:To:Cc:Subject:Message-ID:References:In-Reply-To:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=l+3LD8jEAy9Jzf2aEI0BOsqTN91v1FhXUBuCS2l9c6BfPCoxQtWgKibVNb6ERobq3 9GlIz0VSkpCJ1V/2mv4tmm8or+KjRq5MP5cdutbnj04PFNTsXwNGcJbDBPv1Rgfuy6 DgyJ0x9nBUNXl6j0Hbi7dOAd63rVhbeZBDJi++Ge7Ce9OiNKETTWHx0li7dZeB8PZZ wj81m08tmrfxn1l9X7jqZz89JiwvkEr2ko5i6Eb/dMEWBRkNND/Jit7VgCs/H+jiCk SWRLz1x2ZqBiWBHavKStM5jJ0IqTZ8wvwmpLA0f8VNwuLoCNcum1v1h1gDiHO33oj6 ETUPWXoZnZMWg== X-Pm-Submission-Id: 4cJgBF68lWz1DDBs Date: Sat, 6 Sep 2025 04:25:38 +0000 From: Elle Rhumsaa To: Boqun Feng Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, lkmm@lists.linux.dev, Will Deacon , Peter Zijlstra , Mark Rutland , Ingo Molnar , Thomas Gleixner , "Paul E. McKenney" , stern@rowland.harvard.edu, Miguel Ojeda , alex.gaynor@gmail.com, Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Alice Ryhl , Trevor Gross , Danilo Krummrich , Andreas Hindborg , Alexandre Courbot Subject: Re: [PATCH 11/14] rust: make `Arc::into_unique_or_drop` associated function Message-ID: References: <20250905044141.77868-1-boqun.feng@gmail.com> <20250905044141.77868-12-boqun.feng@gmail.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250905044141.77868-12-boqun.feng@gmail.com> On Thu, Sep 04, 2025 at 09:41:38PM -0700, Boqun Feng wrote: > From: Gary Guo > > Make `Arc::into_unique_or_drop` to become a mere associated function > instead of a method (i.e. removing the `self` receiver). > > It's a general convention for Rust smart pointers to avoid having > methods defined on them, because if the pointee type has a method of the > same name, then it is shadowed. This is normally for avoiding semver > breakage, which isn't an issue for kernel codebase, but it's still > generally a good practice to follow this rule, so that `ptr.foo()` would > always be calling a method on the pointee type. > > Reviewed-by: Benno Lossin > Signed-off-by: Gary Guo > Reviewed-by: Alexandre Courbot > Signed-off-by: Boqun Feng > Link: https://lore.kernel.org/r/20250723233312.3304339-3-gary@kernel.org > --- > rust/kernel/sync/arc.rs | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs > index 63a66761d0c7..4ee155b43b2d 100644 > --- a/rust/kernel/sync/arc.rs > +++ b/rust/kernel/sync/arc.rs > @@ -321,7 +321,7 @@ pub fn ptr_eq(this: &Self, other: &Self) -> bool { > /// use kernel::sync::{Arc, UniqueArc}; > /// > /// let arc = Arc::new(42, GFP_KERNEL)?; > - /// let unique_arc = arc.into_unique_or_drop(); > + /// let unique_arc = Arc::into_unique_or_drop(arc); > /// > /// // The above conversion should succeed since refcount of `arc` is 1. > /// assert!(unique_arc.is_some()); > @@ -337,18 +337,18 @@ pub fn ptr_eq(this: &Self, other: &Self) -> bool { > /// let arc = Arc::new(42, GFP_KERNEL)?; > /// let another = arc.clone(); > /// > - /// let unique_arc = arc.into_unique_or_drop(); > + /// let unique_arc = Arc::into_unique_or_drop(arc); > /// > /// // The above conversion should fail since refcount of `arc` is >1. > /// assert!(unique_arc.is_none()); > /// > /// # Ok::<(), Error>(()) > /// ``` > - pub fn into_unique_or_drop(self) -> Option>> { > + pub fn into_unique_or_drop(this: Self) -> Option>> { > // We will manually manage the refcount in this method, so we disable the destructor. > - let me = ManuallyDrop::new(self); > + let this = ManuallyDrop::new(this); > // SAFETY: We own a refcount, so the pointer is still valid. > - let refcount = unsafe { me.ptr.as_ref() }.refcount.get(); > + let refcount = unsafe { this.ptr.as_ref() }.refcount.get(); > > // If the refcount reaches a non-zero value, then we have destroyed this `Arc` and will > // return without further touching the `Arc`. If the refcount reaches zero, then there are > @@ -365,7 +365,7 @@ pub fn into_unique_or_drop(self) -> Option>> { > // must pin the `UniqueArc` because the values was previously in an `Arc`, and they pin > // their values. > Some(Pin::from(UniqueArc { > - inner: ManuallyDrop::into_inner(me), > + inner: ManuallyDrop::into_inner(this), > })) > } else { > None > -- > 2.51.0 > > Reviewed-by: Elle Rhumsaa