clippy fixes

This commit is contained in:
Matthias Krüger 2020-05-01 00:48:38 +02:00
parent 258c89644c
commit 6694fdb677
16 changed files with 25 additions and 25 deletions

View File

@ -442,7 +442,7 @@ impl Package {
} else { } else {
registry_path.join(&file) 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::create_dir_all(dst.parent().unwrap()));
t!(fs::write(&dst, prev + &line[..] + "\n")); t!(fs::write(&dst, prev + &line[..] + "\n"));

View File

@ -206,7 +206,7 @@ fn parse_edge_kinds(config: &Config, args: &ArgMatches<'_>) -> CargoResult<HashS
.warn("the --no-dev-dependencies flag has changed to -e=no-dev")?; .warn("the --no-dev-dependencies flag has changed to -e=no-dev")?;
kinds.push("no-dev"); kinds.push("no-dev");
} }
if kinds.len() == 0 { if kinds.is_empty() {
kinds.extend(&["normal", "build", "dev"]); kinds.extend(&["normal", "build", "dev"]);
} }

View File

@ -448,7 +448,7 @@ fn env_args(
// This means that, e.g., even if the specified --target is the // This means that, e.g., even if the specified --target is the
// same as the host, build scripts in plugins won't get // same as the host, build scripts in plugins won't get
// RUSTFLAGS. // RUSTFLAGS.
if requested_kinds != &[CompileKind::Host] && kind.is_host() { if requested_kinds != [CompileKind::Host] && kind.is_host() {
// This is probably a build script or plugin and we're // This is probably a build script or plugin and we're
// compiling with --target. In this scenario there are // compiling with --target. In this scenario there are
// no rustflags we can apply. // no rustflags we can apply.

View File

@ -55,7 +55,7 @@ impl CompileKind {
if targets.len() > 1 && !config.cli_unstable().multitarget { if targets.len() > 1 && !config.cli_unstable().multitarget {
bail!("specifying multiple `--target` flags requires `-Zmultitarget`") bail!("specifying multiple `--target` flags requires `-Zmultitarget`")
} }
if targets.len() != 0 { if !targets.is_empty() {
return Ok(targets return Ok(targets
.iter() .iter()
.map(|value| Ok(CompileKind::Target(CompileTarget::new(value)?))) .map(|value| Ok(CompileKind::Target(CompileTarget::new(value)?)))

View File

@ -161,7 +161,7 @@ pub fn generate_std_roots(
let features = std_features.activated_features(pkg.package_id(), FeaturesFor::NormalOrDev); let features = std_features.activated_features(pkg.package_id(), FeaturesFor::NormalOrDev);
for kind in kinds { 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( list.push(interner.intern(
pkg, pkg,
lib, lib,
@ -173,7 +173,7 @@ pub fn generate_std_roots(
)); ));
} }
} }
return Ok(ret); Ok(ret)
} }
fn detect_sysroot_src_path(target_data: &RustcTargetData) -> CargoResult<PathBuf> { fn detect_sysroot_src_path(target_data: &RustcTargetData) -> CargoResult<PathBuf> {

View File

@ -204,6 +204,6 @@ impl UnitInterner {
} }
let item = Rc::new(item.clone()); let item = Rc::new(item.clone());
me.cache.insert(item.clone()); me.cache.insert(item.clone());
return item; item
} }
} }

View File

@ -113,6 +113,6 @@ pub fn emit_serialized_unit_graph(root_units: &[Unit], unit_graph: &UnitGraph) -
let stdout = std::io::stdout(); let stdout = std::io::stdout();
let mut lock = stdout.lock(); let mut lock = stdout.lock();
serde_json::to_writer(&mut lock, &s)?; serde_json::to_writer(&mut lock, &s)?;
write!(lock, "\n")?; writeln!(lock)?;
Ok(()) Ok(())
} }

View File

