From: Miguel Ojeda Date: Mon, 26 May 2025 18:01:42 +0000 (+0200) Subject: rust: str: simplify KUnit tests `format!` macro X-Git-Tag: v6.16-rc1~45^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1486554392e242da5cbe95092d8dfec887bb8cca;p=thirdparty%2Fkernel%2Flinux.git rust: str: simplify KUnit tests `format!` macro Simplify the `format!` macro used in the tests by using `CString::try_from_fmt` and directly `unwrap()`ing. This will allow us to change both `unwrap()`s here in order to showcase the `?` operator support now that the tests are KUnit ones. Reviewed-by: David Gow Acked-by: Danilo Krummrich [ Split from the next commit as suggested by Tamir. - Miguel ] Signed-off-by: Miguel Ojeda --- diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index 9b5228025e2c6..52a500742c1a7 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -576,25 +576,9 @@ macro_rules! c_str { mod tests { use super::*; - struct String(CString); - - impl String { - fn from_fmt(args: fmt::Arguments<'_>) -> Self { - String(CString::try_from_fmt(args).unwrap()) - } - } - - impl Deref for String { - type Target = str; - - fn deref(&self) -> &str { - self.0.to_str().unwrap() - } - } - macro_rules! format { ($($f:tt)*) => ({ - &*String::from_fmt(::kernel::fmt!($($f)*)) + CString::try_from_fmt(::kernel::fmt!($($f)*)).unwrap().to_str().unwrap() }) }