Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <davidgow@google.com>
Acked-by: Danilo Krummrich <dakr@kernel.org>
[ Split from the next commit as suggested by Tamir. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

+1 -17
+1 -17
rust/kernel/str.rs
··· 576 576 mod tests { 577 577 use super::*; 578 578 579 - struct String(CString); 580 - 581 - impl String { 582 - fn from_fmt(args: fmt::Arguments<'_>) -> Self { 583 - String(CString::try_from_fmt(args).unwrap()) 584 - } 585 - } 586 - 587 - impl Deref for String { 588 - type Target = str; 589 - 590 - fn deref(&self) -> &str { 591 - self.0.to_str().unwrap() 592 - } 593 - } 594 - 595 579 macro_rules! format { 596 580 ($($f:tt)*) => ({ 597 - &*String::from_fmt(::kernel::fmt!($($f)*)) 581 + CString::try_from_fmt(::kernel::fmt!($($f)*)).unwrap().to_str().unwrap() 598 582 }) 599 583 } 600 584