[PATCH v2 02/15] rust: pin-init: allow the crate to refer to itself as `pin-init` in doc tests

Benno Lossin posted 15 patches 4 weeks ago
There is a newer version of this series
[PATCH v2 02/15] rust: pin-init: allow the crate to refer to itself as `pin-init` in doc tests
Posted by Benno Lossin 4 weeks ago
The `syn` approach requires use of `::pin_init::...` instead of the
`$crate::...` construct available to declarative macros. To be able to
use the `pin_init` crate from itself (which includes doc tests), we have
to declare it as such.

Signed-off-by: Benno Lossin <lossin@kernel.org>
---
Changes in v2: none
---
 rust/pin-init/src/lib.rs | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/rust/pin-init/src/lib.rs b/rust/pin-init/src/lib.rs
index 8673008f45d2..0e707f00061f 100644
--- a/rust/pin-init/src/lib.rs
+++ b/rust/pin-init/src/lib.rs
@@ -290,6 +290,11 @@
     ptr::{self, NonNull},
 };
 
+// This is used by doc-tests -- the proc-macros expand to `::pin_init::...` and without this the
+// doc-tests wouldn't have an extern crate named `pin_init`.
+#[allow(unused_extern_crates)]
+extern crate self as pin_init;
+
 #[doc(hidden)]
 pub mod __internal;
 #[doc(hidden)]
-- 
2.52.0
Re: [PATCH v2 02/15] rust: pin-init: allow the crate to refer to itself as `pin-init` in doc tests
Posted by Gary Guo 3 weeks, 6 days ago
On Sun Jan 11, 2026 at 12:25 PM GMT, Benno Lossin wrote:
> The `syn` approach requires use of `::pin_init::...` instead of the
> `$crate::...` construct available to declarative macros. To be able to
> use the `pin_init` crate from itself (which includes doc tests), we have
> to declare it as such.
> 
> Signed-off-by: Benno Lossin <lossin@kernel.org>

Reviewed-by: Gary Guo <gary@garyguo.net>

> ---
> Changes in v2: none
> ---
>  rust/pin-init/src/lib.rs | 5 +++++
>  1 file changed, 5 insertions(+)