Skip to content

Fix warnings from Clippy #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions api/build.rs
Original file line number Diff line number Diff line change
@@ -34,11 +34,11 @@ fn main() {
i = i,
j = j,
a = (0..i)
.map(|idx| format!("a[{}]", idx))
.map(|idx| format!("a[{idx}]"))
.collect::<Vec<_>>()
.join(","),
b = (0..j)
.map(|idx| format!("b[{}]", idx))
.map(|idx| format!("b[{idx}]"))
.collect::<Vec<_>>()
.join(","),
);
@@ -56,12 +56,11 @@ fn main() {
Path::new(&out_dir).join("version_info.rs"),
format!(
"
pub const VERSION_MAJOR: u16 = {};
pub const VERSION_MINOR: u16 = {};
pub const VERSION_PATCH: u16 = {};
pub const VERSION_PRE: bool = {};
",
version_major, version_minor, version_patch, pre_release
pub const VERSION_MAJOR: u16 = {version_major};
pub const VERSION_MINOR: u16 = {version_minor};
pub const VERSION_PATCH: u16 = {version_patch};
pub const VERSION_PRE: bool = {pre_release};
"
),
)
.unwrap();
15 changes: 5 additions & 10 deletions bios/stage-2/src/main.rs
Original file line number Diff line number Diff line change
@@ -102,28 +102,23 @@ fn start(disk_number: u16, partition_table_start: *const u8) -> ! {
let kernel_page_size = (((kernel_len - 1) / 4096) + 1) as usize;
let ramdisk_start = KERNEL_DST.wrapping_add(kernel_page_size * 4096);
writeln!(screen::Writer, "Loading ramdisk...").unwrap();
let ramdisk_len = match try_load_file("ramdisk", ramdisk_start, &mut fs, &mut disk, disk_buffer)
{
Some(s) => s,
None => 0u64,
};
let ramdisk_len =
try_load_file("ramdisk", ramdisk_start, &mut fs, &mut disk, disk_buffer).unwrap_or(0u64);

if ramdisk_len == 0 {
writeln!(screen::Writer, "No ramdisk found, skipping.").unwrap();
} else {
writeln!(screen::Writer, "Loaded ramdisk at {ramdisk_start:#p}").unwrap();
}
let config_file_start = ramdisk_start.wrapping_add(ramdisk_len.try_into().unwrap());
let config_file_len = match try_load_file(
let config_file_len = try_load_file(
"config.json",
config_file_start,
&mut fs,
&mut disk,
disk_buffer,
) {
Some(s) => s,
None => 0u64,
};
)
.unwrap_or(0);

let memory_map = unsafe { memory_map::query_memory_map() }.unwrap();
writeln!(screen::Writer, "{memory_map:x?}").unwrap();
2 changes: 1 addition & 1 deletion common/src/logger.rs
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ impl LockedLogger {
};

let serial = match serial_logger_status {
true => Some(Spinlock::new(SerialPort::new())),
true => Some(Spinlock::new(unsafe { SerialPort::init() })),
false => None,
};

5 changes: 4 additions & 1 deletion common/src/serial.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,10 @@ pub struct SerialPort {
}

impl SerialPort {
pub fn new() -> Self {
/// # Safety
///
/// unsafe because this function must only be called once
pub unsafe fn init() -> Self {
let mut port = unsafe { uart_16550::SerialPort::new(0x3F8) };
port.init();
Self { port }
4 changes: 2 additions & 2 deletions tests/test_kernels/config_file/src/bin/basic_boot.rs
Original file line number Diff line number Diff line change
@@ -8,14 +8,14 @@ use test_kernel_config_file::{exit_qemu, serial, QemuExitCode};
entry_point!(kernel_main);

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

/// This function is called on panic.
#[panic_handler]
#[cfg(not(test))]
fn panic(info: &core::panic::PanicInfo) -> ! {
let _ = writeln!(serial(), "PANIC: {}", info);
let _ = writeln!(serial(), "PANIC: {info}");
exit_qemu(QemuExitCode::Failed);
}
Original file line number Diff line number Diff line change
@@ -8,14 +8,14 @@ use test_kernel_config_file::{exit_qemu, serial, QemuExitCode};
entry_point!(kernel_main);

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

/// This function is called on panic.
#[panic_handler]
#[cfg(not(test))]
fn panic(info: &core::panic::PanicInfo) -> ! {
let _ = writeln!(serial(), "PANIC: {}", info);
let _ = writeln!(serial(), "PANIC: {info}");
exit_qemu(QemuExitCode::Failed);
}
4 changes: 2 additions & 2 deletions tests/test_kernels/default_settings/src/bin/basic_boot.rs
Original file line number Diff line number Diff line change
@@ -8,14 +8,14 @@ use test_kernel_default_settings::{exit_qemu, serial, QemuExitCode};
entry_point!(kernel_main);

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

/// This function is called on panic.
#[panic_handler]
#[cfg(not(test))]
fn panic(info: &core::panic::PanicInfo) -> ! {
let _ = writeln!(serial(), "PANIC: {}", info);
let _ = writeln!(serial(), "PANIC: {info}");
exit_qemu(QemuExitCode::Failed);
}
Original file line number Diff line number Diff line change
@@ -45,6 +45,6 @@ fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
fn panic(info: &core::panic::PanicInfo) -> ! {
use core::fmt::Write;

let _ = writeln!(test_kernel_default_settings::serial(), "PANIC: {}", info);
let _ = writeln!(test_kernel_default_settings::serial(), "PANIC: {info}");
exit_qemu(QemuExitCode::Failed);
}
2 changes: 1 addition & 1 deletion tests/test_kernels/higher_half/src/bin/check_boot_info.rs
Original file line number Diff line number Diff line change
@@ -45,6 +45,6 @@ fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
fn panic(info: &core::panic::PanicInfo) -> ! {
use core::fmt::Write;

let _ = writeln!(test_kernel_higher_half::serial(), "PANIC: {}", info);
let _ = writeln!(test_kernel_higher_half::serial(), "PANIC: {info}");
exit_qemu(QemuExitCode::Failed);
}
Original file line number Diff line number Diff line change
@@ -34,6 +34,6 @@ fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
fn panic(info: &core::panic::PanicInfo) -> ! {
use core::fmt::Write;

let _ = writeln!(test_kernel_higher_half::serial(), "PANIC: {}", info);
let _ = writeln!(test_kernel_higher_half::serial(), "PANIC: {info}");
exit_qemu(QemuExitCode::Failed);
}
2 changes: 1 addition & 1 deletion tests/test_kernels/lto/src/bin/basic_boot.rs
Original file line number Diff line number Diff line change
@@ -16,6 +16,6 @@ fn kernel_main(_boot_info: &'static mut BootInfo) -> ! {
fn panic(info: &core::panic::PanicInfo) -> ! {
use core::fmt::Write;

let _ = writeln!(test_kernel_lto::serial(), "PANIC: {}", info);
let _ = writeln!(test_kernel_lto::serial(), "PANIC: {info}");
exit_qemu(QemuExitCode::Failed);
}
2 changes: 1 addition & 1 deletion tests/test_kernels/map_phys_mem/src/bin/access_phys_mem.rs
Original file line number Diff line number Diff line change
@@ -22,6 +22,6 @@ fn panic(info: &core::panic::PanicInfo) -> ! {
use core::fmt::Write;
use test_kernel_map_phys_mem::serial;

let _ = writeln!(serial(), "PANIC: {}", info);
let _ = writeln!(serial(), "PANIC: {info}");
exit_qemu(QemuExitCode::Failed);
}
2 changes: 1 addition & 1 deletion tests/test_kernels/map_phys_mem/src/bin/check_boot_info.rs
Original file line number Diff line number Diff line change
@@ -49,6 +49,6 @@ fn panic(info: &core::panic::PanicInfo) -> ! {
use core::fmt::Write;
use test_kernel_map_phys_mem::serial;

let _ = writeln!(serial(), "PANIC: {}", info);
let _ = writeln!(serial(), "PANIC: {info}");
exit_qemu(QemuExitCode::Failed);
}
2 changes: 1 addition & 1 deletion tests/test_kernels/pie/src/bin/basic_boot.rs
Original file line number Diff line number Diff line change
@@ -16,6 +16,6 @@ fn kernel_main(_boot_info: &'static mut BootInfo) -> ! {
fn panic(info: &core::panic::PanicInfo) -> ! {
use core::fmt::Write;

let _ = writeln!(test_kernel_pie::serial(), "PANIC: {}", info);
let _ = writeln!(test_kernel_pie::serial(), "PANIC: {info}");
exit_qemu(QemuExitCode::Failed);
}
2 changes: 1 addition & 1 deletion tests/test_kernels/pie/src/bin/check_boot_info.rs
Original file line number Diff line number Diff line change
@@ -45,6 +45,6 @@ fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
fn panic(info: &core::panic::PanicInfo) -> ! {
use core::fmt::Write;

let _ = writeln!(test_kernel_pie::serial(), "PANIC: {}", info);
let _ = writeln!(test_kernel_pie::serial(), "PANIC: {info}");
exit_qemu(QemuExitCode::Failed);
}
2 changes: 1 addition & 1 deletion tests/test_kernels/pie/src/bin/global_variable.rs
Original file line number Diff line number Diff line change
@@ -31,6 +31,6 @@ fn kernel_main(_boot_info: &'static mut BootInfo) -> ! {
fn panic(info: &core::panic::PanicInfo) -> ! {
use core::fmt::Write;

let _ = writeln!(test_kernel_pie::serial(), "PANIC: {}", info);
let _ = writeln!(test_kernel_pie::serial(), "PANIC: {info}");
exit_qemu(QemuExitCode::Failed);
}
2 changes: 1 addition & 1 deletion tests/test_kernels/ramdisk/src/bin/basic_boot.rs
Original file line number Diff line number Diff line change
@@ -16,6 +16,6 @@ fn kernel_main(_boot_info: &'static mut BootInfo) -> ! {
fn panic(info: &core::panic::PanicInfo) -> ! {
use core::fmt::Write;

let _ = writeln!(test_kernel_ramdisk::serial(), "PANIC: {}", info);
let _ = writeln!(test_kernel_ramdisk::serial(), "PANIC: {info}");
exit_qemu(QemuExitCode::Failed);
}
6 changes: 3 additions & 3 deletions tests/test_kernels/ramdisk/src/bin/ramdisk.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ use test_kernel_ramdisk::{exit_qemu, serial, QemuExitCode, RAMDISK_CONTENTS};
entry_point!(kernel_main);

fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
writeln!(serial(), "Boot info: {:?}", boot_info).unwrap();
writeln!(serial(), "Boot info: {boot_info:?}").unwrap();
assert!(boot_info.ramdisk_addr.into_option().is_some());
assert_eq!(boot_info.ramdisk_len as usize, RAMDISK_CONTENTS.len());
let actual_ramdisk = unsafe {
@@ -17,7 +17,7 @@ fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
boot_info.ramdisk_len as usize,
)
};
writeln!(serial(), "Actual contents: {:?}", actual_ramdisk).unwrap();
writeln!(serial(), "Actual contents: {actual_ramdisk:?}").unwrap();
assert_eq!(RAMDISK_CONTENTS, actual_ramdisk);

exit_qemu(QemuExitCode::Success);
@@ -27,6 +27,6 @@ fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
#[cfg(not(test))]
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
let _ = writeln!(test_kernel_ramdisk::serial(), "PANIC: {}", info);
let _ = writeln!(test_kernel_ramdisk::serial(), "PANIC: {info}");
exit_qemu(QemuExitCode::Failed);
}
8 changes: 4 additions & 4 deletions uefi/src/main.rs
Original file line number Diff line number Diff line change
@@ -187,8 +187,8 @@ fn main_inner(image: Handle, mut st: SystemTable<Boot>) -> Status {
.or_else(|| config_entries.find(|entry| matches!(entry.guid, cfg::ACPI_GUID)));
rsdp.map(|entry| PhysAddr::new(entry.address as u64))
},
ramdisk_addr: ramdisk_addr,
ramdisk_len: ramdisk_len,
ramdisk_addr,
ramdisk_len,
};

bootloader_x86_64_common::load_and_switch_to_kernel(
@@ -382,7 +382,7 @@ fn load_file_from_tftp_boot_server(
let filename = CStr8::from_bytes_with_nul(name.as_bytes()).unwrap();

// Determine the kernel file size.
let file_size = base_code.tftp_get_file_size(&server_ip, &filename).ok()?;
let file_size = base_code.tftp_get_file_size(&server_ip, filename).ok()?;
let kernel_size = usize::try_from(file_size).expect("The file size should fit into usize");

// Allocate some memory for the kernel file.
@@ -398,7 +398,7 @@ fn load_file_from_tftp_boot_server(

// Load the kernel file.
base_code
.tftp_read_file(&server_ip, &filename, Some(slice))
.tftp_read_file(&server_ip, filename, Some(slice))
.expect("Failed to read kernel file from the TFTP boot server");

Some(slice)