Rust 1.65: Fix clippy borrow_deref_ref, needless_borrow, and explicit_auto_deref lints

BUG=b:260784028
TEST=tools/clippy

Change-Id: I85cd5e096bc7b977fe1d9b231c08338b65e71780
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4064714
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Daniel Verkamp 2022-11-29 16:51:12 -08:00 committed by crosvm LUCI
parent 9f06dcbe16
commit dfe9869d6c
32 changed files with 58 additions and 60 deletions

View file

@ -101,7 +101,8 @@ impl Tube {
let mut msg_descriptors_full = [0; TUBE_MAX_FDS];
let (msg_json_size, descriptor_size) = (&self.socket)
let (msg_json_size, descriptor_size) = self
.socket
.recv_with_fds(IoSliceMut::new(&mut msg_json), &mut msg_descriptors_full)
.map_err(Error::Send)?;

View file

@ -26,7 +26,7 @@ fn compile_policies(out_dir: &Path, rewrote_policy_folder: &Path, compile_seccom
let compiled_policy_folder = out_dir.join("policy_output");
fs::create_dir_all(&compiled_policy_folder).unwrap();
let mut include_all_bytes = String::from("std::collections::HashMap::from([\n");
for entry in fs::read_dir(&rewrote_policy_folder).unwrap() {
for entry in fs::read_dir(rewrote_policy_folder).unwrap() {
let policy_file = entry.unwrap();
if policy_file.path().extension().unwrap() == "policy" {
let output_file_path = compiled_policy_folder.join(

View file

@ -841,7 +841,7 @@ mod test {
s1.send(data1).await.expect("failed to send data");
let recv_data = s2.recv_as_vec().await.expect("failed to recv data");
assert_eq!(&recv_data, &*data1);
assert_eq!(&recv_data, data1);
})
.unwrap();
}

View file

@ -282,7 +282,7 @@ impl FdtWriter {
pub fn property_array_u32(&mut self, name: &str, cells: &[u32]) -> Result<()> {
let mut arr = Vec::with_capacity(cells.len() * size_of::<u32>());
for &c in cells {
arr.extend(&c.to_be_bytes());
arr.extend(c.to_be_bytes());
}
self.property(name, &arr)
}
@ -291,7 +291,7 @@ impl FdtWriter {
pub fn property_array_u64(&mut self, name: &str, cells: &[u64]) -> Result<()> {
let mut arr = Vec::with_capacity(cells.len() * size_of::<u64>());
for &c in cells {
arr.extend(&c.to_be_bytes());
arr.extend(c.to_be_bytes());
}
self.property(name, &arr)
}

View file

@ -308,7 +308,7 @@ impl crosvm {
}
fn get_id_allocator(&self) -> &IdAllocator {
&*self.id_allocator
&self.id_allocator
}
fn main_transaction(

View file

@ -91,7 +91,7 @@ impl IrqChip for KvmKernelIrqChip {
routes.push(route);
self.vm.set_gsi_routing(&*routes)
self.vm.set_gsi_routing(&routes)
}
/// Replace all irq routes with the supplied routes
@ -99,7 +99,7 @@ impl IrqChip for KvmKernelIrqChip {
let mut current_routes = self.routes.lock();
*current_routes = routes.to_vec();
self.vm.set_gsi_routing(&*current_routes)
self.vm.set_gsi_routing(&current_routes)
}
/// Return a vector of all registered irq numbers and their associated events and event

View file

@ -457,7 +457,7 @@ impl IrqChip for KvmSplitIrqChip {
let mut msi_routes = routes.clone();
msi_routes.retain(|r| matches!(r.source, IrqSource::Msi { .. }));
self.vm.set_gsi_routing(&*msi_routes)
self.vm.set_gsi_routing(&msi_routes)
}
/// Replace all irq routes with the supplied routes
@ -469,7 +469,7 @@ impl IrqChip for KvmSplitIrqChip {
let mut msi_routes = routes.to_vec();
msi_routes.retain(|r| matches!(r.source, IrqSource::Msi { .. }));
self.vm.set_gsi_routing(&*msi_routes)
self.vm.set_gsi_routing(&msi_routes)
}
/// Return a vector of all registered irq numbers and their associated events and event

View file

@ -369,7 +369,7 @@ impl PciDevice for Ac97Dev {
}
fn write_config_register(&mut self, reg_idx: usize, offset: u64, data: &[u8]) {
(&mut self.config_regs).write_reg(reg_idx, offset, data)
self.config_regs.write_reg(reg_idx, offset, data)
}
fn keep_rds(&self) -> Vec<RawDescriptor> {

View file

@ -1582,7 +1582,7 @@ impl PciDevice for CoIommuDev {
self.mmap();
}
(&mut self.config_regs).write_reg(reg_idx, offset, data);
self.config_regs.write_reg(reg_idx, offset, data);
}
fn keep_rds(&self) -> Vec<RawDescriptor> {

View file

@ -762,7 +762,7 @@ mod tests {
}
fn write_config_register(&mut self, reg_idx: usize, offset: u64, data: &[u8]) {
(&mut self.config_regs).write_reg(reg_idx, offset, data)
self.config_regs.write_reg(reg_idx, offset, data)
}
fn read_bar(&mut self, _addr: u64, _data: &mut [u8]) {}

View file

@ -60,7 +60,7 @@ impl PciDevice for PciRootConfiguration {
}
fn write_config_register(&mut self, reg_idx: usize, offset: u64, data: &[u8]) {
(&mut self.config).write_reg(reg_idx, offset, data)
self.config.write_reg(reg_idx, offset, data)
}
fn read_bar(&mut self, _addr: u64, _data: &mut [u8]) {}

View file

@ -347,7 +347,7 @@ impl PciDevice for PciBridge {
self.device.lock().write_config(reg_idx, offset, data);
(&mut self.config).write_reg(reg_idx, offset, data)
self.config.write_reg(reg_idx, offset, data)
}
fn read_bar(&mut self, _addr: u64, _data: &mut [u8]) {}

View file

@ -192,7 +192,7 @@ impl PciDevice for StubPciDevice {
}
fn write_config_register(&mut self, reg_idx: usize, offset: u64, data: &[u8]) {
(&mut self.config_regs).write_reg(reg_idx, offset, data)
self.config_regs.write_reg(reg_idx, offset, data)
}
fn read_bar(&mut self, _addr: u64, _data: &mut [u8]) {}

View file

@ -234,7 +234,7 @@ impl VfioPlatformDevice {
Ok(v) => v,
Err(_e) => break,
};
let host = (&mmap).as_ptr() as u64;
let host = mmap.as_ptr() as u64;
// Safe because the given guest_map_start is valid guest bar address. and
// the host pointer is correct and valid guaranteed by MemoryMapping interface.
match unsafe {

View file

@ -285,7 +285,7 @@ impl PciDevice for XhciController {
}
fn write_config_register(&mut self, reg_idx: usize, offset: u64, data: &[u8]) {
(&mut self.config_regs).write_reg(reg_idx, offset, data)
self.config_regs.write_reg(reg_idx, offset, data)
}
fn read_bar(&mut self, addr: u64, data: &mut [u8]) {

View file

@ -767,7 +767,7 @@ impl VfioDevice {
container: Arc<Mutex<VfioContainer>>,
iommu_enabled: bool,
) -> Result<Self> {
let group_id = VfioGroup::get_group_id(&sysfspath)?;
let group_id = VfioGroup::get_group_id(sysfspath)?;
let group = container
.lock()
@ -802,7 +802,7 @@ impl VfioDevice {
sysfspath: &P,
container: Arc<Mutex<VfioContainer>>,
) -> Result<Self> {
let group_id = VfioGroup::get_group_id(&sysfspath)?;
let group_id = VfioGroup::get_group_id(sysfspath)?;
let group = container.lock().get_group(group_id)?;
let name_osstr = sysfspath
.as_ref()

View file

@ -167,7 +167,7 @@ pub fn process_fs_queue<I: SignalableInterrupt, F: FileSystem + Sync>(
let total = server.handle_message(reader, writer, &mapper)?;
queue.add_used(mem, avail_desc.index, total as u32);
queue.trigger_interrupt(mem, &*interrupt);
queue.trigger_interrupt(mem, interrupt);
}
Ok(())

View file

@ -364,7 +364,7 @@ impl VioSClient {
sequence: sequence.into(),
};
let control_socket_lock = self.control_socket.lock();
send_cmd(&*control_socket_lock, msg)
send_cmd(&control_socket_lock, msg)
}
/// Configures a stream with the given parameters.
@ -374,7 +374,7 @@ impl VioSClient {
.ok_or(Error::InvalidStreamId(stream_id))?;
let raw_params: virtio_snd_pcm_set_params = (stream_id, params).into();
let control_socket_lock = self.control_socket.lock();
send_cmd(&*control_socket_lock, raw_params)
send_cmd(&control_socket_lock, raw_params)
}
/// Configures a stream with the given parameters.
@ -384,7 +384,7 @@ impl VioSClient {
.get(stream_id as usize)
.ok_or(Error::InvalidStreamId(stream_id))?;
let control_socket_lock = self.control_socket.lock();
send_cmd(&*control_socket_lock, raw_params)
send_cmd(&control_socket_lock, raw_params)
}
/// Send the PREPARE_STREAM command to the server.
@ -486,7 +486,7 @@ impl VioSClient {
stream_id: stream_id.into(),
};
let control_socket_lock = self.control_socket.lock();
send_cmd(&*control_socket_lock, msg)
send_cmd(&control_socket_lock, msg)
}
fn request_and_cache_info(&mut self) -> Result<()> {
@ -512,7 +512,7 @@ impl VioSClient {
size: (std::mem::size_of::<virtio_snd_query_info>() as u32).into(),
};
let control_socket_lock = self.control_socket.lock();
seq_socket_send(&*control_socket_lock, req)?;
seq_socket_send(&control_socket_lock, req)?;
let reply = control_socket_lock
.recv_as_vec()
.map_err(Error::ServerIOError)?;

View file

@ -199,7 +199,7 @@ impl VhostUserBackend for SndBackend {
ex,
&mem,
&streams,
&*snd_data,
&snd_data,
&mut queue,
&mut kick_evt,
doorbell,
@ -228,7 +228,7 @@ impl VhostUserBackend for SndBackend {
let streams = Rc::clone(&self.streams);
ex.spawn_local(Abortable::new(
async move {
handle_pcm_queue(&*mem, &streams, send, &queue, &kick_evt, None).await
handle_pcm_queue(&mem, &streams, send, &queue, &kick_evt, None).await
},
registration,
))
@ -238,7 +238,7 @@ impl VhostUserBackend for SndBackend {
ex.spawn_local(Abortable::new(
async move {
send_pcm_response_worker(&*mem2, &queue2, doorbell, &mut recv, None).await
send_pcm_response_worker(&mem2, &queue2, doorbell, &mut recv, None).await
},
registration2,
))

View file

@ -250,7 +250,7 @@ impl EncoderSession for FfmpegEncoderSession {
let buffer_id = self.next_input_buffer_id;
self.next_input_buffer_id = buffer_id.wrapping_add(1);
let mut frame: AvFrame = (&resource)
let mut frame: AvFrame = resource
.try_as_av_frame(|mapping| InputBuffer {
mapping,
buffer_id,

View file

@ -155,15 +155,13 @@ pub fn build_config(backend: VideoBackendType) -> virtio_video_config {
let mut device_name = [0u8; 32];
match backend {
#[cfg(feature = "libvda")]
VideoBackendType::Libvda => (&mut device_name[0..6]).copy_from_slice("libvda".as_bytes()),
VideoBackendType::Libvda => device_name[0..6].copy_from_slice("libvda".as_bytes()),
#[cfg(feature = "libvda")]
VideoBackendType::LibvdaVd => {
(&mut device_name[0..8]).copy_from_slice("libvdavd".as_bytes())
}
VideoBackendType::LibvdaVd => device_name[0..8].copy_from_slice("libvdavd".as_bytes()),
#[cfg(feature = "ffmpeg")]
VideoBackendType::Ffmpeg => (&mut device_name[0..6]).copy_from_slice("ffmpeg".as_bytes()),
VideoBackendType::Ffmpeg => device_name[0..6].copy_from_slice("ffmpeg".as_bytes()),
#[cfg(feature = "vaapi")]
VideoBackendType::Vaapi => (&mut device_name[0..5]).copy_from_slice("vaapi".as_bytes()),
VideoBackendType::Vaapi => device_name[0..5].copy_from_slice("vaapi".as_bytes()),
};
virtio_video_config {
version: Le32::from(0),

View file

@ -785,7 +785,7 @@ impl PciDevice for VirtioPciDevice {
}
}
(&mut self.config_regs).write_reg(reg_idx, offset, data)
self.config_regs.write_reg(reg_idx, offset, data)
}
fn read_bar(&mut self, addr: u64, data: &mut [u8]) {

View file

@ -1233,8 +1233,7 @@ impl WlState {
match self.vfds.entry(id) {
Entry::Vacant(entry) => {
let vfd = entry.insert(WlVfd::connect(
&self
.wayland_paths
self.wayland_paths
.get(name)
.ok_or_else(|| WlError::UnknownSocketName(name.to_string()))?,
)?);

View file

@ -62,7 +62,7 @@ pub struct VhostUserBackend {
impl VhostUserBackend {
pub fn new(cfg: Config) -> Result<Self> {
let mut cmd = Command::new(find_crosvm_binary());
cmd.args(&[cfg.cmd_type.to_subcommand()]);
cmd.args([cfg.cmd_type.to_subcommand()]);
cmd.args(cfg.extra_args);
cmd.stdout(Stdio::piped());

View file

@ -124,7 +124,7 @@ fn download_file(url: &str, destination: &Path) -> Result<()> {
let status = Command::new("curl")
.arg("--fail")
.arg("--location")
.args(&["--output", destination.to_str().unwrap()])
.args(["--output", destination.to_str().unwrap()])
.arg(url)
.status();
match status {
@ -255,7 +255,7 @@ impl TestVm {
from_guest_pipe: &Path,
to_guest_pipe: &Path,
) {
command.args(&["--serial", "type=syslog"]);
command.args(["--serial", "type=syslog"]);
// Setup channel for communication with the delegate.
let serial_params = format!(
@ -263,7 +263,7 @@ impl TestVm {
from_guest_pipe.display(),
to_guest_pipe.display()
);
command.args(&["--serial", &serial_params]);
command.args(["--serial", &serial_params]);
}
/// Configures the VM rootfs to load from the guest_under_test assets.
@ -274,8 +274,8 @@ impl TestVm {
if o_direct { ",direct=true" } else { "" }
);
command
.args(&["--block", &rootfs_and_option])
.args(&["--params", "init=/bin/delegate"]);
.args(["--block", &rootfs_and_option])
.args(["--params", "init=/bin/delegate"]);
}
/// Instanciate a new crosvm instance. The first call will trigger the download of prebuilt
@ -299,7 +299,7 @@ impl TestVm {
let control_socket_path = test_dir.path().join(CONTROL_PIPE);
let mut command = Command::new(find_crosvm_binary());
command.args(&["run"]);
command.args(["run"]);
f(&mut command, test_dir.path(), &cfg)?;
@ -357,7 +357,7 @@ impl TestVm {
&test_dir.join(FROM_GUEST_PIPE),
&test_dir.join(TO_GUEST_PIPE),
);
command.args(&["--socket", test_dir.join(CONTROL_PIPE).to_str().unwrap()]);
command.args(["--socket", test_dir.join(CONTROL_PIPE).to_str().unwrap()]);
TestVm::configure_rootfs(command, cfg.o_direct);
// Set kernel as the last argument.
command.arg(kernel_path());
@ -418,7 +418,7 @@ impl TestVm {
TestVm::new_generic(
|command, test_dir, cfg| {
let config_file_path = TestVm::generate_json_config_file(test_dir, cfg)?;
command.args(&["--cfg", config_file_path.to_str().unwrap()]);
command.args(["--cfg", config_file_path.to_str().unwrap()]);
Ok(())
},

View file

@ -67,7 +67,7 @@ pub type Result<T> = std::result::Result<T, Error>;
impl Error {
pub fn sys_error(&self) -> SysError {
match &*self {
match self {
Error::CreateSocket(e) => *e,
Error::OpenTun(e) => *e,
Error::CreateTap(e) => *e,

View file

@ -10,7 +10,7 @@ pub(crate) fn download_command(url: &str, destination: &Path) -> Command {
cmd.arg("--fail")
.arg("--location")
.arg("--silent")
.args(&["--output", destination.to_str().unwrap()])
.args(["--output", destination.to_str().unwrap()])
.arg(url);
cmd
}

View file

@ -46,7 +46,7 @@ pub fn build_protos_explicit(
file.to_str().expect("proto path must be UTF-8")
);
}
fs::create_dir_all(&out_dir).unwrap();
fs::create_dir_all(out_dir).unwrap();
gen_protos(out_dir, proto_paths, includes);
create_gen_file(out_dir, proto_paths);
}

View file

@ -607,7 +607,7 @@ pub fn run_config(cfg: Config) -> Result<()> {
// jail.mount_dev() here because crosvm may not be running with CAP_SYS_ADMIN.
let device_names = ["full", "null", "urandom", "zero"];
for name in &device_names {
let device = Path::new("/dev").join(&name);
let device = Path::new("/dev").join(name);
jail.mount_bind(&device, &device, true)
.context("failed to mount dev")?;
}

View file

@ -291,7 +291,7 @@ fn create_composite(cmd: cmdline::CreateCompositeCommand) -> std::result::Result
.read(true)
.write(true)
.truncate(true)
.open(&composite_image_path)
.open(composite_image_path)
.map_err(|e| {
error!(
"Failed opening composite disk image file at '{}': {}",

View file

@ -68,14 +68,14 @@ fn build_plugin(src: &str) -> RemovePath {
PLUGIN_NUM.fetch_add(1, Ordering::Relaxed)
));
let mut child = Command::new(var_os("CC").unwrap_or(OsString::from("cc")))
.args(&["-Icrosvm_plugin", "-pthread", "-o"]) // crosvm.h location and set output path.
.args(["-Icrosvm_plugin", "-pthread", "-o"]) // crosvm.h location and set output path.
.arg(&out_bin)
.arg("-L") // Path of shared object to link to.
.arg(&libcrosvm_plugin_dir)
.arg("-Wl,-rpath") // Search for shared object in the same path when exec'd.
.arg(&libcrosvm_plugin_dir)
.args(&["-Wl,-rpath", "."]) // Also check current directory in case of sandboxing.
.args(&["-xc", "-"]) // Read source code from piped stdin.
.args(["-Wl,-rpath", "."]) // Also check current directory in case of sandboxing.
.args(["-xc", "-"]) // Read source code from piped stdin.
.arg("-lcrosvm_plugin")
.stdin(Stdio::piped())
.spawn()
@ -95,7 +95,7 @@ fn run_plugin(bin_path: &Path, with_sandbox: bool) {
let mut crosvm_path = get_crosvm_path();
crosvm_path.push("crosvm");
let mut cmd = Command::new(crosvm_path);
cmd.args(&[
cmd.args([
"run",
"-c",
"1",
@ -110,7 +110,7 @@ fn run_plugin(bin_path: &Path, with_sandbox: bool) {
);
if *TAP_AVAILABLE {
cmd.args(&[
cmd.args([
"--host-ip",
"100.115.92.5",
"--netmask",
@ -165,7 +165,7 @@ fn build_assembly(src: &str) -> Vec<u8> {
// which we have preserved accross exec.
let status = Command::new("nasm")
.arg(format!("/proc/self/fd/{}", in_file.as_raw_descriptor()))
.args(&["-f", "bin", "-o"])
.args(["-f", "bin", "-o"])
.arg(format!("/proc/self/fd/{}", out_file.as_raw_descriptor()))
.status()
.expect("failed to spawn assembler");

View file

@ -451,7 +451,7 @@ impl<S: VhostUserMasterReqHandler> MasterReqHandler<S> {
let def_err = libc::EINVAL;
let val = match res {
Ok(n) => *n,
Err(e) => match &*e {
Err(e) => match e {
Error::ReqHandlerError(ioerr) => match ioerr.raw_os_error() {
Some(rawerr) => -rawerr as u64,
None => -def_err as u64,