linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: use the new name Location::file_as_c_str() in rustc 1.91.0+
@ 2025-08-27 13:12 Alice Ryhl
  2025-08-27 14:56 ` Boqun Feng
  2025-08-31 21:39 ` Miguel Ojeda
  0 siblings, 2 replies; 4+ messages in thread
From: Alice Ryhl @ 2025-08-27 13:12 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Danilo Krummrich, linux-kernel,
	rust-for-linux, Alice Ryhl

As part of the stabilization of Location::file_with_nul(), it was
brought up that the with_nul() suffix usually means something else in
Rust APIs, so the API is being renamed prior to stabilization. Thus,
adjust Linux to use the new name on new rustc versions.

Link: https://www.github.com/rust-lang/rust/pull/145928 [1]
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
This hasn't been merged upstream yet. It shouldn't be merged until that
happens.
---
 init/Kconfig       |  3 +++
 rust/kernel/lib.rs | 15 +++++++++------
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/init/Kconfig b/init/Kconfig
index 83632025121937527523f5977a493bd3ae24ed9f..e7459cbea6ca800e56a1e54423e399b689557885 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -145,6 +145,9 @@ config RUSTC_HAS_UNNECESSARY_TRANSMUTES
 config RUSTC_HAS_FILE_WITH_NUL
 	def_bool RUSTC_VERSION >= 108900
 
