mirror of https://github.com/torvalds/linux.git
rust: use `kernel::{fmt,prelude::fmt!}`
Reduce coupling to implementation details of the formatting machinery by avoiding direct use for `core`'s formatting traits and macros. Signed-off-by: Tamir Duberstein <tamird@gmail.com> Reviewed-by: Benno Lossin <lossin@kernel.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20250704-core-cstr-prepare-v1-3-a91524037783@gmail.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
parent
bda947d613
commit
386f285d88
|
|
@ -6,10 +6,10 @@
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
alloc::{layout::LayoutError, AllocError},
|
alloc::{layout::LayoutError, AllocError},
|
||||||
|
fmt,
|
||||||
str::CStr,
|
str::CStr,
|
||||||
};
|
};
|
||||||
|
|
||||||
use core::fmt;
|
|
||||||
use core::num::NonZeroI32;
|
use core::num::NonZeroI32;
|
||||||
use core::num::TryFromIntError;
|
use core::num::TryFromIntError;
|
||||||
use core::str::Utf8Error;
|
use core::str::Utf8Error;
|
||||||
|
|
@ -219,8 +219,8 @@ fn from(_: LayoutError) -> Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<core::fmt::Error> for Error {
|
impl From<fmt::Error> for Error {
|
||||||
fn from(_: core::fmt::Error) -> Error {
|
fn from(_: fmt::Error) -> Error {
|
||||||
code::EINVAL
|
code::EINVAL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ffi::{c_char, c_void},
|
ffi::{c_char, c_void},
|
||||||
|
fmt,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
str::RawFormatter,
|
str::RawFormatter,
|
||||||
};
|
};
|
||||||
use core::fmt;
|
|
||||||
|
|
||||||
// Called from `vsprintf` with format specifier `%pA`.
|
// Called from `vsprintf` with format specifier `%pA`.
|
||||||
#[expect(clippy::missing_safety_doc)]
|
#[expect(clippy::missing_safety_doc)]
|
||||||
|
|
@ -149,7 +149,7 @@ macro_rules! print_macro (
|
||||||
// takes borrows on the arguments, but does not extend the scope of temporaries.
|
// takes borrows on the arguments, but does not extend the scope of temporaries.
|
||||||
// Therefore, a `match` expression is used to keep them around, since
|
// Therefore, a `match` expression is used to keep them around, since
|
||||||
// the scrutinee is kept until the end of the `match`.
|
// the scrutinee is kept until the end of the `match`.
|
||||||
match format_args!($($arg)+) {
|
match $crate::prelude::fmt!($($arg)+) {
|
||||||
// SAFETY: This hidden macro should only be called by the documented
|
// SAFETY: This hidden macro should only be called by the documented
|
||||||
// printing macros which ensure the format string is one of the fixed
|
// printing macros which ensure the format string is one of the fixed
|
||||||
// ones. All `__LOG_PREFIX`s are null-terminated as they are generated
|
// ones. All `__LOG_PREFIX`s are null-terminated as they are generated
|
||||||
|
|
@ -168,7 +168,7 @@ macro_rules! print_macro (
|
||||||
// The `CONT` case.
|
// The `CONT` case.
|
||||||
($format_string:path, true, $($arg:tt)+) => (
|
($format_string:path, true, $($arg:tt)+) => (
|
||||||
$crate::print::call_printk_cont(
|
$crate::print::call_printk_cont(
|
||||||
format_args!($($arg)+),
|
$crate::prelude::fmt!($($arg)+),
|
||||||
);
|
);
|
||||||
);
|
);
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
//! String representations.
|
//! String representations.
|
||||||
|
|
||||||
use crate::alloc::{flags::*, AllocError, KVec};
|
use crate::alloc::{flags::*, AllocError, KVec};
|
||||||
use core::fmt::{self, Write};
|
use crate::fmt::{self, Write};
|
||||||
use core::ops::{self, Deref, DerefMut, Index};
|
use core::ops::{self, Deref, DerefMut, Index};
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ fn arc_print() -> Result {
|
||||||
// behaviour, contract or protocol on both `i32` and `&str` into a single `Arc` of
|
// behaviour, contract or protocol on both `i32` and `&str` into a single `Arc` of
|
||||||
// type `Arc<dyn Display>`.
|
// type `Arc<dyn Display>`.
|
||||||
|
|
||||||
use core::fmt::Display;
|
use kernel::fmt::Display;
|
||||||
fn arc_dyn_print(arc: &Arc<dyn Display>) {
|
fn arc_dyn_print(arc: &Arc<dyn Display>) {
|
||||||
pr_info!("Arc<dyn Display> says {arc}");
|
pr_info!("Arc<dyn Display> says {arc}");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue