Skip to content

Commit fece7ee

Browse files
authored
Address clippy warnings (rust-lang#2807)
Versions of clippy that come with newer toolchains report a large number of needless_borrows_for_generic_args. We can address these now so that we don't have to make these changes as part of a toolchain update.
1 parent fb08f3e commit fece7ee

File tree

24 files changed

+54
-52
lines changed

24 files changed

+54
-52
lines changed

cprover_bindings/src/goto_program/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ impl BuiltinFn {
329329
/// Converters: build symbols and expressions from Builtins
330330
impl BuiltinFn {
331331
pub fn as_symbol(&self) -> Symbol {
332-
Symbol::builtin_function(&self.to_string(), self.param_types(), self.return_type())
332+
Symbol::builtin_function(self.to_string(), self.param_types(), self.return_type())
333333
}
334334

335335
pub fn as_expr(&self) -> Expr {

kani-compiler/src/codegen_cprover_gotoc/codegen/operand.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ impl<'tcx> GotocCtx<'tcx> {
561561
}
562562

563563
let mem_place =
564-
self.symbol_table.lookup(&self.alloc_map.get(&alloc).unwrap()).unwrap().to_expr();
564+
self.symbol_table.lookup(self.alloc_map.get(&alloc).unwrap()).unwrap().to_expr();
565565
mem_place.address_of()
566566
}
567567

@@ -579,16 +579,16 @@ impl<'tcx> GotocCtx<'tcx> {
579579
// initializers. For example, for a boolean static variable, the variable will have type
580580
// CBool and the initializer will be a single byte (a one-character array) representing the
581581
// bit pattern for the boolean value.
582-
let alloc_typ_ref = self.ensure_struct(&struct_name, &struct_name, |ctx, _| {
582+
let alloc_typ_ref = self.ensure_struct(struct_name, struct_name, |ctx, _| {
583583
ctx.codegen_allocation_data(alloc)
584584
.iter()
585585
.enumerate()
586586
.map(|(i, d)| match d {
587587
AllocData::Bytes(bytes) => DatatypeComponent::field(
588-
&i.to_string(),
588+
i.to_string(),
589589
Type::unsigned_int(8).array_of(bytes.len()),
590590
),
591-
AllocData::Expr(e) => DatatypeComponent::field(&i.to_string(), e.typ().clone()),
591+
AllocData::Expr(e) => DatatypeComponent::field(i.to_string(), e.typ().clone()),
592592
})
593593
.collect()
594594
});

kani-compiler/src/codegen_cprover_gotoc/codegen/place.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,10 @@ impl<'tcx> GotocCtx<'tcx> {
268268
| ty::Param(_)
269269
| ty::Infer(_)
270270
| ty::Error(_) => unreachable!("type {parent_ty:?} does not have a field"),
271-
ty::Tuple(_) => Ok(parent_expr
272-
.member(&Self::tuple_fld_name(field.index()), &self.symbol_table)),
271+
ty::Tuple(_) => {
272+
Ok(parent_expr
273+
.member(Self::tuple_fld_name(field.index()), &self.symbol_table))
274+
}
273275
ty::Adt(def, _) if def.repr().simd() => Ok(self.codegen_simd_field(
274276
parent_expr,
275277
*field,
@@ -278,10 +280,10 @@ impl<'tcx> GotocCtx<'tcx> {
278280
// if we fall here, then we are handling either a struct or a union
279281
ty::Adt(def, _) => {
280282
let field = &def.variants().raw[0].fields[*field];
281-
Ok(parent_expr.member(&field.name.to_string(), &self.symbol_table))
283+
Ok(parent_expr.member(field.name.to_string(), &self.symbol_table))
282284
}
283285
ty::Closure(..) => {
284-
Ok(parent_expr.member(&field.index().to_string(), &self.symbol_table))
286+
Ok(parent_expr.member(field.index().to_string(), &self.symbol_table))
285287
}
286288
ty::Generator(..) => {
287289
let field_name = self.generator_field_name(field.as_usize());
@@ -299,7 +301,7 @@ impl<'tcx> GotocCtx<'tcx> {
299301
// if we fall here, then we are handling an enum
300302
TypeOrVariant::Variant(parent_var) => {
301303
let field = &parent_var.fields[*field];
302-
Ok(parent_expr.member(&field.name.to_string(), &self.symbol_table))
304+
Ok(parent_expr.member(field.name.to_string(), &self.symbol_table))
303305
}
304306
TypeOrVariant::GeneratorVariant(_var_idx) => {
305307
let field_name = self.generator_field_name(field.index());

kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ impl<'tcx> GotocCtx<'tcx> {
864864
// We need to pad to the next offset
865865
let padding_size = next_offset - current_offset;
866866
let name = format!("$pad{idx}");
867-
Some(DatatypeComponent::padding(&name, padding_size.bits()))
867+
Some(DatatypeComponent::padding(name, padding_size.bits()))
868868
} else {
869869
None
870870
}
@@ -1378,7 +1378,7 @@ impl<'tcx> GotocCtx<'tcx> {
13781378
.iter()
13791379
.map(|f| {
13801380
DatatypeComponent::field(
1381-
&f.name.to_string(),
1381+
f.name.to_string(),
13821382
ctx.codegen_ty(f.ty(ctx.tcx, subst)),
13831383
)
13841384
})
@@ -1641,7 +1641,7 @@ impl<'tcx> GotocCtx<'tcx> {
16411641
None
16421642
} else {
16431643
Some(DatatypeComponent::field(
1644-
&case.name.to_string(),
1644+
case.name.to_string(),
16451645
self.codegen_enum_case_struct(
16461646
name,
16471647
pretty_name,

kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl CodegenBackend for GotocCodegenBackend {
271271
if let MonoItem::Fn(instance) = test_fn { instance } else { continue };
272272
let metadata = gen_test_metadata(tcx, *test_desc, *instance, &base_filename);
273273
let test_model_path = &metadata.goto_file.as_ref().unwrap();
274-
std::fs::copy(&model_path, &test_model_path).expect(&format!(
274+
std::fs::copy(&model_path, test_model_path).expect(&format!(
275275
"Failed to copy {} to {}",
276276
model_path.display(),
277277
test_model_path.display()

kani-compiler/src/kani_compiler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ impl KaniCompiler {
352352
/// Write the metadata to a file
353353
fn store_metadata(&self, metadata: &KaniMetadata, filename: &Path) {
354354
debug!(?filename, "write_metadata");
355-
let out_file = File::create(&filename).unwrap();
355+
let out_file = File::create(filename).unwrap();
356356
let writer = BufWriter::new(out_file);
357357
if self.queries.lock().unwrap().args().output_pretty_json {
358358
serde_json::to_writer_pretty(writer, &metadata).unwrap();

kani-compiler/src/kani_middle/reachability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ mod debug {
725725
debug!(?target, "dump_dot");
726726
let outputs = tcx.output_filenames(());
727727
let path = outputs.output_path(OutputType::Metadata).with_extension("dot");
728-
let out_file = File::create(&path)?;
728+
let out_file = File::create(path)?;
729729
let mut writer = BufWriter::new(out_file);
730730
writeln!(writer, "digraph ReachabilityGraph {{")?;
731731
if target.is_empty() {

kani-driver/src/args/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ fn check_no_cargo_opt(is_set: bool, name: &str) -> Result<(), Error> {
427427
if is_set {
428428
Err(Error::raw(
429429
ErrorKind::UnknownArgument,
430-
&format!("argument `{}` cannot be used with standalone Kani.", name),
430+
format!("argument `{}` cannot be used with standalone Kani.", name),
431431
))
432432
} else {
433433
Ok(())
@@ -453,7 +453,7 @@ impl ValidateArgs for StandaloneArgs {
453453
if !input.is_file() {
454454
return Err(Error::raw(
455455
ErrorKind::InvalidValue,
456-
&format!(
456+
format!(
457457
"Invalid argument: Input invalid. `{}` is not a regular file.",
458458
input.display()
459459
),
@@ -583,7 +583,7 @@ impl ValidateArgs for VerificationArgs {
583583
if out_dir.exists() && !out_dir.is_dir() {
584584
return Err(Error::raw(
585585
ErrorKind::InvalidValue,
586-
&format!(
586+
format!(
587587
"Invalid argument: `--target-dir` argument `{}` is not a directory",
588588
out_dir.display()
589589
),

kani-driver/src/args/playback_args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl ValidateArgs for KaniPlaybackArgs {
7474
if !self.input.is_file() {
7575
return Err(Error::raw(
7676
ErrorKind::InvalidValue,
77-
&format!(
77+
format!(
7878
"Invalid argument: Input invalid. `{}` is not a regular file.",
7979
self.input.display()
8080
),

kani-driver/src/assess/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub struct SessionError {
8888
/// If given the argument to so do, write the assess metadata to the target file.
8989
pub(crate) fn write_metadata(args: &AssessArgs, metadata: AssessMetadata) -> Result<()> {
9090
if let Some(path) = &args.emit_metadata {
91-
let out_file = File::create(&path)?;
91+
let out_file = File::create(path)?;
9292
let writer = BufWriter::new(out_file);
9393
// use pretty for now to keep things readable and debuggable, but this should change eventually
9494
serde_json::to_writer_pretty(writer, &metadata)?;

kani-driver/src/assess/scan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ fn invoke_assess(
179179
// Additionally, this should be `--manifest-path` but `cargo kani` doesn't support that yet.
180180
cmd.arg("-p").arg(package);
181181
cmd.arg("--enable-unstable"); // This has to be after `-p` due to an argument parsing bug in kani-driver
182-
cmd.args(&["assess", "--emit-metadata"])
182+
cmd.args(["assess", "--emit-metadata"])
183183
.arg(outfile)
184184
.current_dir(dir)
185185
.stdout(log.try_clone()?)

kani-driver/src/concrete_playback/playback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn build_test(install: &InstallType, args: &KaniPlaybackArgs) -> Result<PathBuf>
8484
rustc_args.push("--error-format=json".into());
8585
}
8686

87-
let mut cmd = Command::new(&install.kani_compiler()?);
87+
let mut cmd = Command::new(install.kani_compiler()?);
8888
cmd.args(rustc_args);
8989

9090
session::run_terminal(&args.playback.common_opts, cmd)?;

kani-driver/src/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,6 @@ fn metadata_with_function(
364364
// Note: `out_dir` is already on canonical form, so no need to invoke `try_new()`.
365365
fn standalone_artifact(out_dir: &Path, crate_name: &String, typ: ArtifactType) -> Artifact {
366366
let mut path = out_dir.join(crate_name);
367-
let _ = path.set_extension(&typ);
367+
let _ = path.set_extension(typ);
368368
Artifact { path, typ }
369369
}

kani-driver/src/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pub fn run_redirect(
216216
stdout.display()
217217
);
218218
}
219-
let output_file = std::fs::File::create(&stdout)?;
219+
let output_file = std::fs::File::create(stdout)?;
220220
cmd.stdout(output_file);
221221

222222
let program = cmd.get_program().to_string_lossy().to_string();

kani_metadata/src/artifact.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn convert_type(path: &Path, from: ArtifactType, to: ArtifactType) -> PathBu
5656
match from {
5757
// Artifact types that has only one extension.
5858
ArtifactType::Goto => {
59-
result.set_extension(&to);
59+
result.set_extension(to);
6060
}
6161
// Artifact types that has two extensions.
6262
ArtifactType::Metadata
@@ -66,7 +66,7 @@ pub fn convert_type(path: &Path, from: ArtifactType, to: ArtifactType) -> PathBu
6666
| ArtifactType::VTableRestriction
6767
| ArtifactType::PrettyNameMap => {
6868
result.set_extension("");
69-
result.set_extension(&to);
69+
result.set_extension(to);
7070
}
7171
}
7272
result

src/os_hacks.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ pub fn setup_python_deps_on_ubuntu_18_04(pyroot: &Path, pkg_versions: &[&str]) -
6161

6262
// Step 1: use `--system --prefix pyroot`. This disables the broken behavior, and creates `bin` but...
6363
Command::new("python3")
64-
.args(&["-m", "pip", "install", "--system", "--prefix"])
65-
.arg(&pyroot)
64+
.args(["-m", "pip", "install", "--system", "--prefix"])
65+
.arg(pyroot)
6666
.args(pkg_versions)
6767
.run()?;
6868

@@ -128,7 +128,7 @@ fn setup_nixos_patchelf(kani_dir: &Path) -> Result<()> {
128128
// Find the correct path to link C++ stdlib:
129129
// `rpath=$(nix-instantiate --eval -E "(import <nixpkgs> {}).stdenv.cc.cc.lib.outPath")/lib`
130130
let rpath_output = Command::new("nix-instantiate")
131-
.args(&["--eval", "-E", "(import <nixpkgs> {}).stdenv.cc.cc.lib.outPath"])
131+
.args(["--eval", "-E", "(import <nixpkgs> {}).stdenv.cc.cc.lib.outPath"])
132132
.output()?;
133133
if !rpath_output.status.success() {
134134
bail!("Failed to find C++ standard library with `nix-instantiate`");
@@ -139,10 +139,10 @@ fn setup_nixos_patchelf(kani_dir: &Path) -> Result<()> {
139139
let rpath = format!("{rpath_prefix}/lib");
140140

141141
let patch_interp = |file: &Path| -> Result<()> {
142-
Command::new("patchelf").args(&["--set-interpreter", interp]).arg(file).run()
142+
Command::new("patchelf").args(["--set-interpreter", interp]).arg(file).run()
143143
};
144144
let patch_rpath = |file: &Path| -> Result<()> {
145-
Command::new("patchelf").args(&["--set-rpath", &rpath]).arg(file).run()
145+
Command::new("patchelf").args(["--set-rpath", &rpath]).arg(file).run()
146146
};
147147

148148
let bin = kani_dir.join("bin");

src/setup.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ fn setup_kani_bundle(kani_dir: &Path, use_local_bundle: Option<OsString>) -> Res
107107
.arg("--strip-components=1")
108108
.arg("-zxf")
109109
.arg(&path)
110-
.current_dir(&kani_dir)
110+
.current_dir(kani_dir)
111111
.run()
112112
.context(
113113
"Failed to extract tar file, try removing Kani setup located in .kani in your home directory and restarting",
@@ -118,7 +118,7 @@ fn setup_kani_bundle(kani_dir: &Path, use_local_bundle: Option<OsString>) -> Res
118118
fail_if_unsupported_target()?;
119119
let bundle = base_dir.join(filename);
120120
Command::new("curl")
121-
.args(&["-sSLf", "-o"])
121+
.args(["-sSLf", "-o"])
122122
.arg(&bundle)
123123
.arg(download_url())
124124
.run()
@@ -143,7 +143,7 @@ fn setup_rust_toolchain(kani_dir: &Path) -> Result<String> {
143143
// Currently this means we require the bundle to have been unpacked first!
144144
let toolchain_version = get_rust_toolchain_version(kani_dir)?;
145145
println!("[3/5] Installing rust toolchain version: {}", &toolchain_version);
146-
Command::new("rustup").args(&["toolchain", "install", &toolchain_version]).run()?;
146+
Command::new("rustup").args(["toolchain", "install", &toolchain_version]).run()?;
147147

148148
let toolchain = home::rustup_home()?.join("toolchains").join(&toolchain_version);
149149

@@ -165,7 +165,7 @@ fn setup_python_deps(kani_dir: &Path, os: &os_info::Info) -> Result<()> {
165165
}
166166

167167
Command::new("python3")
168-
.args(&["-m", "pip", "install", "--target"])
168+
.args(["-m", "pip", "install", "--target"])
169169
.arg(&pyroot)
170170
.args(pkg_versions)
171171
.run()?;

tools/bookrunner/src/books.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl Book {
8888
let summary_dir = summary_path.parent().unwrap().to_path_buf();
8989
let summary = fs::read_to_string(summary_path.clone()).unwrap();
9090
assert!(
91-
summary.starts_with(&summary_start.as_str()),
91+
summary.starts_with(summary_start.as_str()),
9292
"Error: The start of {} summary file changed.",
9393
self.name
9494
);
@@ -409,7 +409,7 @@ fn extract(
409409
config_paths: &mut HashSet<PathBuf>,
410410
default_edition: Edition,
411411
) {
412-
let code = fs::read_to_string(&par_from).unwrap();
412+
let code = fs::read_to_string(par_from).unwrap();
413413
let mut examples = Examples(Vec::new());
414414
find_testable_code(&code, &mut examples, ErrorCodes::No, false, None);
415415
for mut example in examples.0 {
@@ -514,7 +514,7 @@ fn generate_text_bookrunner(bookrunner: bookrunner::Tree, path: &Path) {
514514
bookrunner.data.num_fail,
515515
bookrunner
516516
);
517-
fs::write(&path, bookrunner_str).expect("Error: Unable to write bookrunner results");
517+
fs::write(path, bookrunner_str).expect("Error: Unable to write bookrunner results");
518518
}
519519

520520
/// Runs examples using Litani build.

tools/bookrunner/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ pub fn add_verification_job(litani: &mut Litani, test_props: &TestProps) {
206206
// Add `--function main` so we can run these without having to amend them to add `#[kani::proof]`.
207207
// Some of test_props.kani_args will contains `--cbmc-args` so we should always put that last.
208208
kani.arg(&test_props.path)
209-
.args(&["--enable-unstable", "--function", "main"])
209+
.args(["--enable-unstable", "--function", "main"])
210210
.args(&test_props.kani_args);
211211
if !test_props.rustc_args.is_empty() {
212212
kani.env("RUSTFLAGS", test_props.rustc_args.join(" "));

tools/build-kani/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn bundle_kani(dir: &Path) -> Result<()> {
8383

8484
// 2. Kani scripts
8585
let scripts = dir.join("scripts");
86-
std::fs::create_dir(&scripts)?;
86+
std::fs::create_dir(scripts)?;
8787

8888
// 3. Kani libraries
8989
let library = dir.join("library");
@@ -148,7 +148,7 @@ fn bundle_kissat(dir: &Path) -> Result<()> {
148148
/// This should include all files as `dir/<path>` in the tarball.
149149
/// e.g. `kani-1.0/bin/kani-compiler` not just `bin/kani-compiler`.
150150
fn create_release_bundle(dir: &Path, bundle: &str) -> Result<()> {
151-
Command::new("tar").args(&["zcf", bundle]).arg(dir).run()
151+
Command::new("tar").args(["zcf", bundle]).arg(dir).run()
152152
}
153153

154154
/// Helper trait to fallibly run commands

tools/build-kani/src/sysroot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fn build_kani_lib(
151151
/// Copy all the artifacts to their correct place to generate a valid sysroot.
152152
fn copy_artifacts(artifacts: &[Artifact], sysroot_lib: &Path, target: &str) -> Result<()> {
153153
// Create sysroot folder hierarchy.
154-
sysroot_lib.exists().then(|| fs::remove_dir_all(&sysroot_lib));
154+
sysroot_lib.exists().then(|| fs::remove_dir_all(sysroot_lib));
155155
let std_path = path_buf!(&sysroot_lib, "rustlib", target, "lib");
156156
fs::create_dir_all(&std_path).expect(&format!("Failed to create {std_path:?}"));
157157

tools/compiletest/src/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn extract_rendered(output: &str) -> String {
6363
String::new(),
6464
|mut output, item| {
6565
use std::fmt::Write;
66-
let _ = write!(output, "Future breakage diagnostic:\n");
66+
let _ = writeln!(output, "Future breakage diagnostic:");
6767
let s = item
6868
.diagnostic
6969
.rendered

tools/compiletest/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ fn collect_rs_tests_from_dir(
467467
// tests themselves, they race for the privilege of
468468
// creating the directories and sometimes fail randomly.
469469
let build_dir = output_relative_path(config, relative_dir_path);
470-
fs::create_dir_all(&build_dir).unwrap();
470+
fs::create_dir_all(build_dir).unwrap();
471471

472472
// Add each `.rs` file as a test, and recurse further on any
473473
// subdirectories we find, except for `aux` directories.
@@ -571,7 +571,7 @@ fn make_test_name(config: &Config, testpaths: &TestPaths) -> test::TestName {
571571
// ui/foo/bar/baz.rs
572572
let path = PathBuf::from(config.src_base.file_name().unwrap())
573573
.join(&testpaths.relative_dir)
574-
.join(&testpaths.file.file_name().unwrap());
574+
.join(testpaths.file.file_name().unwrap());
575575

576576
test::DynTestName(format!("[{}] {}", config.mode, path.display()))
577577
}

0 commit comments

Comments
 (0)