+config RUSTC_HAS_FILE_AS_C_STR
+	def_bool RUSTC_VERSION >= 109100
+
 config PAHOLE_VERSION
 	int
 	default $(shell,$(srctree)/scripts/pahole-version.sh $(PAHOLE))
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index ed53169e795c0badf548025a57f946fa18bc73e3..604069b1bd5c373d2ad8419872a358a8d01d0bb5 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -296,7 +296,7 @@ macro_rules! asm {
 
 /// Gets the C string file name of a [`Location`].
 ///
-/// If `file_with_nul()` is not available, returns a string that warns about it.
+/// If `Location::file_as_c_str()` is not available, returns a string that warns about it.
 ///
 /// [`Location`]: core::panic::Location
 ///
@@ -310,8 +310,8 @@ macro_rules! asm {
 ///     let caller = core::panic::Location::caller();
 ///
 ///     // Output:
-///     // - A path like "rust/kernel/example.rs" if file_with_nul() is available.
-///     // - "<Location::file_with_nul() not supported>" otherwise.
+///     // - A path like "rust/kernel/example.rs" if `file_as_c_str()` is available.
+///     // - "<Location::file_as_c_str() not supported>" otherwise.
 ///     let caller_file = file_from_location(caller);
 ///
 ///     // Prints out the message with caller's file name.
@@ -326,14 +326,17 @@ macro_rules! asm {
 /// ```
 #[inline]
 pub fn file_from_location<'a>(loc: &'a core::panic::Location<'a>) -> &'a core::ffi::CStr {
-    #[cfg(CONFIG_RUSTC_HAS_FILE_WITH_NUL)]
+    #[cfg(CONFIG_RUSTC_HAS_FILE_AS_C_STR)]
+    {
+        loc.file_as_c_str()
+    }
+    #[cfg(all(CONFIG_RUSTC_HAS_FILE_WITH_NUL, not(CONFIG_RUSTC_HAS_FILE_AS_C_STR)))]
     {
         loc.file_with_nul()
     }
-
     #[cfg(not(CONFIG_RUSTC_HAS_FILE_WITH_NUL))]
     {
         let _ = loc;
-        c"<Location::file_with_nul() not supported>"
+        c"<Location::file_as_c_str() not supported>"
     }
 }

---
base-commit: c17b750b3ad9f45f2b6f7e6f7f4679844244f0b9
change-id: 20250827-file_as_c_str-b4d4eca4ce40

Best regards,
-- 
Alice Ryhl <aliceryhl@google.com>


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

* Re: [PATCH] rust: use the new name Location::file_as_c_str() in rustc 1.91.0+
  2025-08-27 13:12 [PATCH] rust: use the new name Location::file_as_c_str() in rustc 1.91.0+ Alice Ryhl
@ 2025-08-27 14:56 ` Boqun Feng
  2025-08-29  8:36   ` Alice Ryhl
  2025-08-31 21:39 ` Miguel Ojeda
  1 sibling, 1 reply; 4+ messages in thread
From: Boqun Feng @ 2025-08-27 14:56 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: Miguel Ojeda, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Danilo Krummrich, linux-kernel,
	rust-for-linux

On Wed, Aug 27, 2025 at 01:12:16PM +0000, Alice Ryhl wrote:
> As part of the stabilization of Location::file_with_nul(), it was
> brought up that the with_nul() suffix usually means something else in
> Rust APIs, so the API is being renamed prior to stabilization. Thus,
> adjust Linux to use the new name on new rustc versions.
> 
> Link: https://www.github.com/rust-lang/rust/pull/145928 [1]
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>

Thanks for doing this!

Reviewed-by: Boqun Feng <boqun.feng@gmail.com>

> ---
> This hasn't been merged upstream yet. It shouldn't be merged until that
> happens.

Let me know when it gets upstreamed, I'm happy to do a test then.

Regards,
Boqun

> ---
>  init/Kconfig       |  3 +++
>  rust/kernel/lib.rs | 15 +++++++++------
>  2 files changed, 12 insertions(+), 6 deletions(-)
[...]

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

* Re: [PATCH] rust: use the new name Location::file_as_c_str() in rustc 1.91.0+
  2025-08-27 14:56 ` Boqun Feng
@ 2025-08-29  8:36   ` Alice Ryhl
  0 siblings, 0 replies; 4+ messages in thread
From: Alice Ryhl @ 2025-08-29  8:36 UTC (permalink / raw)
  To: Boqun Feng
  Cc: Miguel Ojeda, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Danilo Krummrich, linux-kernel,
	rust-for-linux

On Wed, Aug 27, 2025 at 07:56:35AM -0700, Boqun Feng wrote:
> On Wed, Aug 27, 2025 at 01:12:16PM +0000, Alice Ryhl wrote:
> > As part of the stabilization of Location::file_with_nul(), it was
> > brought up that the with_nul() suffix usually means something else in
> > Rust APIs, so the API is being renamed prior to stabilization. Thus,
> > adjust Linux to use the new name on new rustc versions.
> > 
> > Link: https://www.github.com/rust-lang/rust/pull/145928 [1]
> > Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> 
> Thanks for doing this!
> 
> Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
> 
> > ---
> > This hasn't been merged upstream yet. It shouldn't be merged until that
> > happens.
> 
> Let me know when it gets upstreamed, I'm happy to do a test then.

The PR just landed.

Alice

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

* Re: [PATCH] rust: use the new name Location::file_as_c_str() in rustc 1.91.0+
  2025-08-27 13:12 [PATCH] rust: use the new name Location::file_as_c_str() in rustc 1.91.0+ Alice Ryhl
  2025-08-27 14:56 ` Boqun Feng
@ 2025-08-31 21:39 ` Miguel Ojeda
  1 sibling, 0 replies; 4+ messages in thread
From: Miguel Ojeda @ 2025-08-31 21:39 UTC (permalink / raw)
  To: Alice Ryhl
  Cc: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich,
	linux-kernel, rust-for-linux

On Wed, Aug 27, 2025 at 3:12 PM Alice Ryhl <aliceryhl@google.com> wrote:
>
> As part of the stabilization of Location::file_with_nul(), it was
> brought up that the with_nul() suffix usually means something else in
> Rust APIs, so the API is being renamed prior to stabilization. Thus,
> adjust Linux to use the new name on new rustc versions.
>
> Link: https://www.github.com/rust-lang/rust/pull/145928 [1]
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>

Applied to `rust-fixes` -- thanks everyone!

    [ Kept `cfg` separation. Reworded slightly. - Miguel ]

Cheers,
Miguel

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

end of thread, other threads:[~2025-08-31 21:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-27 13:12 [PATCH] rust: use the new name Location::file_as_c_str() in rustc 1.91.0+ Alice Ryhl
2025-08-27 14:56 ` Boqun Feng
2025-08-29  8:36   ` Alice Ryhl
2025-08-31 21:39 ` Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).