Skip to content

Commit 85c3536

Browse files
Fix warnings from Clippy (#336)
1 parent b2d744b commit 85c3536

File tree

19 files changed

+40
-43
lines changed

19 files changed

+40
-43
lines changed

api/build.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ fn main() {
3434
i = i,
3535
j = j,
3636
a = (0..i)
37-
.map(|idx| format!("a[{}]", idx))
37+
.map(|idx| format!("a[{idx}]"))
3838
.collect::<Vec<_>>()
3939
.join(","),
4040
b = (0..j)
41-
.map(|idx| format!("b[{}]", idx))
41+
.map(|idx| format!("b[{idx}]"))
4242
.collect::<Vec<_>>()
4343
.join(","),
4444
);
@@ -56,12 +56,11 @@ fn main() {
5656
Path::new(&out_dir).join("version_info.rs"),
5757
format!(
5858
"
59-
pub const VERSION_MAJOR: u16 = {};
60-
pub const VERSION_MINOR: u16 = {};
61-
pub const VERSION_PATCH: u16 = {};
62-
pub const VERSION_PRE: bool = {};
63-
",
64-
version_major, version_minor, version_patch, pre_release
59+
pub const VERSION_MAJOR: u16 = {version_major};
60+
pub const VERSION_MINOR: u16 = {version_minor};
61+
pub const VERSION_PATCH: u16 = {version_patch};
62+
pub const VERSION_PRE: bool = {pre_release};
63+
"
6564
),
6665
)
6766
.unwrap();

bios/stage-2/src/main.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,23 @@ fn start(disk_number: u16, partition_table_start: *const u8) -> ! {
102102
let kernel_page_size = (((kernel_len - 1) / 4096) + 1) as usize;
103103
let ramdisk_start = KERNEL_DST.wrapping_add(kernel_page_size * 4096);
104104
writeln!(screen::Writer, "Loading ramdisk...").unwrap();
105-
let ramdisk_len = match try_load_file("ramdisk", ramdisk_start, &mut fs, &mut disk, disk_buffer)
106-
{
107-
Some(s) => s,
108-
None => 0u64,
109-
};
105+
let ramdisk_len =
106+
try_load_file("ramdisk", ramdisk_start, &mut fs, &mut disk, disk_buffer).unwrap_or(0u64);
110107

111108
if ramdisk_len == 0 {
112109
writeln!(screen::Writer, "No ramdisk found, skipping.").unwrap();
113110
} else {
114111
writeln!(screen::Writer, "Loaded ramdisk at {ramdisk_start:#p}").unwrap();
115112
}
116113
let config_file_start = ramdisk_start.wrapping_add(ramdisk_len.try_into().unwrap());
117-
let config_file_len = match try_load_file(
114+
let config_file_len = try_load_file(
118115
"config.json",
119116
config_file_start,
120117
&mut fs,
121118
&mut disk,
122119
disk_buffer,
123-
) {
124-
Some(s) => s,
125-
None => 0u64,
126-
};
120+
)
121+
.unwrap_or(0);
127122

128123
let memory_map = unsafe { memory_map::query_memory_map() }.unwrap();
129124
writeln!(screen::Writer, "{memory_map:x?}").unwrap();

common/src/logger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl LockedLogger {
2727
};
2828

2929
let serial = match serial_logger_status {
30-
true => Some(Spinlock::new(SerialPort::new())),
30+
true => Some(Spinlock::new(unsafe { SerialPort::init() })),
3131
false => None,
3232
};
3333

common/src/serial.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ pub struct SerialPort {
55
}
66

77
impl SerialPort {
8-
pub fn new() -> Self {
8+
/// # Safety
9+
///
10+
/// unsafe because this function must only be called once
11+
pub unsafe fn init() -> Self {
912
let mut port = unsafe { uart_16550::SerialPort::new(0x3F8) };
1013
port.init();
1114
Self { port }

tests/test_kernels/config_file/src/bin/basic_boot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ use test_kernel_config_file::{exit_qemu, serial, QemuExitCode};
88
entry_point!(kernel_main);
99

1010
fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
11-
writeln!(serial(), "Entered kernel with boot info: {:?}", boot_info).unwrap();
11+
writeln!(serial(), "Entered kernel with boot info: {boot_info:?}").unwrap();
1212
exit_qemu(QemuExitCode::Success);
1313
}
1414

1515
/// This function is called on panic.
1616
#[panic_handler]
1717
#[cfg(not(test))]
1818
fn panic(info: &core::panic::PanicInfo) -> ! {
19-
let _ = writeln!(serial(), "PANIC: {}", info);
19+
let _ = writeln!(serial(), "PANIC: {info}");
2020
exit_qemu(QemuExitCode::Failed);
2121
}

tests/test_kernels/config_file/src/bin/basic_boot_broken_config_file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ use test_kernel_config_file::{exit_qemu, serial, QemuExitCode};
88
entry_point!(kernel_main);
99

1010
fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
11-
writeln!(serial(), "Entered kernel with boot info: {:?}", boot_info).unwrap();
11+
writeln!(serial(), "Entered kernel with boot info: {boot_info:?}").unwrap();
1212
exit_qemu(QemuExitCode::Success);
1313
}
1414

1515
/// This function is called on panic.
1616
#[panic_handler]
1717
#[cfg(not(test))]
1818
fn panic(info: &core::panic::PanicInfo) -> ! {
19-
let _ = writeln!(serial(), "PANIC: {}", info);
19+
let _ = writeln!(serial(), "PANIC: {info}");
2020
exit_qemu(QemuExitCode::Failed);
2121
}

tests/test_kernels/default_settings/src/bin/basic_boot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ use test_kernel_default_settings::{exit_qemu, serial, QemuExitCode};
88
entry_point!(kernel_main);
99

1010
fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
11-
writeln!(serial(), "Entered kernel with boot info: {:?}", boot_info).unwrap();
11+
writeln!(serial(), "Entered kernel with boot info: {boot_info:?}").unwrap();
1212
exit_qemu(QemuExitCode::Success);
1313
}
1414

1515
/// This function is called on panic.
1616
#[panic_handler]
1717
#[cfg(not(test))]
1818
fn panic(info: &core::panic::PanicInfo) -> ! {
19-
let _ = writeln!(serial(), "PANIC: {}", info);
19+
let _ = writeln!(serial(), "PANIC: {info}");
2020
exit_qemu(QemuExitCode::Failed);
2121
}

tests/test_kernels/default_settings/src/bin/check_boot_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
4545
fn panic(info: &core::panic::PanicInfo) -> ! {
4646
use core::fmt::Write;
4747

48-
let _ = writeln!(test_kernel_default_settings::serial(), "PANIC: {}", info);
48+
let _ = writeln!(test_kernel_default_settings::serial(), "PANIC: {info}");
4949
exit_qemu(QemuExitCode::Failed);
5050
}

tests/test_kernels/higher_half/src/bin/check_boot_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
4545
fn panic(info: &core::panic::PanicInfo) -> ! {
4646
use core::fmt::Write;
4747

48-
let _ = writeln!(test_kernel_higher_half::serial(), "PANIC: {}", info);
48+
let _ = writeln!(test_kernel_higher_half::serial(), "PANIC: {info}");
4949
exit_qemu(QemuExitCode::Failed);
5050
}

tests/test_kernels/higher_half/src/bin/verify_higher_half.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
3434
fn panic(info: &core::panic::PanicInfo) -> ! {
3535
use core::fmt::Write;
3636

37-
let _ = writeln!(test_kernel_higher_half::serial(), "PANIC: {}", info);
37+
let _ = writeln!(test_kernel_higher_half::serial(), "PANIC: {info}");
3838
exit_qemu(QemuExitCode::Failed);
3939
}

0 commit comments

Comments
 (0)