diff --git a/crates/cargo-test-support/src/registry.rs b/crates/cargo-test-support/src/registry.rs index cf6cff8d2c2..6d3db585a34 100644 --- a/crates/cargo-test-support/src/registry.rs +++ b/crates/cargo-test-support/src/registry.rs @@ -442,7 +442,7 @@ impl Package { } else { registry_path.join(&file) }; - let prev = fs::read_to_string(&dst).unwrap_or(String::new()); + let prev = fs::read_to_string(&dst).unwrap_or_default(); t!(fs::create_dir_all(dst.parent().unwrap())); t!(fs::write(&dst, prev + &line[..] + "\n")); diff --git a/src/bin/cargo/commands/tree.rs b/src/bin/cargo/commands/tree.rs index b98ee5f7aad..9cfff98fe48 100644 --- a/src/bin/cargo/commands/tree.rs +++ b/src/bin/cargo/commands/tree.rs @@ -206,7 +206,7 @@ fn parse_edge_kinds(config: &Config, args: &ArgMatches<'_>) -> CargoResult 1 && !config.cli_unstable().multitarget { bail!("specifying multiple `--target` flags requires `-Zmultitarget`") } - if targets.len() != 0 { + if !targets.is_empty() { return Ok(targets .iter() .map(|value| Ok(CompileKind::Target(CompileTarget::new(value)?))) diff --git a/src/cargo/core/compiler/standard_lib.rs b/src/cargo/core/compiler/standard_lib.rs index 0ae0b651546..c1c7f875c65 100644 --- a/src/cargo/core/compiler/standard_lib.rs +++ b/src/cargo/core/compiler/standard_lib.rs @@ -161,7 +161,7 @@ pub fn generate_std_roots( let features = std_features.activated_features(pkg.package_id(), FeaturesFor::NormalOrDev); for kind in kinds { - let list = ret.entry(*kind).or_insert(Vec::new()); + let list = ret.entry(*kind).or_insert_with(Vec::new); list.push(interner.intern( pkg, lib, @@ -173,7 +173,7 @@ pub fn generate_std_roots( )); } } - return Ok(ret); + Ok(ret) } fn detect_sysroot_src_path(target_data: &RustcTargetData) -> CargoResult { diff --git a/src/cargo/core/compiler/unit.rs b/src/cargo/core/compiler/unit.rs index ebbba387983..84565a6517e 100644 --- a/src/cargo/core/compiler/unit.rs +++ b/src/cargo/core/compiler/unit.rs @@ -204,6 +204,6 @@ impl UnitInterner { } let item = Rc::new(item.clone()); me.cache.insert(item.clone()); - return item; + item } } diff --git a/src/cargo/core/compiler/unit_graph.rs b/src/cargo/core/compiler/unit_graph.rs index 2db9015058e..350c040abad 100644 --- a/src/cargo/core/compiler/unit_graph.rs +++ b/src/cargo/core/compiler/unit_graph.rs @@ -113,6 +113,6 @@ pub fn emit_serialized_unit_graph(root_units: &[Unit], unit_graph: &UnitGraph) - let stdout = std::io::stdout(); let mut lock = stdout.lock(); serde_json::to_writer(&mut lock, &s)?; - write!(lock, "\n")?; + writeln!(lock)?; Ok(()) } diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index c5c15a4a8b0..646708e5901 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -669,7 +669,7 @@ impl Target { .set_name(name) .set_doctest(true) .set_doc(true); - return target; + target } pub fn bin_target( @@ -684,7 +684,7 @@ impl Target { .set_name(name) .set_required_features(required_features) .set_doc(true); - return target; + target } /// Builds a `Target` corresponding to the `build = "build.rs"` entry. @@ -696,7 +696,7 @@ impl Target { .set_for_host(true) .set_benched(false) .set_tested(false); - return target; + target } pub fn metabuild_target(name: &str) -> Target { @@ -707,7 +707,7 @@ impl Target { .set_for_host(true) .set_benched(false) .set_tested(false); - return target; + target } pub fn example_target( @@ -733,7 +733,7 @@ impl Target { .set_required_features(required_features) .set_tested(false) .set_benched(false); - return target; + target } pub fn test_target( @@ -748,7 +748,7 @@ impl Target { .set_name(name) .set_required_features(required_features) .set_benched(false); - return target; + target } pub fn bench_target( @@ -763,7 +763,7 @@ impl Target { .set_name(name) .set_required_features(required_features) .set_tested(false); - return target; + target } pub fn name(&self) -> &str { diff --git a/src/cargo/core/registry.rs b/src/cargo/core/registry.rs index 5b45a4bc501..8a05b4510d6 100644 --- a/src/cargo/core/registry.rs +++ b/src/cargo/core/registry.rs @@ -622,7 +622,7 @@ fn lock( // Lock the summary's ID if possible let summary = match pair { - Some((precise, _)) => summary.override_id(precise.clone()), + Some((precise, _)) => summary.override_id(*precise), None => summary, }; summary.map_dependencies(|dep| { diff --git a/src/cargo/core/resolver/conflict_cache.rs b/src/cargo/core/resolver/conflict_cache.rs index c59e4117810..e0e64b96a5d 100644 --- a/src/cargo/core/resolver/conflict_cache.rs +++ b/src/cargo/core/resolver/conflict_cache.rs @@ -213,7 +213,7 @@ impl ConflictCache { for c in con.keys() { self.dep_from_pid - .entry(c.clone()) + .entry(*c) .or_insert_with(HashSet::new) .insert(dep.clone()); } diff --git a/src/cargo/core/resolver/encode.rs b/src/cargo/core/resolver/encode.rs index 5fb4631952f..4d711498235 100644 --- a/src/cargo/core/resolver/encode.rs +++ b/src/cargo/core/resolver/encode.rs @@ -260,7 +260,7 @@ impl EncodableResolve { let mut g = Graph::new(); for &(ref id, _) in live_pkgs.values() { - g.add(id.clone()); + g.add(*id); } for &(ref id, pkg) in live_pkgs.values() { @@ -271,7 +271,7 @@ impl EncodableResolve { for edge in deps.iter() { if let Some(to_depend_on) = lookup_id(edge) { - g.link(id.clone(), to_depend_on); + g.link(*id, to_depend_on); } } } @@ -282,7 +282,7 @@ impl EncodableResolve { if let Some(ref replace) = pkg.replace { assert!(pkg.dependencies.is_none()); if let Some(replace_id) = lookup_id(replace) { - replacements.insert(id.clone(), replace_id); + replacements.insert(*id, replace_id); } } } diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index a5c94f73fa8..b386ee7f558 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -144,7 +144,7 @@ pub fn display_error(err: &Error, shell: &mut Shell) { /// and context. pub fn display_warning_with_error(warning: &str, err: &Error, shell: &mut Shell) { drop(shell.warn(warning)); - drop(writeln!(shell.err(), "")); + drop(writeln!(shell.err())); _display_error(err, shell, false); } diff --git a/src/cargo/ops/cargo_fetch.rs b/src/cargo/ops/cargo_fetch.rs index a21c9443eb0..1e0d855d0d1 100644 --- a/src/cargo/ops/cargo_fetch.rs +++ b/src/cargo/ops/cargo_fetch.rs @@ -39,7 +39,7 @@ pub fn fetch<'a>( deps.iter().any(|d| { // If no target was specified then all dependencies are // fetched. - if options.targets.len() == 0 { + if options.targets.is_empty() { return true; } diff --git a/src/cargo/ops/cargo_output_metadata.rs b/src/cargo/ops/cargo_output_metadata.rs index d10a6a4f3c9..e6261d3a927 100644 --- a/src/cargo/ops/cargo_output_metadata.rs +++ b/src/cargo/ops/cargo_output_metadata.rs @@ -176,7 +176,7 @@ fn build_resolve_graph_r( let deps: Vec = resolve .deps(pkg_id) .filter(|(_dep_id, deps)| { - if requested_kinds == &[CompileKind::Host] { + if requested_kinds == [CompileKind::Host] { true } else { requested_kinds.iter().any(|kind| { diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 4d47bc45342..570e6f522bd 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -378,7 +378,7 @@ fn registry( token: token_config, index: index_config, } = registry_configuration(config, registry.clone())?; - let opt_index = index_config.as_ref().or(index.as_ref()); + let opt_index = index_config.as_ref().or_else(|| index.as_ref()); let sid = get_source_id(config, opt_index, registry.as_ref())?; if !sid.is_remote_registry() { bail!( diff --git a/tests/testsuite/multitarget.rs b/tests/testsuite/multitarget.rs index 1235642cb56..a72203c5779 100644 --- a/tests/testsuite/multitarget.rs +++ b/tests/testsuite/multitarget.rs @@ -35,7 +35,7 @@ fn simple_build() { .masquerade_as_nightly_cargo() .run(); - assert!(p.target_bin(&t1, "foo").is_file()); + assert!(p.target_bin(t1, "foo").is_file()); assert!(p.target_bin(&t2, "foo").is_file()); }