@ -669,7 +669,7 @@ impl Target {
.set_name(name) .set_name(name)
.set_doctest(true) .set_doctest(true)
.set_doc(true); .set_doc(true);
return target; target
} }
pub fn bin_target( pub fn bin_target(
@ -684,7 +684,7 @@ impl Target {
.set_name(name) .set_name(name)
.set_required_features(required_features) .set_required_features(required_features)
.set_doc(true); .set_doc(true);
return target; target
} }
/// Builds a `Target` corresponding to the `build = "build.rs"` entry. /// Builds a `Target` corresponding to the `build = "build.rs"` entry.
@ -696,7 +696,7 @@ impl Target {
.set_for_host(true) .set_for_host(true)
.set_benched(false) .set_benched(false)
.set_tested(false); .set_tested(false);
return target; target
} }
pub fn metabuild_target(name: &str) -> Target { pub fn metabuild_target(name: &str) -> Target {
@ -707,7 +707,7 @@ impl Target {
.set_for_host(true) .set_for_host(true)
.set_benched(false) .set_benched(false)
.set_tested(false); .set_tested(false);
return target; target
} }
pub fn example_target( pub fn example_target(
@ -733,7 +733,7 @@ impl Target {
.set_required_features(required_features) .set_required_features(required_features)
.set_tested(false) .set_tested(false)
.set_benched(false); .set_benched(false);
return target; target
} }
pub fn test_target( pub fn test_target(
@ -748,7 +748,7 @@ impl Target {
.set_name(name) .set_name(name)
.set_required_features(required_features) .set_required_features(required_features)
.set_benched(false); .set_benched(false);
return target; target
} }
pub fn bench_target( pub fn bench_target(
@ -763,7 +763,7 @@ impl Target {
.set_name(name) .set_name(name)
.set_required_features(required_features) .set_required_features(required_features)
.set_tested(false); .set_tested(false);
return target; target
} }
pub fn name(&self) -> &str { pub fn name(&self) -> &str {

View File

@ -622,7 +622,7 @@ fn lock(
// Lock the summary's ID if possible // Lock the summary's ID if possible
let summary = match pair { let summary = match pair {
Some((precise, _)) => summary.override_id(precise.clone()), Some((precise, _)) => summary.override_id(*precise),
None => summary, None => summary,
}; };
summary.map_dependencies(|dep| { summary.map_dependencies(|dep| {

View File

@ -213,7 +213,7 @@ impl ConflictCache {
for c in con.keys() { for c in con.keys() {
self.dep_from_pid self.dep_from_pid
.entry(c.clone()) .entry(*c)
.or_insert_with(HashSet::new) .or_insert_with(HashSet::new)
.insert(dep.clone()); .insert(dep.clone());
} }

View File

@ -260,7 +260,7 @@ impl EncodableResolve {
let mut g = Graph::new(); let mut g = Graph::new();
for &(ref id, _) in live_pkgs.values() { for &(ref id, _) in live_pkgs.values() {
g.add(id.clone()); g.add(*id);
} }
for &(ref id, pkg) in live_pkgs.values() { for &(ref id, pkg) in live_pkgs.values() {
@ -271,7 +271,7 @@ impl EncodableResolve {
for edge in deps.iter() { for edge in deps.iter() {
if let Some(to_depend_on) = lookup_id(edge) { 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 { if let Some(ref replace) = pkg.replace {
assert!(pkg.dependencies.is_none()); assert!(pkg.dependencies.is_none());
if let Some(replace_id) = lookup_id(replace) { if let Some(replace_id) = lookup_id(replace) {
replacements.insert(id.clone(), replace_id); replacements.insert(*id, replace_id);
} }
} }
} }

View File

@ -144,7 +144,7 @@ pub fn display_error(err: &Error, shell: &mut Shell) {
/// and context. /// and context.
pub fn display_warning_with_error(warning: &str, err: &Error, shell: &mut Shell) { pub fn display_warning_with_error(warning: &str, err: &Error, shell: &mut Shell) {
drop(shell.warn(warning)); drop(shell.warn(warning));
drop(writeln!(shell.err(), "")); drop(writeln!(shell.err()));
_display_error(err, shell, false); _display_error(err, shell, false);
} }

View File

@ -39,7 +39,7 @@ pub fn fetch<'a>(
deps.iter().any(|d| { deps.iter().any(|d| {
// If no target was specified then all dependencies are // If no target was specified then all dependencies are
// fetched. // fetched.
if options.targets.len() == 0 { if options.targets.is_empty() {
return true; return true;
} }

View File

@ -176,7 +176,7 @@ fn build_resolve_graph_r(
let deps: Vec<Dep> = resolve let deps: Vec<Dep> = resolve
.deps(pkg_id) .deps(pkg_id)
.filter(|(_dep_id, deps)| { .filter(|(_dep_id, deps)| {
if requested_kinds == &[CompileKind::Host] { if requested_kinds == [CompileKind::Host] {
true true
} else { } else {
requested_kinds.iter().any(|kind| { requested_kinds.iter().any(|kind| {

View File

@ -378,7 +378,7 @@ fn registry(
token: token_config, token: token_config,
index: index_config, index: index_config,
} = registry_configuration(config, registry.clone())?; } = 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())?; let sid = get_source_id(config, opt_index, registry.as_ref())?;
if !sid.is_remote_registry() { if !sid.is_remote_registry() {
bail!( bail!(

View File

@ -35,7 +35,7 @@ fn simple_build() {
.masquerade_as_nightly_cargo() .masquerade_as_nightly_cargo()
.run(); .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()); assert!(p.target_bin(&t2, "foo").is_file());
} }