Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clippy fixes #8189

Merged
merged 1 commit into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/cargo-test-support/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?;
kinds.push("no-dev");
}
if kinds.len() == 0 {
if kinds.is_empty() {
kinds.extend(&["normal", "build", "dev"]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ fn env_args(
// This means that, e.g., even if the specified --target is the
// same as the host, build scripts in plugins won't get
// 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
// compiling with --target. In this scenario there are
// no rustflags we can apply.
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/compile_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl CompileKind {
if targets.len() > 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)?)))
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/standard_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -173,7 +173,7 @@ pub fn generate_std_roots(
));
}
}
return Ok(ret);
Ok(ret)
}

fn detect_sysroot_src_path(target_data: &RustcTargetData) -> CargoResult<PathBuf> {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,6 @@ impl UnitInterner {
}
let item = Rc::new(item.clone());
me.cache.insert(item.clone());
return item;
item
}
}
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/unit_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
14 changes: 7 additions & 7 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ impl Target {
.set_name(name)
.set_doctest(true)
.set_doc(true);
return target;
target
}

pub fn bin_target(
Expand All @@ -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.
Expand All @@ -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 {
Expand All @@ -707,7 +707,7 @@ impl Target {
.set_for_host(true)
.set_benched(false)
.set_tested(false);
return target;
target
}

pub fn example_target(
Expand All @@ -733,7 +733,7 @@ impl Target {
.set_required_features(required_features)
.set_tested(false)
.set_benched(false);
return target;
target
}

pub fn test_target(
Expand All @@ -748,7 +748,7 @@ impl Target {
.set_name(name)
.set_required_features(required_features)
.set_benched(false);
return target;
target
}

pub fn bench_target(
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/resolver/conflict_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/core/resolver/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
}
}
}
Expand All @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_output_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ fn build_resolve_graph_r(
let deps: Vec<Dep> = 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| {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/multitarget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down