arceos-hypervisor / axvcpu

Apache License 2.0
1 stars 2 forks source link

Clippy Warning on `get_arch_vcpu` function #4

Open hky1999 opened 1 month ago

hky1999 commented 1 month ago

There is a clippy waring exiss in vcpu's get_arch_vcpu function.

    /// Get the architecture-specific vcpu.
    pub fn get_arch_vcpu(&self) -> &mut A {
        unsafe { &mut *self.arch_vcpu.get() }
    }

Warning:

➜  axvcpu git:(ci) cargo clippy --all-features
    Checking axvcpu v0.1.0 (/home/hky/workspace/arceos/arceos-crates/axvcpu)
error: mutable borrow from immutable input(s)
   --> src/vcpu.rs:188:36
    |
188 |     pub fn get_arch_vcpu(&self) -> &mut A {
    |                                    ^^^^^^
    |
note: immutable borrow here
   --> src/vcpu.rs:188:26
    |
188 |     pub fn get_arch_vcpu(&self) -> &mut A {
    |                          ^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mut_from_ref
    = note: `#[deny(clippy::mut_from_ref)]` on by default

warning: unsafe function's docs miss `# Safety` section
   --> src/vcpu.rs:250:1
    |
250 | pub unsafe fn set_current_vcpu<A: AxArchVCpu>(vcpu: &AxVCpu<A>) {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_safety_doc
    = note: `#[warn(clippy::missing_safety_doc)]` on by default

warning: `axvcpu` (lib) generated 1 warning
error: could not compile `axvcpu` (lib) due to 1 previous error; 1 warning emitted
__vsc_update_cwd:printf:1: write error: interrupt                                                                                                                                           
➜  axvcpu git:(ci) ✗

Indeed, get mutable borrow from immutable input is not a good coding style, but this design is related to inter mutability.

I use #[allow(clippy::mut_from_ref)] to decorate this function to bypass this warning for now.

aarkegz commented 1 month ago

It'll be fixed later.