Remove unnecessary borrows and dereferences
Newer versions of clippy warn about these unnecessary things, so make
the updates now in preparation for a future toolchain upgrade.
BUG=None
TEST=cargo xtask check && cargo xtask qemu
Change-Id: I96054c1715ff1778eaa560526769d16e1ccd1f8d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crdyboot/+/4000569
Commit-Queue: Nicholas Bishop <nicholasbishop@google.com>
Reviewed-by: Esther Shimanovich <eshimanovich@google.com>
Tested-by: Nicholas Bishop <nicholasbishop@google.com>
diff --git a/crdyboot/build.rs b/crdyboot/build.rs
index 46438af..330177e 100644
--- a/crdyboot/build.rs
+++ b/crdyboot/build.rs
@@ -30,5 +30,5 @@
let dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let out_path = dir.join("sbat_section.rs");
- fs::write(&out_path, &code).unwrap();
+ fs::write(out_path, code).unwrap();
}
diff --git a/vboot/src/disk.rs b/vboot/src/disk.rs
index fab66f3..3b75e57 100644
--- a/vboot/src/disk.rs
+++ b/vboot/src/disk.rs
@@ -272,7 +272,7 @@
if num_blocks > stream.remaining_blocks {
error!(
"stream read requested too many blocks: {num_blocks} > {}",
- (*stream).remaining_blocks
+ stream.remaining_blocks
);
return ReturnCode::VB2_ERROR_UNKNOWN;
}
diff --git a/xtask/src/gen_disk.rs b/xtask/src/gen_disk.rs
index 56a9bca..b634de2 100644
--- a/xtask/src/gen_disk.rs
+++ b/xtask/src/gen_disk.rs
@@ -28,11 +28,11 @@
fn create_empty_file_with_size(path: &Utf8Path, size: &str) -> Result<()> {
// Delete the file if it already exists.
if path.exists() {
- fs::remove_file(&path)?;
+ fs::remove_file(path)?;
}
// Generate empty image.
- Command::with_args("truncate", &["--size", size, path.as_str()]).run()?;
+ Command::with_args("truncate", ["--size", size, path.as_str()]).run()?;
Ok(())
}
@@ -457,7 +457,7 @@
// Get the kernel command line and write it to a file.
let output = Command::with_args(
futility,
- &[
+ [
"vbutil_kernel",
"--verify",
unsigned_kernel_partition.as_str(),
@@ -473,7 +473,7 @@
// Extract vmlinuz.
Command::with_args(
futility,
- &[
+ [
"vbutil_kernel",
"--get-vmlinuz",
unsigned_kernel_partition.as_str(),
@@ -488,7 +488,7 @@
// Sign it.
#[rustfmt::skip]
- Command::with_args(futility, &["vbutil_kernel",
+ Command::with_args(futility, ["vbutil_kernel",
"--pack", signed_kernel_partition.as_str(),
"--keyblock", kernel_data_key.keyblock.as_ref().unwrap().as_str(),
"--signprivate", kernel_data_key.vbprivk.as_str(),
@@ -501,7 +501,7 @@
// Verify it.
Command::with_args(
futility,
- &[
+ [
"vbutil_kernel",
"--verify",
signed_kernel_partition.as_str(),
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index c5c739f..ac2d1ba 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -147,17 +147,17 @@
fn run_cargo_deny() -> Result<()> {
// Check if cargo-deny is installed, and install it if not.
- if Command::with_args("cargo", &["deny", "--version"])
+ if Command::with_args("cargo", ["deny", "--version"])
.enable_capture()
.run()
.is_err()
{
- Command::with_args("cargo", &["install", "--locked", "cargo-deny"])
+ Command::with_args("cargo", ["install", "--locked", "cargo-deny"])
.run()?;
}
// Run cargo-deny. This uses the config in `.deny.toml`.
- Command::with_args("cargo", &["deny", "check"]).run()?;
+ Command::with_args("cargo", ["deny", "check"]).run()?;
Ok(())
}
@@ -176,7 +176,7 @@
for target in Arch::all_targets() {
let mut cmd = Command::with_args(
"cargo",
- &[
+ [
"build",
"--package",
package.name(),
@@ -209,7 +209,7 @@
Command::with_args(
"llvm-objcopy",
- &[
+ [
"--add-section",
&format!("{section_name}={vbpubk_path}"),
"--set-section-flags",
@@ -252,18 +252,18 @@
pub fn update_local_repo(path: &Utf8Path, url: &str, rev: &str) -> Result<()> {
// Clone repo if not already cloned, otherwise just fetch.
if path.exists() {
- Command::with_args("git", &["-C", path.as_str(), "fetch"]).run()?;
+ Command::with_args("git", ["-C", path.as_str(), "fetch"]).run()?;
} else {
- Command::with_args("git", &["clone", url, path.as_str()]).run()?;
+ Command::with_args("git", ["clone", url, path.as_str()]).run()?;
}
// Check out a known-working commit.
- Command::with_args("git", &["-C", path.as_str(), "checkout", rev]).run()?;
+ Command::with_args("git", ["-C", path.as_str(), "checkout", rev]).run()?;
// Init/update submodules.
Command::with_args(
"git",
- &["-C", path.as_str(), "submodule", "update", "--init"],
+ ["-C", path.as_str(), "submodule", "update", "--init"],
)
.run()?;
@@ -290,9 +290,9 @@
}
fn run_rustfmt(action: &FormatAction) -> Result<()> {
- let mut cmd = Command::with_args("cargo", &["fmt", "--all"]);
+ let mut cmd = Command::with_args("cargo", ["fmt", "--all"]);
if action.check {
- cmd.add_args(&["--", "--check"]);
+ cmd.add_args(["--", "--check"]);
}
cmd.run()?;
@@ -309,14 +309,14 @@
fn run_clippy_for_package(package: Package) -> Result<()> {
let mut cmd =
- Command::with_args("cargo", &["clippy", "--package", package.name()]);
+ Command::with_args("cargo", ["clippy", "--package", package.name()]);
// Use a UEFI target for everything but xtask. This gives slightly
// better coverage (for example, third_party/malloc.rs is not
// included on the host target), and is required in newer versions
// of uefi-rs due to `eh_personality` no longer being set.
if package != Package::Xtask {
- cmd.add_args(&[
+ cmd.add_args([
"-Zbuild-std=core,compiler_builtins,alloc",
"-Zbuild-std-features=compiler-builtins-mem",
"--target",
@@ -344,7 +344,7 @@
cmd.env
.insert("MIRIFLAGS".into(), "-Zmiri-tag-raw-pointers".into());
}
- cmd.add_args(&["test", "--package", package.name()]);
+ cmd.add_args(["test", "--package", package.name()]);
cmd.run()?;
Ok(())
@@ -382,7 +382,7 @@
fn init_submodules(conf: &Config) -> Result<()> {
Command::with_args(
"git",
- &[
+ [
"-C",
conf.repo_path().as_str(),
"submodule",
@@ -430,7 +430,7 @@
fn clean_futility_build(conf: &Config) -> Result<()> {
Command::with_args(
"make",
- &["-C", conf.vboot_reference_path().as_str(), "clean"],
+ ["-C", conf.vboot_reference_path().as_str(), "clean"],
)
.run()?;
@@ -442,7 +442,7 @@
fn build_futility(conf: &Config) -> Result<()> {
let mut cmd = Command::with_args(
"make",
- &[
+ [
"-C",
conf.vboot_reference_path().as_str(),
"USE_FLASHROM=0",
@@ -503,7 +503,7 @@
}
fn run_writedisk(conf: &Config) -> Result<()> {
- Command::with_args("writedisk", &[conf.disk_path()]).run()?;
+ Command::with_args("writedisk", [conf.disk_path()]).run()?;
Ok(())
}
diff --git a/xtask/src/qemu.rs b/xtask/src/qemu.rs
index 6bc512c..db9f471 100644
--- a/xtask/src/qemu.rs
+++ b/xtask/src/qemu.rs
@@ -91,39 +91,39 @@
let mut cmd = Command::new("qemu-system-x86_64");
cmd.add_arg("-enable-kvm");
cmd.add_arg("-nodefaults");
- cmd.add_args(&["-vga", "virtio"]);
- cmd.add_args(&["-serial", "stdio"]);
- cmd.add_args(&["-display", display.as_arg_str()]);
+ cmd.add_args(["-vga", "virtio"]);
+ cmd.add_args(["-serial", "stdio"]);
+ cmd.add_args(["-display", display.as_arg_str()]);
// Give it a small but reasonable amount of memory (the
// default of 128M is too small).
- cmd.add_args(&["-m", "1G"]);
+ cmd.add_args(["-m", "1G"]);
// These options are needed for SMM as described in
// edk2/OvmfPkg/README.
- cmd.add_args(&["-machine", "q35,smm=on,accel=kvm"]);
- cmd.add_args(&["-global", "ICH9-LPC.disable_s3=1"]);
+ cmd.add_args(["-machine", "q35,smm=on,accel=kvm"]);
+ cmd.add_args(["-global", "ICH9-LPC.disable_s3=1"]);
// Send OVMF debug logging to a file.
- cmd.add_args(&[
+ cmd.add_args([
"-debugcon",
&format!("file:{}", self.ovmf.qemu_log()),
"-global",
"isa-debugcon.iobase=0x402",
]);
- cmd.add_args(&[
+ cmd.add_args([
"-global",
"driver=cfi.pflash01,property=secure,value=on",
]);
- cmd.add_args(&[
+ cmd.add_args([
"-drive",
&format!(
"if=pflash,format=raw,unit=0,readonly=on,file={}",
self.ovmf.code()
),
]);
- cmd.add_args(&[
+ cmd.add_args([
"-drive",
&format!(
"if=pflash,format=raw,unit=1,readonly={},file={}",
@@ -151,7 +151,7 @@
) -> Result<()> {
let mut cmd = self.create_command(var_access, display);
- cmd.add_args(&["-drive", &format!("format=raw,file={image_path}")]);
+ cmd.add_args(["-drive", &format!("format=raw,file={image_path}")]);
cmd.run()?;
Ok(())
diff --git a/xtask/src/secure_boot.rs b/xtask/src/secure_boot.rs
index b3d6677..0ab0bbb 100644
--- a/xtask/src/secure_boot.rs
+++ b/xtask/src/secure_boot.rs
@@ -57,7 +57,7 @@
}
#[rustfmt::skip]
- Command::with_args("openssl", &[
+ Command::with_args("openssl", [
"req", "-x509",
"-newkey", "rsa:2048",
"-keyout", paths.priv_pem().as_str(),
@@ -94,12 +94,12 @@
// to Rust at some point...
Command::with_args(
"cert-to-efi-sig-list",
- &[paths.pub_pem().as_str(), unsigned_var.as_str()],
+ [paths.pub_pem().as_str(), unsigned_var.as_str()],
)
.run()?;
#[rustfmt::skip]
- Command::with_args("sign-efi-sig-list", &[
+ Command::with_args("sign-efi-sig-list", [
"-k", paths.priv_pem().as_str(),
"-c", paths.pub_pem().as_str(),
// The var name is used to pick the appropriate vendor GUID
@@ -115,7 +115,7 @@
fn convert_pem_to_der(input: &Utf8Path, output: &Utf8Path) -> Result<()> {
#[rustfmt::skip]
- Command::with_args("openssl", &[
+ Command::with_args("openssl", [
"x509",
"-outform", "der",
"-in", input.as_str(),
@@ -133,7 +133,7 @@
key_paths: &SecureBootKeyPaths,
) -> Result<()> {
#[rustfmt::skip]
- Command::with_args("sbsign", &[
+ Command::with_args("sbsign", [
"--key", key_paths.priv_pem().as_str(),
"--cert", key_paths.pub_pem().as_str(),
src.as_str(),
diff --git a/xtask/src/shim.rs b/xtask/src/shim.rs
index cf8d087..643f454 100644
--- a/xtask/src/shim.rs
+++ b/xtask/src/shim.rs
@@ -20,7 +20,7 @@
// modification below doesn't keep inserting the same change,
// and so that the checked-out revision can be changed without
// conflicts.
- Command::with_args("git", &["-C", shim_dir.as_str(), "checkout", "-f"])
+ Command::with_args("git", ["-C", shim_dir.as_str(), "checkout", "-f"])
.run()?;
}
@@ -45,10 +45,10 @@
let new_dockerfile = orig_dockerfile.replace(orig_str, &new_str);
fs::write(&dockerfile_path, new_dockerfile)?;
- Command::with_args("make", &["build"])
+ Command::with_args("make", ["build"])
.set_dir(&shim_dir)
.run()?;
- Command::with_args("make", &["copy"])
+ Command::with_args("make", ["copy"])
.set_dir(&shim_dir)
.run()?;
diff --git a/xtask/src/vboot.rs b/xtask/src/vboot.rs
index 41244d0..2405a8e 100644
--- a/xtask/src/vboot.rs
+++ b/xtask/src/vboot.rs
@@ -35,7 +35,7 @@
// Use clang to get an AST in JSON.
let output = Command::with_args(
"clang",
- &["-Xclang", "-ast-dump=json", "-fsyntax-only"],
+ ["-Xclang", "-ast-dump=json", "-fsyntax-only"],
)
.add_arg(header_path)
.enable_capture()