Skip to content
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

Clippy Warning on get_arch_vcpu function #4

Open
hky1999 opened this issue Aug 1, 2024 · 1 comment
Open

Clippy Warning on get_arch_vcpu function #4

hky1999 opened this issue Aug 1, 2024 · 1 comment

Comments

@hky1999
Copy link
Contributor

hky1999 commented Aug 1, 2024

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
Copy link
Contributor

aarkegz commented Aug 1, 2024

It'll be fixed later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants