Rust for Linux List
 help / color / mirror / Atom feed
* [PATCH] rust: kunit: use crate-level mapping for `c_void`
@ 2025-05-26 16:24 Jesung Yang
  2025-05-26 16:32 ` Miguel Ojeda
  2025-05-27 12:06 ` Benno Lossin
  0 siblings, 2 replies; 6+ messages in thread
From: Jesung Yang @ 2025-05-26 16:24 UTC (permalink / raw)
  To: Brendan Higgins, David Gow, Rae Moar, Miguel Ojeda, Alex Gaynor,
	Boqun Feng, Gary Guo, Björn Roy Baron, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, Danilo Krummrich
  Cc: linux-kselftest, kunit-dev, rust-for-linux, linux-kernel,
	Jesung Yang

Use `kernel::ffi::c_void` instead of `core::ffi::c_void` for consistency
and to centralize abstraction.

Since `kernel::ffi::c_void` is a transparent wrapper around
`core::ffi::c_void`, both are functionally equivalent. However, using
`kernel::ffi::c_void` improves consistency across the kernel's Rust code
and provides a unified reference point in case the definition ever needs
to change, even if such a change is unlikely.

Signed-off-by: Jesung Yang <y.j3ms.n@gmail.com>
---
 rust/kernel/kunit.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/rust/kernel/kunit.rs b/rust/kernel/kunit.rs
index 81833a687b75..bd6fc712dd79 100644
--- a/rust/kernel/kunit.rs
+++ b/rust/kernel/kunit.rs
@@ -6,7 +6,8 @@
 //!
 //! Reference: <https://docs.kernel.org/dev-tools/kunit/index.html>
 
-use core::{ffi::c_void, fmt};
+use core::fmt;
+use kernel::ffi::c_void;
 
 /// Prints a KUnit error-level message.
 ///
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] rust: kunit: use crate-level mapping for `c_void`
  2025-05-26 16:24 [PATCH] rust: kunit: use crate-level mapping for `c_void` Jesung Yang
@ 2025-05-26 16:32 ` Miguel Ojeda
  2025-05-27 12:06 ` Benno Lossin
  1 sibling, 0 replies; 6+ messages in thread
From: Miguel Ojeda @ 2025-05-26 16:32 UTC (permalink / raw)
  To: Jesung Yang
  Cc: Brendan Higgins, David Gow, Rae Moar, Miguel Ojeda, Alex Gaynor,
	Boqun Feng, Gary Guo, Björn Roy Baron, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, Danilo Krummrich, linux-kselftest,
	kunit-dev, rust-for-linux, linux-kernel

On Mon, May 26, 2025 at 6:26 PM Jesung Yang <y.j3ms.n@gmail.com> wrote:
>
> Since `kernel::ffi::c_void` is a transparent wrapper around
> `core::ffi::c_void`, both are functionally equivalent. However, using

Hmm... It is not a transparent wrapper, but a reexport, right? (it is
not even a type alias, like the others in the `ffi` crate).

Other than that, the change looks fine -- thanks for the patch!

(By the way, in general, please provide the `--base` flag to
`format-patch` when possible, since that makes later on applying
commits much easier. And it usually doesn't hurt to have a "Link:" tag
to the discussion in Zulip.)

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rust: kunit: use crate-level mapping for `c_void`
  2025-05-26 16:24 [PATCH] rust: kunit: use crate-level mapping for `c_void` Jesung Yang
  2025-05-26 16:32 ` Miguel Ojeda
@ 2025-05-27 12:06 ` Benno Lossin
  2025-05-27 13:51   ` Miguel Ojeda
  2025-05-27 13:55   ` Jesung Yang
  1 sibling, 2 replies; 6+ messages in thread
From: Benno Lossin @ 2025-05-27 12:06 UTC (permalink / raw)
  To: Jesung Yang, Brendan Higgins, David Gow, Rae Moar, Miguel Ojeda,
	Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich
  Cc: linux-kselftest, kunit-dev, rust-for-linux, linux-kernel

On Mon May 26, 2025 at 6:24 PM CEST, Jesung Yang wrote:
> Use `kernel::ffi::c_void` instead of `core::ffi::c_void` for consistency
> and to centralize abstraction.
>
> Since `kernel::ffi::c_void` is a transparent wrapper around
> `core::ffi::c_void`, both are functionally equivalent. However, using
> `kernel::ffi::c_void` improves consistency across the kernel's Rust code
> and provides a unified reference point in case the definition ever needs
> to change, even if such a change is unlikely.
>
> Signed-off-by: Jesung Yang <y.j3ms.n@gmail.com>
> ---
>  rust/kernel/kunit.rs | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/rust/kernel/kunit.rs b/rust/kernel/kunit.rs
> index 81833a687b75..bd6fc712dd79 100644
> --- a/rust/kernel/kunit.rs
> +++ b/rust/kernel/kunit.rs
> @@ -6,7 +6,8 @@
>  //!
>  //! Reference: <https://docs.kernel.org/dev-tools/kunit/index.html>
>  
> -use core::{ffi::c_void, fmt};
> +use core::fmt;
> +use kernel::ffi::c_void;

We don't need to explicitly import it, as `c_void` is present in the
prelude since 3d5bef5d47c3 ("rust: add C FFI types to the prelude").

With the import removed:

Reviewed-by: Benno Lossin <lossin@kernel.org>

---
Cheers,
Benno

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rust: kunit: use crate-level mapping for `c_void`
  2025-05-27 12:06 ` Benno Lossin
@ 2025-05-27 13:51   ` Miguel Ojeda
  2025-05-27 20:38     ` Benno Lossin
  2025-05-27 13:55   ` Jesung Yang
  1 sibling, 1 reply; 6+ messages in thread
From: Miguel Ojeda @ 2025-05-27 13:51 UTC (permalink / raw)
  To: Benno Lossin
  Cc: Jesung Yang, Brendan Higgins, David Gow, Rae Moar, Miguel Ojeda,
	Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	linux-kselftest, kunit-dev, rust-for-linux, linux-kernel

On Tue, May 27, 2025 at 2:06 PM Benno Lossin <lossin@kernel.org> wrote:
>
> We don't need to explicitly import it, as `c_void` is present in the
> prelude since 3d5bef5d47c3 ("rust: add C FFI types to the prelude").

Hmm... But the prelude isn't there yet in this patch, no? i.e. our
prelude is (so far) not a "real prelude" that gets injected
automatically. So I guess you mean importing the prelude instead.

(It is imported in the KUnit series anyway, so it will llikely be
there either way)

Thanks!

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rust: kunit: use crate-level mapping for `c_void`
  2025-05-27 12:06 ` Benno Lossin
  2025-05-27 13:51   ` Miguel Ojeda
@ 2025-05-27 13:55   ` Jesung Yang
  1 sibling, 0 replies; 6+ messages in thread
From: Jesung Yang @ 2025-05-27 13:55 UTC (permalink / raw)
  To: Brendan Higgins, David Gow, Rae Moar, Miguel Ojeda, Alex Gaynor,
	Boqun Feng, Gary Guo, Björn Roy Baron, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, Danilo Krummrich
  Cc: linux-kselftest, kunit-dev, rust-for-linux, linux-kernel,
	Jesung Yang

Hi,

On Tue, May 27, 2025 at 9:06 PM Benno Lossin <lossin@kernel.org> wrote:
>
> We don't need to explicitly import it, as `c_void` is present in the
> prelude since 3d5bef5d47c3 ("rust: add C FFI types to the prelude").

The base commit of my patch is f4daa80d6be7 ("rust: compile libcore with
edition 2024 for 1.87+"), which unfortunately predates the addition of
`use crate::prelude::*`. As a result, removing `use kernel::ffi::c_void`
causes the build to fail with the following error:

```
error[E0412]: cannot find type `c_void` in this scope
  --> rust/kernel/kunit.rs:22:41
   |
22 |             &args as *const _ as *const c_void,
   |                                         ^^^^^^ not found in this scope
   |
help: consider importing one of these enums
   |
9  + use crate::prelude::c_void;
   |
9  + use core::ffi::c_void;
   |
9  + use ffi::c_void;
   |

error[E0412]: cannot find type `c_void` in this scope
  --> rust/kernel/kunit.rs:38:41
   |
38 |             &args as *const _ as *const c_void,
   |                                         ^^^^^^ not found in this scope
   |
help: consider importing one of these enums
   |
9  + use crate::prelude::c_void;
   |
9  + use core::ffi::c_void;
   |
9  + use ffi::c_void;
   |

error: aborting due to 2 previous errors
```

Starting from commit c4c0574ee33b ("rust: add `kunit_tests` to the
prelude"), we do have `use crate::prelude::*;`, so the explicit import
is no longer necessary in that context.

Thanks for pointing this out!

Best regards,
Jesung

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rust: kunit: use crate-level mapping for `c_void`
  2025-05-27 13:51   ` Miguel Ojeda
@ 2025-05-27 20:38     ` Benno Lossin
  0 siblings, 0 replies; 6+ messages in thread
From: Benno Lossin @ 2025-05-27 20:38 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Jesung Yang, Brendan Higgins, David Gow, Rae Moar, Miguel Ojeda,
	Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	linux-kselftest, kunit-dev, rust-for-linux, linux-kernel

On Tue May 27, 2025 at 3:51 PM CEST, Miguel Ojeda wrote:
> On Tue, May 27, 2025 at 2:06 PM Benno Lossin <lossin@kernel.org> wrote:
>>
>> We don't need to explicitly import it, as `c_void` is present in the
>> prelude since 3d5bef5d47c3 ("rust: add C FFI types to the prelude").
>
> Hmm... But the prelude isn't there yet in this patch, no? i.e. our
> prelude is (so far) not a "real prelude" that gets injected
> automatically. So I guess you mean importing the prelude instead.

Ah right it's only auto-imported in the doctests. Forgot that, would be
nice if it could be :)

> (It is imported in the KUnit series anyway, so it will llikely be
> there either way)

Oh yeah, it's in rust-next already :)

---
Cheers,
Benno

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-05-27 20:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-26 16:24 [PATCH] rust: kunit: use crate-level mapping for `c_void` Jesung Yang
2025-05-26 16:32 ` Miguel Ojeda
2025-05-27 12:06 ` Benno Lossin
2025-05-27 13:51   ` Miguel Ojeda
2025-05-27 20:38     ` Benno Lossin
2025-05-27 13:55   ` Jesung Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox