Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4233100rwl; Mon, 3 Apr 2023 01:45:08 -0700 (PDT) X-Google-Smtp-Source: AKy350YMdSrWT4SLTn87YKqaO2CFyZGBB9LfP0dW284XaJFli3G5pS9dtzy5AtzDMD/p0P/MHD63 X-Received: by 2002:aa7:cccc:0:b0:502:2953:c0b2 with SMTP id y12-20020aa7cccc000000b005022953c0b2mr17055427edt.12.1680511508540; Mon, 03 Apr 2023 01:45:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680511508; cv=none; d=google.com; s=arc-20160816; b=JjuFDmdTb0mMnMxL3QiyTyFiX/7smnr5LvJbsC2V5VEDdODylB/eRGh+qq24Ao7TGN g6ykibeCZ0ytoMiORlRqDC5fMb5209tMTvvgh1oD+HEB0mm0+Wb0ubXPiPhy5gDbzbm/ MbSdQqZFDCpc+6i08UuPyx3ZL8Pzr9cGB5GrNlxGzhjUcEr1JB+vaY+Auk38X5ESO3BE KNDJU9NvgKzFZvjNeri4KPl13LTX9sb+oZFT6AJYIkWUVS4mJOvoLqYPyW6QMgPoJ9Mo 8T1VN66YvkIWN1Q6+OVtGrjWONnGUL1apHvbXE2j+bR/yZNL9ILf8O6T+vAwZ94wAdze 5CSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date:subject :cc:to:from:user-agent:references:dkim-signature; bh=QTJlPe83VxVN/a/064MffW70nIdppbk/yJjbPFL4b3k=; b=scB8sbaJZw19hZfVSPJT/kS9pFJ7u8AMprlAf1EU6WZDyAHCwNpp9erovtQzSh0j2O NnmNJOCpB7ecA/tqAE4IGg9/eUE3rczGoxqK3Mejek/JDb0U8tUIJzJ2jvnUZq2kIL0V vBE4aL5xD6pwSjcElGB2u5JLrVb6cbHa8jP/YSRgIUu+budidmQ1mtRBNMBUn5quMhEj 9SHEk3VqezbjjkHhALdtmrnPHTHA+gbyJoqKyiu3olRjS8iBonA//qGRnr6KltK3dXCr cdZjj4fhuFZHz6qE6QpaZS1d1VJt6Al+oY/NfpeSrfyEzE2Z1oSGG5BR/LnoRR49STbV mA4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metaspace-dk.20210112.gappssmtp.com header.s=20210112 header.b=2LfxvaU3; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q22-20020a056402033600b00501d50c1416si146918edw.411.2023.04.03.01.44.41; Mon, 03 Apr 2023 01:45:08 -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=@metaspace-dk.20210112.gappssmtp.com header.s=20210112 header.b=2LfxvaU3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231749AbjDCImD (ORCPT + 99 others); Mon, 3 Apr 2023 04:42:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231761AbjDCIl7 (ORCPT ); Mon, 3 Apr 2023 04:41:59 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 788C4EB70 for ; Mon, 3 Apr 2023 01:41:49 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id h8so114152009ede.8 for ; Mon, 03 Apr 2023 01:41:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20210112.gappssmtp.com; s=20210112; t=1680511307; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:from:to:cc:subject:date:message-id:reply-to; bh=QTJlPe83VxVN/a/064MffW70nIdppbk/yJjbPFL4b3k=; b=2LfxvaU3LlfabrRlPEyZCExJAxNv+/yycGqARiUwnciKzD5fIHuqXS864XRArjAQ8h lrQgJcIOqR+nw3z3IjSxe4UmHBdCwwyGguBXplfv9d4bctz+iCX4NON6F6Y+bu+tje3z fFWiIybNVXTfUehTV5zfYnLaTG/mg4ubFJ7K8luth9p801eSrnkYjyl5JlYkvcMGF6s9 M9rB/ho9d/oBu9KuxQEGkrEAyzIIhC0d0sjVteUVU+WTqG7g/D3NJ3r74CMETNI/uB/v hTnKtpvgOJ1AllPKfEOPJwiEEGFF+mmbP939fQXD5n62EZUkuItGVb/VRa8CDskHRtib pZLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680511307; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=QTJlPe83VxVN/a/064MffW70nIdppbk/yJjbPFL4b3k=; b=ikokMFlAr7P0bUgSl9oRUikn5YwJIgpmO9Y72jshMyWVdWBYL/wAxTjs7U2Qid0ItM /bwXwVViYGNbY4W6IzuDNVO60XbP+joZWZYI9pxKlGf13weaOlzLITfBzeLXBaIbPR3A q7nCB0b84GQCXUkG7PPO0z1JyMkARpnOYCPJuJoWUsm0PKJp598j+FHycEMgRZkayqGq ihLzfIVYFN9MCulSWWgOJsPIuaiT/nNpsywkWwobMDS5Siz+wj64x1gjkFPjWYm3xqE+ IXwFoSUPCTleUoqzl3i+3y1mv/gGgDjCmeXBsWI7poqjWeTPmdjVTlOv5SQAhclQfPrP eWDg== X-Gm-Message-State: AAQBX9fG1Z1xAUjIim8TLTL4Hsf/acoJx+KCydbonoCFLrnJjjCaQLAp gwR0+68wxItHnH+rbCr9mUI2LQ== X-Received: by 2002:a17:906:aeda:b0:931:20fd:3d09 with SMTP id me26-20020a170906aeda00b0093120fd3d09mr19595275ejb.17.1680511307670; Mon, 03 Apr 2023 01:41:47 -0700 (PDT) Received: from localhost ([79.142.230.34]) by smtp.gmail.com with ESMTPSA id ld4-20020a1709079c0400b009486efb9192sm1535169ejc.11.2023.04.03.01.41.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 01:41:47 -0700 (PDT) References: <20230331215053.585759-1-y86-dev@protonmail.com> <20230331215053.585759-4-y86-dev@protonmail.com> User-agent: mu4e 1.9.18; emacs 28.2.50 From: Andreas Hindborg To: y86-dev@protonmail.com Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn?= Roy Baron , Alice Ryhl , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Alice Ryhl , Andreas Hindborg Subject: Re: [PATCH v4 03/15] rust: sync: change error type of constructor functions Date: Mon, 03 Apr 2023 10:41:08 +0200 In-reply-to: <20230331215053.585759-4-y86-dev@protonmail.com> Message-ID: <87y1n9jr1x.fsf@metaspace.dk> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=0.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE 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 y86-dev@protonmail.com writes: > From: Benno Lossin > > Change the error type of the constructors of `Arc` and `UniqueArc` to be > `AllocError` instead of `Error`. This makes the API more clear as to > what can go wrong when calling `try_new` or its variants. > > Signed-off-by: Benno Lossin > Cc: Gary Guo > Cc: Andreas Hindborg > Cc: Alice Ryhl > --- Reviewed-by: Andreas Hindborg > rust/kernel/sync/arc.rs | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs > index f2f1c83d72ba..aa7135f0f238 100644 > --- a/rust/kernel/sync/arc.rs > +++ b/rust/kernel/sync/arc.rs > @@ -17,11 +17,11 @@ > > use crate::{ > bindings, > - error::Result, > types::{ForeignOwnable, Opaque}, > }; > use alloc::boxed::Box; > use core::{ > + alloc::AllocError, > marker::{PhantomData, Unsize}, > mem::{ManuallyDrop, MaybeUninit}, > ops::{Deref, DerefMut}, > @@ -149,7 +149,7 @@ unsafe impl Sync for Arc {} > > impl Arc { > /// Constructs a new reference counted instance of `T`. > - pub fn try_new(contents: T) -> Result { > + pub fn try_new(contents: T) -> Result { > // INVARIANT: The refcount is initialised to a non-zero value. > let value = ArcInner { > // SAFETY: There are no safety requirements for this FFI call. > @@ -469,7 +469,7 @@ pub struct UniqueArc { > > impl UniqueArc { > /// Tries to allocate a new [`UniqueArc`] instance. > - pub fn try_new(value: T) -> Result { > + pub fn try_new(value: T) -> Result { > Ok(Self { > // INVARIANT: The newly-created object has a ref-count of 1. > inner: Arc::try_new(value)?, > @@ -477,7 +477,7 @@ impl UniqueArc { > } > > /// Tries to allocate a new [`UniqueArc`] instance whose contents are not initialised yet. > - pub fn try_new_uninit() -> Result>> { > + pub fn try_new_uninit() -> Result>, AllocError> { > Ok(UniqueArc::> { > // INVARIANT: The newly-created object has a ref-count of 1. > inner: Arc::try_new(MaybeUninit::uninit())?,