Skip to content

Commit

Permalink
Run through nightly clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksator committed Feb 20, 2020
1 parent 45ad3f9 commit 2b1dc3e
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 55 deletions.
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
2 changes: 1 addition & 1 deletion src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
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
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
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
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: 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: 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
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
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

0 comments on commit 2b1dc3e

Please sign in to comment.