From patchwork Tue Jul 18 05:27:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 121769 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp1523510vqt; Mon, 17 Jul 2023 22:39:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlFsjIdi4KxxIsBEuz4II1dT0MN2AG68NLwFZtdylIyC8/e9ART3kijQk7MsKDvlBKI0qYww X-Received: by 2002:a05:6512:e81:b0:4fb:8802:9554 with SMTP id bi1-20020a0565120e8100b004fb88029554mr11469885lfb.6.1689658767206; Mon, 17 Jul 2023 22:39:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689658767; cv=none; d=google.com; s=arc-20160816; b=ofkQooGReFfTw+ReivejoADj4ECsRIkkKFsGUTrlMmNPVSFfI5SG2z5tnvDJMT2dnp pNM9sN3mWDreeZ0qcZp1Q8o61LcjxQVwpK2uqS5BtXVbbd/s/UYveODcxm5txNl4moV3 xPA7JIdVPpiAuMj6+yEiWo2jn1eVHUCn6UPXzQqXWlhOdl0SJ5Pt3WYOHqPnx939uMRn xb+ZfOoKFKP7ug8H6ONSevMbCS0Haaem5t3k175RSW9y7GM1kKB4I6miR4nqjrOeO0K/ kHvHNRYXAUyod57Ud2oSu2BoijCnpDfV5odIHelANw7Kev5nGiRH2dtsPCXG8ksDP6Ul o35w== 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=uV4E+c9dBmGstJYuPcH/eDtLtl6gy94kxbCUAYpiOY4=; fh=idY8ZpQobwn4LBSZ5YdQwasJlU+OywLSGnM0rkTCwe0=; b=cFQUK5Gx067FPnVGE8n4QgbRZ56iTLeZezYDIxkDOxV0TK2AluQZw+eW/Njf8UnH+T BvT4wf2Kl6xnqk79bnGeBBDHTN1ptn1wzLqSa+WQmKm9xRRY4OS+YKGcw5CPqMJMtlbH WYhSfhCg+Jf9VWqdZnXE8Qkm262iWp6qvrXa3LfftImd3Sf5JnZzL06FR41QIkv83aPy I46LqYIOD5v0/GfXuiGlwEB02ETiNkgxP4q94/a8I87bP8/HDKOhykV1DbwKNpWSoySd X36Z8xEXfT3oAi3Dpsp9zAkVDiP2/ipkiYiHru08B2pJ2kMO5BRHGWCBmIxNdEqzHHs0 Vuxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TpXWXHzo; 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=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w26-20020a056402071a00b0051e2767612esi683462edx.328.2023.07.17.22.39.02; Mon, 17 Jul 2023 22:39:27 -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=@kernel.org header.s=k20201202 header.b=TpXWXHzo; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230328AbjGRF2z (ORCPT + 99 others); Tue, 18 Jul 2023 01:28:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230379AbjGRF2t (ORCPT ); Tue, 18 Jul 2023 01:28:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E0181737; Mon, 17 Jul 2023 22:28:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EF7A16144A; Tue, 18 Jul 2023 05:28:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A18F8C433CA; Tue, 18 Jul 2023 05:28:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689658115; bh=kbTYD/XHSLwWeaw9PdvZppJ7Vxhric46YCXiOC0rb7Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TpXWXHzomibZLxv1UpxZchEbd5njAUz1GR3pxZBw4eP0lOOPTJfuprkjv9Vnx8LyS d5FL/iTrjuxUnwidjnNKZ9cUcNxX/b0Y1i9+tr6aARA2a1pZ4iesoQ/1mwpErfPg1Z Qd34M0ydPtf4LHDgpZ2riK9LG/1BosVKFvnwhJx/Dy/3N1xVvyQJmUr2bxtalrJyIs OvJShMv7iQbfmVgnljGj6YQSnEK15aKora5+xq1DVMTmUEkHf41ykTQngxzR1RuYUR uguZn3i4Gb9oJqAYCtev8R0UVnlGbQgAY+yffxfXmUPFR7jLj4WgKNpzn4kgr2PsaW iar/JX8uH3ndA== From: Miguel Ojeda To: David Gow , Brendan Higgins , Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor Cc: Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Andreas Hindborg , kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Martin Rodriguez Reboredo Subject: [PATCH v2 4/7] rust: sync: make doctests compilable/testable Date: Tue, 18 Jul 2023 07:27:49 +0200 Message-ID: <20230718052752.1045248-5-ojeda@kernel.org> In-Reply-To: <20230718052752.1045248-1-ojeda@kernel.org> References: <20230718052752.1045248-1-ojeda@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771735631545437150 X-GMAIL-MSGID: 1771735631545437150 Rust documentation tests are going to be build/run-tested with the KUnit integration added in a future patch, thus update them to make them compilable/testable so that we may start enforcing it. Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Björn Roy Baron Reviewed-by: Alice Ryhl Reviewed-by: David Gow Signed-off-by: Miguel Ojeda --- rust/kernel/sync/arc.rs | 9 +++++++-- rust/kernel/sync/lock/mutex.rs | 1 + rust/kernel/sync/lock/spinlock.rs | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs index a89843cacaad..1ecb2efab51e 100644 --- a/rust/kernel/sync/arc.rs +++ b/rust/kernel/sync/arc.rs @@ -73,6 +73,7 @@ /// assert_eq!(cloned.b, 20); /// /// // The refcount drops to zero when `cloned` goes out of scope, and the memory is freed. +/// # Ok::<(), Error>(()) /// ``` /// /// Using `Arc` as the type of `self`: @@ -98,6 +99,7 @@ /// let obj = Arc::try_new(Example { a: 10, b: 20 })?; /// obj.use_reference(); /// obj.take_over(); +/// # Ok::<(), Error>(()) /// ``` /// /// Coercion from `Arc` to `Arc`: @@ -121,6 +123,7 @@ /// /// // `coerced` has type `Arc`. /// let coerced: Arc = obj; +/// # Ok::<(), Error>(()) /// ``` pub struct Arc { ptr: NonNull>, @@ -337,7 +340,7 @@ fn from(item: Pin>) -> Self { /// # Example /// /// ``` -/// use crate::sync::{Arc, ArcBorrow}; +/// use kernel::sync::{Arc, ArcBorrow}; /// /// struct Example; /// @@ -350,12 +353,13 @@ fn from(item: Pin>) -> Self { /// /// // Assert that both `obj` and `cloned` point to the same underlying object. /// assert!(core::ptr::eq(&*obj, &*cloned)); +/// # Ok::<(), Error>(()) /// ``` /// /// Using `ArcBorrow` as the type of `self`: /// /// ``` -/// use crate::sync::{Arc, ArcBorrow}; +/// use kernel::sync::{Arc, ArcBorrow}; /// /// struct Example { /// a: u32, @@ -370,6 +374,7 @@ fn from(item: Pin>) -> Self { /// /// let obj = Arc::try_new(Example { a: 10, b: 20 })?; /// obj.as_arc_borrow().use_reference(); +/// # Ok::<(), Error>(()) /// ``` pub struct ArcBorrow<'a, T: ?Sized + 'a> { inner: NonNull>, diff --git a/rust/kernel/sync/lock/mutex.rs b/rust/kernel/sync/lock/mutex.rs index 923472f04af4..09276fedc091 100644 --- a/rust/kernel/sync/lock/mutex.rs +++ b/rust/kernel/sync/lock/mutex.rs @@ -63,6 +63,7 @@ macro_rules! new_mutex { /// assert_eq!(e.c, 10); /// assert_eq!(e.d.lock().a, 20); /// assert_eq!(e.d.lock().b, 30); +/// # Ok::<(), Error>(()) /// ``` /// /// The following example shows how to use interior mutability to modify the contents of a struct diff --git a/rust/kernel/sync/lock/spinlock.rs b/rust/kernel/sync/lock/spinlock.rs index 979b56464a4e..91eb2c9e9123 100644 --- a/rust/kernel/sync/lock/spinlock.rs +++ b/rust/kernel/sync/lock/spinlock.rs @@ -61,6 +61,7 @@ macro_rules! new_spinlock { /// assert_eq!(e.c, 10); /// assert_eq!(e.d.lock().a, 20); /// assert_eq!(e.d.lock().b, 30); +/// # Ok::<(), Error>(()) /// ``` /// /// The following example shows how to use interior mutability to modify the contents of a struct