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

Clean up code mostly based on clippy suggestions #7911

Merged
merged 2 commits into from
Feb 21, 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
18 changes: 8 additions & 10 deletions crates/cargo-platform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,14 @@ impl Platform {
)),
_ => (),
},
Cfg::KeyPair(name, _) => match name.as_str() {
"feature" =>
warnings.push(String::from(
"Found `feature = ...` in `target.'cfg(...)'.dependencies`. \
This key is not supported for selecting dependencies \
and will not work as expected. \
Use the [features] section instead: \
https://doc.rust-lang.org/cargo/reference/features.html"
)),
_ => (),
Cfg::KeyPair(name, _) => if name.as_str() == "feature" {
warnings.push(String::from(
"Found `feature = ...` in `target.'cfg(...)'.dependencies`. \
This key is not supported for selecting dependencies \
and will not work as expected. \
Use the [features] section instead: \
https://doc.rust-lang.org/cargo/reference/features.html"
))
},
}
}
Expand Down
1 change: 0 additions & 1 deletion crates/crates-io/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use anyhow::{bail, Result};
use curl::easy::{Easy, List};
use percent_encoding::{percent_encode, NON_ALPHANUMERIC};
use serde::{Deserialize, Serialize};
use serde_json;
use url::Url;

pub struct Registry {
Expand Down
7 changes: 2 additions & 5 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use clap;

use clap::{AppSettings, Arg, ArgMatches};

use cargo::core::features;
use cargo::{self, CliResult, Config};
use clap::{AppSettings, Arg, ArgMatches};

use super::commands;
use super::list_commands;
Expand Down Expand Up @@ -154,7 +151,7 @@ fn expand_aliases(
// capture those global options now.
// Note that an alias to an external command will not receive
// these arguments. That may be confusing, but such is life.
let global_args = GlobalArgs::new(&args);
let global_args = GlobalArgs::new(args);
let new_args = cli()
.setting(AppSettings::NoBinaryName)
.get_matches_from_safe(alias)?;
Expand Down
3 changes: 1 addition & 2 deletions src/cargo/core/compiler/context/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {

let file_type = file_types
.iter()
.filter(|file_type| file_type.flavor == FileFlavor::Normal)
.next()
.find(|file_type| file_type.flavor == FileFlavor::Normal)
.expect("target must support `bin`");

Ok(dest.join(file_type.filename(target.name())))
Expand Down
10 changes: 2 additions & 8 deletions src/cargo/core/compiler/unit_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,7 @@ fn compute_deps<'a, 'cfg>(
// If this is an optional dependency, and the new feature resolver
// did not enable it, don't include it.
if dep.is_optional() {
let features_for = match unit_for.is_for_build_dep() {
true => FeaturesFor::BuildDep,
false => FeaturesFor::NormalOrDev,
};
let features_for = unit_for.map_to_features_for();

let feats = state.activated_features(id, features_for);
if !feats.contains(&dep.name_in_toml()) {
Expand Down Expand Up @@ -627,10 +624,7 @@ fn new_unit_dep_with_profile<'a>(
let public = state
.resolve()
.is_public_dep(parent.pkg.package_id(), pkg.package_id());
let features_for = match unit_for.is_for_build_dep() {
true => FeaturesFor::BuildDep,
false => FeaturesFor::NormalOrDev,
};
let features_for = unit_for.map_to_features_for();
let features = state.activated_features(pkg.package_id(), features_for);
let unit = state
.bcx
Expand Down
1 change: 0 additions & 1 deletion src/cargo/core/package_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::path::Path;
use std::ptr;
use std::sync::Mutex;

use semver;
use serde::de;
use serde::ser;

Expand Down
9 changes: 9 additions & 0 deletions src/cargo/core/profiles.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::core::compiler::CompileMode;
use crate::core::interning::InternedString;
use crate::core::resolver::features::FeaturesFor;
use crate::core::{Feature, Features, PackageId, PackageIdSpec, Resolve, Shell};
use crate::util::errors::CargoResultExt;
use crate::util::toml::{ProfilePackageSpec, StringOrBool, TomlProfile, TomlProfiles, U32OrBool};
Expand Down Expand Up @@ -975,6 +976,14 @@ impl UnitFor {
];
ALL
}

pub(crate) fn map_to_features_for(&self) -> FeaturesFor {
if self.is_for_build_dep() {
FeaturesFor::BuildDep
} else {
FeaturesFor::NormalOrDev
}
}
}

/// Takes the manifest profiles, and overlays the config profiles on-top.
Expand Down
1 change: 0 additions & 1 deletion src/cargo/core/resolver/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::core::{Dependency, PackageId, Registry, Summary};
use crate::util::lev_distance::lev_distance;
use crate::util::Config;
use anyhow::Error;
use semver;

use super::context::Context;
use super::types::{ConflictMap, ConflictReason};
Expand Down
3 changes: 1 addition & 2 deletions src/cargo/core/resolver/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,7 @@ impl PartialEq for Resolve {
fn eq(&self, other: &Resolve) -> bool {
macro_rules! compare {
($($fields:ident)* | $($ignored:ident)*) => {
let Resolve { $($fields,)* $($ignored,)* } = self;
$(drop($ignored);)*
let Resolve { $($fields,)* $($ignored: _,)* } = self;
$($fields == &other.$fields)&&*
}
}
Expand Down
1 change: 0 additions & 1 deletion src/cargo/core/resolver/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::core::interning::InternedString;
use crate::core::{Dependency, PackageId, Summary};
use crate::util::errors::CargoResult;
use crate::util::Config;
use im_rc;
use std::cmp::Ordering;
use std::collections::{BTreeMap, BTreeSet};
use std::ops::Range;
Expand Down
6 changes: 1 addition & 5 deletions src/cargo/core/shell.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::fmt;
use std::io::prelude::*;

use atty;
use termcolor::Color::{Cyan, Green, Red, Yellow};
use termcolor::{self, Color, ColorSpec, StandardStream, WriteColor};

Expand Down Expand Up @@ -382,11 +381,8 @@ impl ColorChoice {

#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
mod imp {
use std::mem;

use libc;

use super::Shell;
use std::mem;

pub fn stderr_width() -> Option<usize> {
unsafe {
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ impl<'cfg> Workspace<'cfg> {
.map(|m| (m, RequestedFeatures::new_all(false)))
.collect());
}
return Ok(members);
Ok(members)
} else {
let ms = self.members().filter_map(|member| {
let member_id = member.package_id();
Expand All @@ -911,7 +911,7 @@ impl<'cfg> Workspace<'cfg> {
}
}
});
return Ok(ms.collect());
Ok(ms.collect())
}
}
}
Expand Down
9 changes: 2 additions & 7 deletions src/cargo/ops/cargo_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use crate::core::compiler::unit_dependencies;
use crate::core::compiler::{BuildConfig, BuildContext, CompileKind, CompileMode, Context};
use crate::core::compiler::{RustcTargetData, UnitInterner};
use crate::core::profiles::{Profiles, UnitFor};
use crate::core::resolver::features::{
FeatureResolver, FeaturesFor, HasDevUnits, RequestedFeatures,
};
use crate::core::resolver::features::{FeatureResolver, HasDevUnits, RequestedFeatures};
use crate::core::{PackageIdSpec, Workspace};
use crate::ops;
use crate::util::errors::{CargoResult, CargoResultExt};
Expand Down Expand Up @@ -120,10 +118,7 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> {
};
// Use unverified here since this is being more
// exhaustive than what is actually needed.
let features_for = match unit_for.is_for_build_dep() {
true => FeaturesFor::BuildDep,
false => FeaturesFor::NormalOrDev,
};
let features_for = unit_for.map_to_features_for();
let features =
features.activated_features_unverified(pkg.package_id(), features_for);
units.push(bcx.units.intern(
Expand Down
14 changes: 8 additions & 6 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,10 @@ pub fn compile_ws<'a>(
let specs = spec.to_package_id_specs(ws)?;
let dev_deps = ws.require_optional_deps() || filter.need_dev_deps(build_config.mode);
let opts = ResolveOpts::new(dev_deps, features, all_features, !no_default_features);
let has_dev_units = match filter.need_dev_deps(build_config.mode) {
true => HasDevUnits::Yes,
false => HasDevUnits::No,
let has_dev_units = if filter.need_dev_deps(build_config.mode) {
HasDevUnits::Yes
} else {
HasDevUnits::No
};
let resolve = ops::resolve_ws_with_opts(
ws,
Expand Down Expand Up @@ -950,9 +951,10 @@ fn resolve_all_features(
// required-features field when deciding whether to be built or skipped.
for (dep_id, deps) in resolve_with_overrides.deps(package_id) {
for dep in deps {
let features_for = match dep.is_build() {
true => FeaturesFor::BuildDep,
false => FeaturesFor::NormalOrDev,
let features_for = if dep.is_build() {
FeaturesFor::BuildDep
} else {
FeaturesFor::NormalOrDev
};
for feature in resolved_features.activated_features(dep_id, features_for) {
features.insert(dep.name_in_toml().to_string() + "/" + &feature);
Expand Down
2 changes: 0 additions & 2 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ use std::path::{Path, PathBuf};
use std::process::Command;
use std::str::{from_utf8, FromStr};

use toml;

#[derive(Clone, Copy, Debug, PartialEq)]
pub enum VersionControl {
Git,
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 @@ -172,7 +172,7 @@ fn build_resolve_graph_r(
if node_map.contains_key(&pkg_id) {
return;
}
let features = resolve.features(pkg_id).iter().cloned().collect();
let features = resolve.features(pkg_id).to_vec();

let deps: Vec<Dep> = resolve
.deps(pkg_id)
Expand Down
2 changes: 0 additions & 2 deletions src/cargo/ops/lockfile.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::io::prelude::*;

use toml;

use crate::core::{resolver, Resolve, ResolveVersion, Workspace};
use crate::util::errors::{CargoResult, CargoResultExt};
use crate::util::toml as cargo_toml;
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ impl Config {
/// Helper for StringList type to get something that is a string or list.
fn get_list_or_string(&self, key: &ConfigKey) -> CargoResult<Vec<(String, Definition)>> {
let mut res = Vec::new();
match self.get_cv(&key)? {
match self.get_cv(key)? {
Some(CV::List(val, _def)) => res.extend(val),
Some(CV::String(val, def)) => {
let split_vs = val.split_whitespace().map(|s| (s.to_string(), def.clone()));
Expand Down
2 changes: 0 additions & 2 deletions src/cargo/util/flock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use std::io::{Read, Seek, SeekFrom, Write};
use std::path::{Display, Path, PathBuf};

use fs2::{lock_contended_error, FileExt};
#[allow(unused_imports)]
use libc;
use termcolor::Color::Cyan;
#[cfg(windows)]
use winapi::shared::winerror::ERROR_INVALID_FUNCTION;
Expand Down
2 changes: 0 additions & 2 deletions src/cargo/util/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use std::borrow::Borrow;
use std::collections::BTreeSet;
use std::fmt;

use im_rc;

pub struct Graph<N: Clone, E: Clone> {
nodes: im_rc::OrdMap<N, im_rc::OrdMap<N, E>>,
}
Expand Down
1 change: 0 additions & 1 deletion src/cargo/util/hex.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![allow(deprecated)]

use hex;
use std::hash::{Hash, Hasher, SipHasher};

pub fn to_hex(num: u64) -> String {
Expand Down
1 change: 0 additions & 1 deletion src/cargo/util/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub fn setup() -> Option<Setup> {

#[cfg(unix)]
mod imp {
use libc;
use std::env;

pub type Setup = ();
Expand Down
3 changes: 0 additions & 3 deletions src/cargo/util/network.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use curl;
use git2;

use anyhow::Error;

use crate::util::errors::{CargoResult, HttpNot200};
Expand Down
26 changes: 12 additions & 14 deletions src/cargo/util/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,21 +378,19 @@ fn _link_or_copy(src: &Path, dst: &Path) -> CargoResult<()> {
src
};
symlink(src, dst)
} else if env::var_os("__CARGO_COPY_DONT_LINK_DO_NOT_USE_THIS").is_some() {
// This is a work-around for a bug in macOS 10.15. When running on
// APFS, there seems to be a strange race condition with
// Gatekeeper where it will forcefully kill a process launched via
// `cargo run` with SIGKILL. Copying seems to avoid the problem.
// This shouldn't affect anyone except Cargo's test suite because
// it is very rare, and only seems to happen under heavy load and
// rapidly creating lots of executables and running them.
// See https://github.com/rust-lang/cargo/issues/7821 for the
// gory details.
fs::copy(src, dst).map(|_| ())
} else {
if env::var_os("__CARGO_COPY_DONT_LINK_DO_NOT_USE_THIS").is_some() {
// This is a work-around for a bug in macOS 10.15. When running on
// APFS, there seems to be a strange race condition with
// Gatekeeper where it will forcefully kill a process launched via
// `cargo run` with SIGKILL. Copying seems to avoid the problem.
// This shouldn't affect anyone except Cargo's test suite because
// it is very rare, and only seems to happen under heavy load and
// rapidly creating lots of executables and running them.
// See https://github.com/rust-lang/cargo/issues/7821 for the
// gory details.
fs::copy(src, dst).map(|_| ())
} else {
fs::hard_link(src, dst)
}
fs::hard_link(src, dst)
};
link_result
.or_else(|err| {
Expand Down
1 change: 0 additions & 1 deletion src/cargo/util/read2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ pub use self::imp::read2;

#[cfg(unix)]
mod imp {
use libc;
use std::io;
use std::io::prelude::*;
use std::mem;
Expand Down
3 changes: 1 addition & 2 deletions src/cargo/util/sha256.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use self::crypto_hash::{Algorithm, Hasher};
use crate::util::{CargoResult, CargoResultExt};
use crypto_hash;
use crypto_hash::{Algorithm, Hasher};
use std::fs::File;
use std::io::{self, Read, Write};
use std::path::Path;
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ impl TomlManifest {
.collect()
})
.unwrap_or_else(BTreeMap::new),
project.links.as_ref().map(|x| x.as_str()),
project.links.as_deref(),
project.namespaced_features.unwrap_or(false),
)?;
let metadata = ManifestMetadata {
Expand Down
1 change: 0 additions & 1 deletion src/cargo/util/vcs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::util::paths;
use crate::util::{process, CargoResult};
use git2;
use std::path::Path;

// Check if we are in an existing repo. We define that to be true if either:
Expand Down