From bfd7497b25c413c65df524021038c3796dedd810 Mon Sep 17 00:00:00 2001 From: "Tate, Hongliang Tian" Date: Mon, 8 Aug 2022 16:02:55 -0700 Subject: [PATCH] Fix Rust format and lint issues --- Makefile | 10 ++++++---- src/kxos-frame/src/cpu.rs | 6 ++++-- src/kxos-frame/src/task/mod.rs | 1 + src/kxos-frame/src/vm/frame.rs | 5 +++++ src/kxos-frame/src/vm/pod.rs | 5 ++++- src/kxos-frame/src/vm/space.rs | 12 ++++++++++++ 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index f786b7047..88b0f5c5b 100644 --- a/Makefile +++ b/Makefile @@ -9,12 +9,14 @@ test: build @cd src && cargo test docs: - @cd src && cargo doc + @cd src && cargo doc # Build Rust docs @echo "" # Add a blank line - @cd docs && mdbook build + @cd docs && mdbook build # Build mdBook -fmt: - @cd src && cargo fmt +check: + @cd src && cargo check # Check dependency errors + @cd src && cargo fmt --check # Check Rust format issues + @cd src && cargo clippy # Check common programming mistakes clean: @cd src && cargo clean diff --git a/src/kxos-frame/src/cpu.rs b/src/kxos-frame/src/cpu.rs index 2c68e0e98..45f3c6ba2 100644 --- a/src/kxos-frame/src/cpu.rs +++ b/src/kxos-frame/src/cpu.rs @@ -81,10 +81,12 @@ impl FpRegs { /// Save the floating state given by a slice of u8. /// + /// After calling this method, the state of the instance will be considered valid. + /// + /// # Safety + /// /// It is the caller's responsibility to ensure that the source slice contains /// data that is in xsave/xrstor format. The slice must have a length of 512 bytes. - /// - /// After calling this method, the state of the instance will be considered valid. pub unsafe fn save_from_slice(&mut self, src: &[u8]) { //(&mut self.buf).copy_from_slice(src); //self.is_valid = true; diff --git a/src/kxos-frame/src/task/mod.rs b/src/kxos-frame/src/task/mod.rs index 9b93c2ce1..f22f43511 100644 --- a/src/kxos-frame/src/task/mod.rs +++ b/src/kxos-frame/src/task/mod.rs @@ -1,6 +1,7 @@ //! Tasks are the unit of code execution. mod scheduler; +#[allow(clippy::module_inception)] mod task; pub use self::scheduler::{set_scheduler, Scheduler}; diff --git a/src/kxos-frame/src/vm/frame.rs b/src/kxos-frame/src/vm/frame.rs index 2e207870a..f84ead076 100644 --- a/src/kxos-frame/src/vm/frame.rs +++ b/src/kxos-frame/src/vm/frame.rs @@ -62,6 +62,11 @@ impl VmFrameVec { todo!() } + /// Returns whether the frame collection is empty. + pub fn is_empty(&self) -> bool { + todo!() + } + /// Returns the number of bytes. /// /// This method is equivalent to `self.len() * PAGE_SIZE`. diff --git a/src/kxos-frame/src/vm/pod.rs b/src/kxos-frame/src/vm/pod.rs index d65826fa8..1216486f5 100644 --- a/src/kxos-frame/src/vm/pod.rs +++ b/src/kxos-frame/src/vm/pod.rs @@ -24,7 +24,10 @@ pub unsafe trait Pod: Copy + Sized { /// Creates a new instance of Pod type with uninitialized content. fn new_uninit() -> Self { // SAFETY. A value of `T: Pod` can have arbitrary bits. - unsafe { MaybeUninit::uninit().assume_init() } + #[allow(clippy::uninit_assumed_init)] + unsafe { + MaybeUninit::uninit().assume_init() + } } /// Creates a new instance from the given bytes. diff --git a/src/kxos-frame/src/vm/space.rs b/src/kxos-frame/src/vm/space.rs index f7d99beec..8dd54d5aa 100644 --- a/src/kxos-frame/src/vm/space.rs +++ b/src/kxos-frame/src/vm/space.rs @@ -48,6 +48,12 @@ impl VmSpace { } } +impl Default for VmSpace { + fn default() -> Self { + Self::new() + } +} + /// Options for mapping physical memory pages into a VM address space. /// See `VmSpace::map`. pub struct VmMapOptions {} @@ -93,6 +99,12 @@ impl VmMapOptions { } } +impl Default for VmMapOptions { + fn default() -> Self { + Self::new() + } +} + bitflags! { /// Virtual memory protection permissions. pub struct VmPerm: u8 {