From: Tamir Duberstein <tamird@kernel.org>
To: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Tamir Duberstein" <tamird@gmail.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
Tamir Duberstein <tamird@kernel.org>
Subject: [PATCH] rust: fix tests under Rust 1.89.0's `CStr` `Debug` impl
Date: Mon, 20 Oct 2025 11:27:28 -0400 [thread overview]
Message-ID: <20251020-cstr-debug-utf-8-v1-1-1933c0a6d6b9@kernel.org> (raw)
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>
next reply other threads:[~2025-10-20 15:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-20 15:27 Tamir Duberstein [this message]
2025-10-22 5:51 ` [PATCH] rust: fix tests under Rust 1.89.0's `CStr` `Debug` impl Miguel Ojeda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251020-cstr-debug-utf-8-v1-1-1933c0a6d6b9@kernel.org \
--to=tamird@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@gmail.com \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).