Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp13468903rwl; Wed, 4 Jan 2023 08:33:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXvF/FgLxEUmisBmr/YVUrCeq69jbKKp2spOk9P+6Vl1tMlHNhD9t7K0kysw/ZvZIIH1cWiL X-Received: by 2002:a17:907:1c9a:b0:7c1:2f05:7fd6 with SMTP id nb26-20020a1709071c9a00b007c12f057fd6mr46036875ejc.39.1672849997196; Wed, 04 Jan 2023 08:33:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672849997; cv=none; d=google.com; s=arc-20160816; b=EClBcmUz2eBq7X82AaXw+V9aOOUmK1Hpli5zk68xJaIPlvuheuANcDfYnEYzme23im wMo6MLrnCeRbwccekS5/KXVKU18aU+TG6DXI3TXCrF7RxmbAdxM/UP38Bt+r1Aec5eRI fglDVO1EK89xPdAVpty9mJJvExIV2hCs/heiWheJpl8HhmCr6Km9hQC97pB22MAnASci ntmqXwCHK6qEhd9xRH/e7mS0hHbiHWMGGXiqLvZR6zGqZyeUOI3yNhOcTJqJClcEqZO0 ++ucS2Nh3qbwSB/eIWSI+/Kyi7VmCI7h+WAzUypwX2TUYK5NJv/JH9fje9zDJSFvmnKN R6KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:references:subject:cc:to:from :message-id:date:content-transfer-encoding:mime-version :dkim-signature; bh=dlNSZ1zKeio5IM+qciAQdm1jmpnza6LnH9wQe17H30s=; b=i0GxQHEBqTlclE9Tp/DlX2xiGw1FK/XsatlXq40I4teX/bYzzhLmiAgx/umzF/3VQI +hJNeMXxlq6zAsMG5Isd1bH5ToT+nR+KtmN+cZ70Rb7GN9MTOY1m8/N7EWHfaYw5+/wt LTW4gomEum0cGY+Bu93B7BvL6aguLOumZEhGl2g9Yz4Cl9l/ORLZbEgE793mXtN7kSmC Mtr1bxkg0XzAgg43PV+Mq8BwAC2hTbz2spW7m/MW/ls3y/RcnLXB0EvD89D6hvkz9KPK 7ODRLqyNjKZihs1TaKkA9TqhfPlQnmZlzWMJfHrfxiElf2/fhxXYF8EUwG8ty/EPBvb0 NwXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=X2pw5+FF; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg37-20020a170907a42500b007adf38290f1si31674652ejc.642.2023.01.04.08.33.03; Wed, 04 Jan 2023 08:33:17 -0800 (PST) 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=@gmail.com header.s=20210112 header.b=X2pw5+FF; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239865AbjADQ1C (ORCPT + 57 others); Wed, 4 Jan 2023 11:27:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239805AbjADQ0t (ORCPT ); Wed, 4 Jan 2023 11:26:49 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D63D21B1EE; Wed, 4 Jan 2023 08:26:48 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id kw15so83759234ejc.10; Wed, 04 Jan 2023 08:26:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:references:subject:cc:to:from:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=dlNSZ1zKeio5IM+qciAQdm1jmpnza6LnH9wQe17H30s=; b=X2pw5+FFh90/EXimxoLnyKytSb4yzru+hZwCCCd60c5Al23P9O0EPouNqRdmZTVoHw hMdkNZEsUdkzUc6U4X6fDNtaf+e3n0ze06t2lidZUcAGnuYs11WNPVIJ9I0+4py702nh G+lPvwXVaXsxf3VHCDKa7us9TAzGHh8L6Jiis56AVr2Qf47ViIGg6qv3Mt3rSkkXi4Y9 yiU++J/VFmKPXd9WZfulHreIhCtYJ4V7YRNJL7QRmnhsBziYZRMia3vRcIddP3GIQvHa y9MWP6iAsPUbIj5z4RXVmaXMhTpZlUleMPP3QdxS1rxMy4wO+n/d5FDyo7Lb1NUYJeHe O8Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:subject:cc:to:from:message-id:date :content-transfer-encoding:mime-version:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=dlNSZ1zKeio5IM+qciAQdm1jmpnza6LnH9wQe17H30s=; b=fSI+eMYQFR7+pEFzWR+dwiPwpR1Bqp+1B+Y6HZyHY1ya6EwjN9vrE6CKNm1AGZkABa XbBSZkPM9pG7UwqOXTyuqxzIVaENiLxg8LffyFEmir+vZLvs660xF12mxfWDvh/bhMtb DW9LbHosG7wK3j+04Px40yEdNj1Uvh1YJ/0Jn42koUSgs39Ns3YrGIMZGJIINdCBItvH kcCUVOpENyChi/XRVJndQjuQVk1q59uF1rKfig848gTZHszGGnc9IW9/E8kLSeRXFMQq 6jOQjzBTW+I6vpD+JmlSSM+7lghl9PFcTXnnki/cIfQu7X/b3qUXkYd+uISeVVHqllgT qbPQ== X-Gm-Message-State: AFqh2kpH/7zWlmaFl79786mli06mERJCodNh5a21Hw7bunlMoQu30LHz 8HyGzIEBIo8EAUkcXEQSCHw= X-Received: by 2002:a17:906:185b:b0:841:e5b3:c95d with SMTP id w27-20020a170906185b00b00841e5b3c95dmr44848358eje.30.1672849607455; Wed, 04 Jan 2023 08:26:47 -0800 (PST) Received: from localhost (host-82-60-200-213.retail.telecomitalia.it. [82.60.200.213]) by smtp.gmail.com with ESMTPSA id e11-20020a170906314b00b007ae10525550sm15402209eje.47.2023.01.04.08.26.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Jan 2023 08:26:46 -0800 (PST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 04 Jan 2023 17:26:45 +0100 Message-Id: From: "Vincenzo" To: "Wedson Almeida Filho" , Cc: "Miguel Ojeda" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Subject: Re: [PATCH 7/7] rust: sync: add support for dispatching on Arc and ArcBorrow. X-Mailer: aerc 0.8.2 References: <20221228060346.352362-1-wedsonaf@gmail.com> <20221228060346.352362-7-wedsonaf@gmail.com> In-Reply-To: <20221228060346.352362-7-wedsonaf@gmail.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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 On Wed Dec 28, 2022 at 7:03 AM CET, Wedson Almeida Filho wrote: > Trait objects (`dyn T`) require trait `T` to be "object safe". One of > the requirements for "object safety" is that the receiver have one of > the allowed types. This commit adds `Arc` and `ArcBorrow<'_, T>` to > the list of allowed types. > > Signed-off-by: Wedson Almeida Filho Reviewed-by: Vincenzo Palazzo > --- > rust/kernel/lib.rs | 1 + > rust/kernel/sync/arc.rs | 20 ++++++++++++++++++-- > 2 files changed, 19 insertions(+), 2 deletions(-) > > diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs > index 4bde65e7b06b..e0b0e953907d 100644 > --- a/rust/kernel/lib.rs > +++ b/rust/kernel/lib.rs > @@ -15,6 +15,7 @@ > #![feature(allocator_api)] > #![feature(coerce_unsized)] > #![feature(core_ffi_c)] > +#![feature(dispatch_from_dyn)] > #![feature(receiver_trait)] > #![feature(unsize)] > =20 > diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs > index 832bafc74a90..ff73f9240ca1 100644 > --- a/rust/kernel/sync/arc.rs > +++ b/rust/kernel/sync/arc.rs > @@ -92,9 +92,15 @@ use core::{ > /// Coercion from `Arc` to `Arc`: > /// > /// ``` > -/// use kernel::sync::Arc; > +/// use kernel::sync::{Arc, ArcBorrow}; > +/// > +/// trait MyTrait { > +/// // Trait has a function whose `self` type is `Arc`. > +/// fn example1(self: Arc) {} > /// > -/// trait MyTrait {} > +/// // Trait has a function whose `self` type is `ArcBorrow<'_, Self= >`. > +/// fn example2(self: ArcBorrow<'_, Self>) {} > +/// } > /// > /// struct Example; > /// impl MyTrait for Example {} > @@ -123,6 +129,9 @@ impl core::ops::Receiver for Arc {} > // dynamically-sized type (DST) `U`. > impl, U: ?Sized> core::ops::CoerceUnsized> = for Arc {} > =20 > +// This is to allow `Arc` to be dispatched on when `Arc` can be co= erced into `Arc`. > +impl, U: ?Sized> core::ops::DispatchFromDyn= > for Arc {} > + > // SAFETY: It is safe to send `Arc` to another thread when the underl= ying `T` is `Sync` because > // it effectively means sharing `&T` (which is safe because `T` is `Sync= `); additionally, it needs > // `T` to be `Send` because any thread that has an `Arc` may ultimate= ly access `T` directly, for > @@ -297,6 +306,13 @@ pub struct ArcBorrow<'a, T: ?Sized + 'a> { > // This is to allow [`ArcBorrow`] (and variants) to be used as the type = of `self`. > impl core::ops::Receiver for ArcBorrow<'_, T> {} > =20 > +// This is to allow `ArcBorrow` to be dispatched on when `ArcBorrow` can be coerced into > +// `ArcBorrow`. > +impl, U: ?Sized> core::ops::DispatchFromDyn> > + for ArcBorrow<'_, T> > +{ > +} > + > impl Clone for ArcBorrow<'_, T> { > fn clone(&self) -> Self { > *self > --=20 > 2.34.1