init/Kconfig | 3 +++ rust/kernel/str.rs | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-)
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>
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
© 2016 - 2026 Red Hat, Inc.