rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: fix tests under Rust 1.89.0's `CStr` `Debug` impl
@ 2025-10-20 15:27 Tamir Duberstein
  2025-10-22  5:51 ` Miguel Ojeda
  0 siblings, 1 reply; 2+ messages in thread
From: Tamir Duberstein @ 2025-10-20 15:27 UTC (permalink / raw)
  To: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Tamir Duberstein,
	Greg Kroah-Hartman
  Cc: linux-kernel, rust-for-linux, Tamir Duberstein

Starting with Rust 1.89.0, `<CStr as Debug>::fmt` prints UTF-8 sequences
unescaped.

Thus update our test to expect the new behavior starting with Rust
1.89.0.

Fixes: a1ec674cd709 ("rust: replace `CStr` with `core::ffi::CStr`")
Link: https://github.com/rust-lang/rust/commit/a82062055af1ecdcb7f4d3371855aae843fc0ae3
Signed-off-by: Tamir Duberstein <tamird@kernel.org>
---
Hi Miguel, please feel free to rebase this in, if easier.
---
 init/Kconfig       | 3 +++
 rust/kernel/str.rs | 6 +++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/init/Kconfig b/init/Kconfig
index cab3ad28ca49..aa29eae7f14b 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -156,6 +156,9 @@ config RUSTC_HAS_SPAN_FILE
 config RUSTC_HAS_UNNECESSARY_TRANSMUTES
 	def_bool RUSTC_VERSION >= 108800
 
+config RUSTC_HAS_CSTR_DEBUG_UTF8
+	def_bool RUSTC_VERSION >= 108900
+
 config RUSTC_HAS_FILE_WITH_NUL
 	def_bool RUSTC_VERSION >= 108900
 
diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs
index da539e1f29d4..f2d60288eced 100644
--- a/rust/kernel/str.rs
+++ b/rust/kernel/str.rs
@@ -478,7 +478,11 @@ fn test_cstr_debug() -> Result {
         let non_ascii = c"d\xe9j\xe0 vu";
         assert_eq!(format!("{non_ascii:?}"), "\"d\\xe9j\\xe0 vu\"");
         let good_bytes = c"\xf0\x9f\xa6\x80";
-        assert_eq!(format!("{good_bytes:?}"), "\"\\xf0\\x9f\\xa6\\x80\"");
+        if cfg!(CONFIG_RUSTC_HAS_CSTR_DEBUG_UTF8) {
+            assert_eq!(format!("{good_bytes:?}"), "\"🦀\"");
+        } else {
+            assert_eq!(format!("{good_bytes:?}"), "\"\\xf0\\x9f\\xa6\\x80\"");
+        }
         Ok(())
     }
 

---
base-commit: a1ec674cd709fec213acbb567e699c5f6f58cb60
change-id: 20251020-cstr-debug-utf-8-8e9c43a1b757

Best regards,
--  
Tamir Duberstein <tamird@kernel.org>


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

* Re: [PATCH] rust: fix tests under Rust 1.89.0's `CStr` `Debug` impl
  2025-10-20 15:27 [PATCH] rust: fix tests under Rust 1.89.0's `CStr` `Debug` impl Tamir Duberstein
@ 2025-10-22  5:51 ` Miguel Ojeda
  0 siblings, 0 replies; 2+ messages in thread
From: Miguel Ojeda @ 2025-10-22  5:51 UTC (permalink / raw)
  To: Tamir Duberstein
  Cc: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Tamir Duberstein,
	Greg Kroah-Hartman, linux-kernel, rust-for-linux

On Mon, Oct 20, 2025 at 5:27 PM Tamir Duberstein <tamird@kernel.org> wrote:
>
> Starting with Rust 1.89.0, `<CStr as Debug>::fmt` prints UTF-8 sequences
> unescaped.
>
> Thus update our test to expect the new behavior starting with Rust
> 1.89.0.
>
> Fixes: a1ec674cd709 ("rust: replace `CStr` with `core::ffi::CStr`")
> Link: https://github.com/rust-lang/rust/commit/a82062055af1ecdcb7f4d3371855aae843fc0ae3
> Signed-off-by: Tamir Duberstein <tamird@kernel.org>
> ---
> Hi Miguel, please feel free to rebase this in, if easier.

Thanks Tamir, yeah, I saw the test failing in my CI.

To keep things simple, I just removed that assert for the moment -- if
we care about the escaping behavior on debug formatting to the point
of testing the behavior on different Rust versions, then we can
re-introduce it.

    [ Removed assert that would now depend on the Rust version. - Miguel ]

I took the chance to take the tags we got so far too.

I appreciate that you took the time to put the link to the relevant
commit upstream (in this case, it was yourself, but still :)

Cheers,
Miguel

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

end of thread, other threads:[~2025-10-22  5:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-20 15:27 [PATCH] rust: fix tests under Rust 1.89.0's `CStr` `Debug` impl Tamir Duberstein
2025-10-22  5:51 ` 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).