diff --git a/crates/cargo-platform/src/lib.rs b/crates/cargo-platform/src/lib.rs index bafa2b6f338..0a3dcf1af15 100644 --- a/crates/cargo-platform/src/lib.rs +++ b/crates/cargo-platform/src/lib.rs @@ -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" + )) }, } } diff --git a/crates/crates-io/lib.rs b/crates/crates-io/lib.rs index becd02af8d8..68e5a3b9b0d 100644 --- a/crates/crates-io/lib.rs +++ b/crates/crates-io/lib.rs @@ -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 { diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index 567a5ece735..ed348e2838f 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -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; @@ -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)?; diff --git a/src/cargo/core/compiler/context/compilation_files.rs b/src/cargo/core/compiler/context/compilation_files.rs index 313935d8e3d..f9eab92f67d 100644 --- a/src/cargo/core/compiler/context/compilation_files.rs +++ b/src/cargo/core/compiler/context/compilation_files.rs @@ -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()))) diff --git a/src/cargo/core/compiler/unit_dependencies.rs b/src/cargo/core/compiler/unit_dependencies.rs index 7f19c917539..1dd7f233c48 100644 --- a/src/cargo/core/compiler/unit_dependencies.rs +++ b/src/cargo/core/compiler/unit_dependencies.rs @@ -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()) { @@ -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 diff --git a/src/cargo/core/package_id.rs b/src/cargo/core/package_id.rs index e15fbed243b..088a4d98d79 100644 --- a/src/cargo/core/package_id.rs +++ b/src/cargo/core/package_id.rs @@ -6,7 +6,6 @@ use std::path::Path; use std::ptr; use std::sync::Mutex; -use semver; use serde::de; use serde::ser; diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 2f83aba2211..562bf1b3e3f 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -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}; @@ -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. diff --git a/src/cargo/core/resolver/errors.rs b/src/cargo/core/resolver/errors.rs index 807555c86ee..68ed530e539 100644 --- a/src/cargo/core/resolver/errors.rs +++ b/src/cargo/core/resolver/errors.rs @@ -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}; diff --git a/src/cargo/core/resolver/resolve.rs b/src/cargo/core/resolver/resolve.rs index cd4afbfb380..91df17b2e18 100644 --- a/src/cargo/core/resolver/resolve.rs +++ b/src/cargo/core/resolver/resolve.rs @@ -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)&&* } } diff --git a/src/cargo/core/resolver/types.rs b/src/cargo/core/resolver/types.rs index 53e325bb5c5..8fb56ceb422 100644 --- a/src/cargo/core/resolver/types.rs +++ b/src/cargo/core/resolver/types.rs @@ -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; diff --git a/src/cargo/core/shell.rs b/src/cargo/core/shell.rs index 3310c34245f..8350f99e87b 100644 --- a/src/cargo/core/shell.rs +++ b/src/cargo/core/shell.rs @@ -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}; @@ -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 { unsafe { diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index cd818302588..1da47e0ebd6 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -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(); @@ -911,7 +911,7 @@ impl<'cfg> Workspace<'cfg> { } } }); - return Ok(ms.collect()); + Ok(ms.collect()) } } } diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index 16a6de24ce1..1e13d5a2f0d 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -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}; @@ -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( diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index fc6dffd7544..89ea39ca0c1 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -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, @@ -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); diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index dd892d5a12a..7b8d9660e1c 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -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, diff --git a/src/cargo/ops/cargo_output_metadata.rs b/src/cargo/ops/cargo_output_metadata.rs index c1e5c720394..05b68fb7cdf 100644 --- a/src/cargo/ops/cargo_output_metadata.rs +++ b/src/cargo/ops/cargo_output_metadata.rs @@ -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 = resolve .deps(pkg_id) diff --git a/src/cargo/ops/lockfile.rs b/src/cargo/ops/lockfile.rs index da23b4a9f7b..35417ab07ad 100644 --- a/src/cargo/ops/lockfile.rs +++ b/src/cargo/ops/lockfile.rs @@ -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; diff --git a/src/cargo/util/config/mod.rs b/src/cargo/util/config/mod.rs index e780410cff6..66b4e8afb43 100644 --- a/src/cargo/util/config/mod.rs +++ b/src/cargo/util/config/mod.rs @@ -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> { 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())); diff --git a/src/cargo/util/flock.rs b/src/cargo/util/flock.rs index 2d4332ab40b..76998165b42 100644 --- a/src/cargo/util/flock.rs +++ b/src/cargo/util/flock.rs @@ -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; diff --git a/src/cargo/util/graph.rs b/src/cargo/util/graph.rs index 00f58a292fb..8d2dc5b8449 100644 --- a/src/cargo/util/graph.rs +++ b/src/cargo/util/graph.rs @@ -2,8 +2,6 @@ use std::borrow::Borrow; use std::collections::BTreeSet; use std::fmt; -use im_rc; - pub struct Graph { nodes: im_rc::OrdMap>, } diff --git a/src/cargo/util/hex.rs b/src/cargo/util/hex.rs index ed60f9b8e5f..f3e905c9aba 100644 --- a/src/cargo/util/hex.rs +++ b/src/cargo/util/hex.rs @@ -1,6 +1,5 @@ #![allow(deprecated)] -use hex; use std::hash::{Hash, Hasher, SipHasher}; pub fn to_hex(num: u64) -> String { diff --git a/src/cargo/util/job.rs b/src/cargo/util/job.rs index 27b3b953f1a..51eb550b639 100644 --- a/src/cargo/util/job.rs +++ b/src/cargo/util/job.rs @@ -23,7 +23,6 @@ pub fn setup() -> Option { #[cfg(unix)] mod imp { - use libc; use std::env; pub type Setup = (); diff --git a/src/cargo/util/network.rs b/src/cargo/util/network.rs index d822b5d5df9..5b9275ceb93 100644 --- a/src/cargo/util/network.rs +++ b/src/cargo/util/network.rs @@ -1,6 +1,3 @@ -use curl; -use git2; - use anyhow::Error; use crate::util::errors::{CargoResult, HttpNot200}; diff --git a/src/cargo/util/paths.rs b/src/cargo/util/paths.rs index 5625ea104f8..3369e732478 100644 --- a/src/cargo/util/paths.rs +++ b/src/cargo/util/paths.rs @@ -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| { diff --git a/src/cargo/util/read2.rs b/src/cargo/util/read2.rs index bfa2427976d..53322a51d70 100644 --- a/src/cargo/util/read2.rs +++ b/src/cargo/util/read2.rs @@ -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; diff --git a/src/cargo/util/sha256.rs b/src/cargo/util/sha256.rs index b2cd8cab08a..f1b80594cfb 100644 --- a/src/cargo/util/sha256.rs +++ b/src/cargo/util/sha256.rs @@ -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; diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 950783d8911..30264b4d35a 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -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 { diff --git a/src/cargo/util/vcs.rs b/src/cargo/util/vcs.rs index d716ba61403..96d934a5dc2 100644 --- a/src/cargo/util/vcs.rs +++ b/src/cargo/util/vcs.rs @@ -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: