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/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index e08c96fd0a1..ed348e2838f 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -151,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/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/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/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_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/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/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/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 {