Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp4113754rwl; Tue, 27 Dec 2022 22:33:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXv+tiOCyzz81MV+gYU8PPKwLHywcKKjLT0OORVTgCE6mYGsjS1fAeWJ/SFL36D95OhLCBZB X-Received: by 2002:a05:6a20:8f0c:b0:af:cc4e:f2f with SMTP id b12-20020a056a208f0c00b000afcc4e0f2fmr37994639pzk.34.1672209239795; Tue, 27 Dec 2022 22:33:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672209239; cv=none; d=google.com; s=arc-20160816; b=vuzK3uj11OSkZzEzI6ZRf8qJnIr4/CFbwHZQIr5dgeCEdkQ5NiJSDXDEUVunjeXyV+ VglNSLpd+pXj6vvT0yLvGvOHkxmnceL/OYlf3Q3WXyJKzSfuNHvSXKnnF+14ml6F+oVz uwFcH1tCT5usMS4bF9Q20fJnWpXay6KHpqpk5TBICPc8UFeBLXAi7UzYFQLNazfx3JdA 4paNiilA7lqA0c9XFtskhk3p6Nx4y+sBuX5tmn9hTYn8ycwfCWEXhdL2jdhWMl3dtyUX V0KgUWNT7qPNfecVg4+03rqGrxZrwjfaXsMXQZvUffwg4kxSUlqnQef5AM6al1WA9dVb vePA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Nyqdaq2S7tC0O5h+EPr9voswYlNOiiQ62YOgK8u+XEY=; b=GZbeLd3QpCCx5cLA8NUQrhaR6F8zHtX+wWkAvJbQEcwbrctSQiRscmTfviyOlnmO+u uUwK8zUjUZAn/jZVGmZfijHw8jg+kgxDSK2uIZEayeDAa4MFtCf6uMST2rzJoSfan9bc gGvwZA5K9BolrZ53BUvtakLGgYLyTVtQO9Q48HPx6ygFGoDC4oPspcVHYcvnqXy6dVbz HddD8yuwYFP5w1rMVfbaSinHTyrxwex5IaM+iZ9i/DdHEAb796PtWq3BxzMDfycVmrqT OmkSoTY9+Xo7CacvPdT96EYbYduvqZlTVVe+dlrBBQK1sWuBCACjFda+OTr5vYpiravm l9gQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PkjOU0Ow; 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 w184-20020a6362c1000000b004403ddda6e6si16847887pgb.847.2022.12.27.22.33.50; Tue, 27 Dec 2022 22:33:59 -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=PkjOU0Ow; 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 S232272AbiL1GFJ (ORCPT + 65 others); Wed, 28 Dec 2022 01:05:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229666AbiL1GEn (ORCPT ); Wed, 28 Dec 2022 01:04:43 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 054C7DF5E; Tue, 27 Dec 2022 22:04:42 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id t15so5238847wro.9; Tue, 27 Dec 2022 22:04:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Nyqdaq2S7tC0O5h+EPr9voswYlNOiiQ62YOgK8u+XEY=; b=PkjOU0OwjgOja8a24OYSeB2xiCXsUcXR2DuCf4HwLICZZ6x5sUmJcWD+n6ZDvBAkTG Q+yDtygd9skAsH7t4D3HxYgI4yhnyQ4mSJt1uW+qYKr5q7Jka2QoKZll1mkxK5Ug149F fO1lUz8ciMe3jG1z4R/He3IGT7X3d09qLVq8L5fdAc+sQv1qBijTYeekmQUnBnE0KJ6y ZxPStzKKAtcEnK1FxUL6vlmqE8oH/vjbQ/iiV0qSrloeoFwlXy3KIVD5QWoGxMAmG4OW y+g3SztzbfqSiPuTK8NIqTg6b99rR+6POIH9XoXMkEZ0Bwj5wbv5fnr8W/bbql43LwpJ +Rug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Nyqdaq2S7tC0O5h+EPr9voswYlNOiiQ62YOgK8u+XEY=; b=onRpjMBBF4HRqEBlmSaNibzSz7COsuAPjn+8KM/7duv2V2aavRDQECpwzr6uPAzMNQ m3OZyoq7nycNz/UiFdYeowxLhvfSb1Wd8qqdhCXPKmKqjFzf685KfVbFIqgyPDRM6utX R4pHfEZn0GPaB8grdVV5/uPklAjPU10qmJj9XCW22Y4liAdHprwfqCuWwmwoSgdURuCB FlII50Eo2L3nOHTDdygMz8S7rkIq2yAd5+cV2tc7zmpOq3cb9IdzSy4j3HdqJgq65OAA oz7heN+OuIBa4utdlA5mkR83P3ezlnJkM0f5tfqOGjUUbdYtyRYae/oHglQfZID29nXu 4L9Q== X-Gm-Message-State: AFqh2kqRX257t2wXcArj2++vzM0+giWLTY7WdBn7Yvbfd+iJdT/eBr7a ItkRxr2I9glTjWUeo2iDBku8dZ86FpwEHA== X-Received: by 2002:a5d:494d:0:b0:268:5557:98c9 with SMTP id r13-20020a5d494d000000b00268555798c9mr14607418wrs.58.1672207480519; Tue, 27 Dec 2022 22:04:40 -0800 (PST) Received: from wedsonaf-dev.. ([81.2.152.129]) by smtp.googlemail.com with ESMTPSA id x16-20020a5d6510000000b002755e301eeasm12128867wru.100.2022.12.27.22.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Dec 2022 22:04:40 -0800 (PST) From: Wedson Almeida Filho To: rust-for-linux@vger.kernel.org Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , linux-kernel@vger.kernel.org, Wedson Almeida Filho Subject: [PATCH 7/7] rust: sync: add support for dispatching on Arc and ArcBorrow. Date: Wed, 28 Dec 2022 06:03:46 +0000 Message-Id: <20221228060346.352362-7-wedsonaf@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221228060346.352362-1-wedsonaf@gmail.com> References: <20221228060346.352362-1-wedsonaf@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 --- 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)] 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 {} +// This is to allow `Arc` to be dispatched on when `Arc` can be coerced into `Arc`. +impl, U: ?Sized> core::ops::DispatchFromDyn> for Arc {} + // SAFETY: It is safe to send `Arc` to another thread when the underlying `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 ultimately 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> {} +// 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 -- 2.34.1