Closed
Description
Summary
My code is like this:
async fn process_config(sandbox: &mut KuasarSandbox<QemuVM>) -> Result<()> {
if let Some(resources) = get_resources(&sandbox.data) {
if resources.cpu_period > 0 && resources.cpu_quota > 0 {
// get ceil of cpus if it is not integer
let base = (resources.cpu_quota as f64 / resources.cpu_period as f64).ceil();
sandbox.vm.config.smp.cpus = base as u32;
sandbox.vm.config.smp.max_cpus = base as u32;
}
if resources.memory_limit_in_bytes > 0 {
sandbox.vm.config.memory.size = format!(
"{}M",
((resources.memory_limit_in_bytes) as u64 / bytefmt::MIB) as u32
);
}
// TODO add other resource limits to vm
}
Ok(())
}
I'm running into a problem when I try to run the command: cargo clippy --all-features -- -D warnings
error: this argument is a mutable reference, but not used mutably
--> src/qemu/hooks.rs:57:34
|
57 | async fn process_config(sandbox: &mut KuasarSandbox<QemuVM>) -> Result<()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&KuasarSandbox<QemuVM>`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut
= note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`
After modifying according to the prompt:
Checking vmm-sandboxer v0.1.0 (/root/dierbei/kuasar/vmm/sandbox)
error[E0594]: cannot assign to `sandbox.vm.config.smp.cpus`, which is behind a `&` reference
--> src/qemu/hooks.rs:62:13
|
62 | sandbox.vm.config.smp.cpus = base as u32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `sandbox` is a `&` reference, so the data it refers to cannot be written
|
help: consider specifying this binding's type
|
57 | async fn process_config(sandbox: &mut sandbox::KuasarSandbox<qemu::QemuVM>: &KuasarSandbox<QemuVM>) -> Result<()> {
| +++++++++++++++++++++++++++++++++++++++++++
error[E0594]: cannot assign to `sandbox.vm.config.smp.max_cpus`, which is behind a `&` reference
--> src/qemu/hooks.rs:63:13
|
63 | sandbox.vm.config.smp.max_cpus = base as u32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `sandbox` is a `&` reference, so the data it refers to cannot be written
|
help: consider specifying this binding's type
|
57 | async fn process_config(sandbox: &mut sandbox::KuasarSandbox<qemu::QemuVM>: &KuasarSandbox<QemuVM>) -> Result<()> {
| +++++++++++++++++++++++++++++++++++++++++++
error[E0594]: cannot assign to `sandbox.vm.config.memory.size`, which is behind a `&` reference
--> src/qemu/hooks.rs:66:13
|
66 | sandbox.vm.config.memory.size = format!(
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `sandbox` is a `&` reference, so the data it refers to cannot be written
Reproducer
No response
Version
rustc 1.73.0-nightly (500647fd8 2023-07-27)
binary: rustc
commit-hash: 500647fd8138cc09e87edb08d62f81654fbf6ef8
commit-date: 2023-07-27
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5
Additional Labels
No response