Skip to content

Commit f08c853

Browse files
authored
Merge pull request #2180 from hermit-os/format-args
fix: tag all format-like macros with `#[clippy::format_args]`
2 parents f094840 + 25af164 commit f08c853

File tree

6 files changed

+34
-28
lines changed

6 files changed

+34
-28
lines changed

hermit-macro/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use proc_macro::TokenStream;
22
use quote::ToTokens;
33
use syn::parse_macro_input;
44

5+
#[clippy::format_args]
56
macro_rules! bail {
67
($span:expr, $($tt:tt)*) => {
78
return Err(syn::Error::new_spanned($span, format!($($tt)*)))

src/arch/aarch64/kernel/processor.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,10 @@ pub fn print_information() {
331331
let fdt = env::fdt().unwrap();
332332
let cpu0 = fdt.cpus().next().unwrap();
333333
let cpu0_compatible = cpu0.property("compatible").unwrap().as_str().unwrap();
334+
let cpu_freq = &*CPU_FREQUENCY;
334335

335336
infoheader!(" CPU INFORMATION ");
336-
infoentry!("Processor compatibility", cpu0_compatible);
337-
infoentry!("Counter frequency", *CPU_FREQUENCY);
337+
infoentry!("Processor compatibility", "{cpu0_compatible}");
338+
infoentry!("Counter frequency", "{cpu_freq}");
338339
infofooter!();
339340
}

src/arch/x86_64/kernel/apic.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -995,14 +995,13 @@ fn local_apic_write(x2apic_msr: u32, value: u64) {
995995

996996
pub fn print_information() {
997997
infoheader!(" MULTIPROCESSOR INFORMATION ");
998-
infoentry!(
999-
"APIC in use",
1000-
if processor::supports_x2apic() {
1001-
"x2APIC"
1002-
} else {
1003-
"xAPIC"
1004-
}
1005-
);
1006-
infoentry!("Initialized CPUs", arch::get_processor_count());
998+
let apic = if processor::supports_x2apic() {
999+
"x2APIC"
1000+
} else {
1001+
"xAPIC"
1002+
};
1003+
infoentry!("APIC in use", "{apic}");
1004+
let processor_count = arch::get_processor_count();
1005+
infoentry!("Initialized CPUs", "{processor_count}");
10071006
infofooter!();
10081007
}

src/arch/x86_64/kernel/processor.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -944,23 +944,24 @@ pub fn print_information() {
944944
let feature_printer = CpuFeaturePrinter::new(&cpuid);
945945

946946
if let Some(brand_string) = cpuid.get_processor_brand_string() {
947-
infoentry!("Model", brand_string.as_str());
947+
let brand_string = brand_string.as_str();
948+
infoentry!("Model", "{brand_string}");
948949
}
949950

950-
infoentry!("Frequency", *CPU_FREQUENCY);
951-
infoentry!("SpeedStep Technology", FEATURES.cpu_speedstep);
952-
953-
infoentry!("Features", feature_printer);
954-
infoentry!(
955-
"Physical Address Width",
956-
"{} bits",
957-
get_physical_address_bits()
958-
);
959-
infoentry!("Linear Address Width", "{} bits", get_linear_address_bits());
960-
infoentry!(
961-
"Supports 1GiB Pages",
962-
if supports_1gib_pages() { "Yes" } else { "No" }
963-
);
951+
let cpu_freq = &*CPU_FREQUENCY;
952+
let speedstep = &FEATURES.cpu_speedstep;
953+
infoentry!("Frequency", "{cpu_freq}");
954+
infoentry!("SpeedStep Technology", "{speedstep}");
955+
956+
infoentry!("Features", "{feature_printer}");
957+
958+
let phys_addr_bits = get_physical_address_bits();
959+
let virt_addr_bits = get_linear_address_bits();
960+
let size_1gib_pages = if supports_1gib_pages() { "Yes" } else { "No" };
961+
infoentry!("Physical Address Width", "{phys_addr_bits} bits");
962+
infoentry!("Linear Address Width", "{virt_addr_bits} bits");
963+
infoentry!("Supports 1GiB Pages", "{size_1gib_pages}");
964+
964965
infofooter!();
965966
}
966967

src/logging.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ macro_rules! infoheader {
147147
}
148148

149149
#[cfg_attr(target_arch = "riscv64", allow(unused))]
150+
#[clippy::format_args]
150151
macro_rules! infoentry {
151-
($str:expr, $rhs:expr) => (infoentry!($str, "{}", $rhs));
152152
($str:expr, $($arg:tt)+) => (::log::info!("{:25}{}", concat!($str, ":"), format_args!($($arg)+)));
153153
}
154154

src/macros.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/// [`std::print`]: https://doc.rust-lang.org/stable/std/macro.print.html
66
#[cfg(target_os = "none")]
77
#[macro_export]
8+
#[clippy::format_args]
89
macro_rules! print {
910
($($arg:tt)*) => {{
1011
$crate::console::_print(::core::format_args!($($arg)*));
@@ -18,18 +19,20 @@ macro_rules! print {
1819
/// [`std::println`]: https://doc.rust-lang.org/stable/std/macro.println.html
1920
#[cfg(target_os = "none")]
2021
#[macro_export]
22+
#[clippy::format_args]
2123
macro_rules! println {
2224
() => {
2325
$crate::print!("\n")
2426
};
2527
($($arg:tt)*) => {{
26-
$crate::console::_print(::core::format_args!("{}\n", format_args!($($arg)*)));
28+
$crate::console::_print(::core::format_args!("{}\n", ::core::format_args!($($arg)*)));
2729
}};
2830
}
2931

3032
/// Emergency output.
3133
#[cfg(target_os = "none")]
3234
#[macro_export]
35+
#[clippy::format_args]
3336
macro_rules! panic_println {
3437
() => {{
3538
$crate::console::_panic_print(::core::format_args!("\n"));
@@ -41,6 +44,7 @@ macro_rules! panic_println {
4144

4245
#[cfg(not(target_os = "none"))]
4346
#[macro_export]
47+
#[clippy::format_args]
4448
macro_rules! panic_println {
4549
($($arg:tt)*) => {
4650
println!($($arg)*);

0 commit comments

Comments
 (0)