cargo clippy + fmt
diff --git a/src/cargo_ops/elaborate_workspace.rs b/src/cargo_ops/elaborate_workspace.rs
index 8e31266..11b4f67 100644
--- a/src/cargo_ops/elaborate_workspace.rs
+++ b/src/cargo_ops/elaborate_workspace.rs
@@ -4,13 +4,12 @@
use std::io::{self, Write};
use anyhow::anyhow;
+use cargo::core::compiler::{CompileKind, RustcTargetData};
+use cargo::core::resolver::features::{ForceAllTargets, HasDevUnits};
use cargo::core::{dependency::DepKind, Dependency, Package, PackageId, Workspace};
-use cargo::core::compiler::{RustcTargetData, CompileKind};
use cargo::ops::{self, Packages};
-use cargo::core::resolver::features::{HasDevUnits, ForceAllTargets};
use cargo::util::{CargoResult, Config};
use serde::{Deserialize, Serialize};
-use serde_json;
use tabwriter::TabWriter;
use super::pkg_status::*;
@@ -45,17 +44,12 @@
pub platform: Option<String>,
}
-
impl Ord for Metadata {
- fn cmp(&self, other: &Self) -> Ordering {
- self.name.cmp(&other.name)
- }
+ fn cmp(&self, other: &Self) -> Ordering { self.name.cmp(&other.name) }
}
impl PartialOrd for Metadata {
- fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
- Some(self.cmp(other))
- }
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }
}
impl<'ela> ElaborateWorkspace<'ela> {
@@ -67,19 +61,28 @@
use cargo::core::resolver::{features::RequestedFeatures, ResolveOpts};
let specs = Packages::All.to_package_id_specs(workspace)?;
let features = RequestedFeatures::from_command_line(
- &options.flag_features, options.all_features(), options.no_default_features()
+ &options.flag_features,
+ options.all_features(),
+ options.no_default_features(),
);
- let opts = ResolveOpts::new(
- true,
- features,
- );
+ let opts = ResolveOpts::new(true, features);
//The CompileKind, this has no target since it's the temp workspace
//targets are blank since we don't need to fully build for the targets to get the dependencies
let compile_kind = CompileKind::from_requested_targets(workspace.config(), &[])?;
let target_data = RustcTargetData::new(&workspace, &compile_kind)?;
- let ws_resolve = ops::resolve_ws_with_opts(&workspace, &target_data, &compile_kind, &opts, &specs, HasDevUnits::Yes, ForceAllTargets::Yes)?;
+ let ws_resolve = ops::resolve_ws_with_opts(
+ &workspace,
+ &target_data,
+ &compile_kind,
+ &opts,
+ &specs,
+ HasDevUnits::Yes,
+ ForceAllTargets::Yes,
+ )?;
let packages = ws_resolve.pkg_set;
- let resolve = ws_resolve.workspace_resolve.expect("Error getting workspace resolved");
+ let resolve = ws_resolve
+ .workspace_resolve
+ .expect("Error getting workspace resolved");
let mut pkgs = HashMap::new();
let mut pkg_deps = HashMap::new();
for pkg in packages.get_many(packages.package_ids())? {
@@ -119,9 +122,9 @@
return Ok(*direct_dep);
}
}
- return Err(anyhow!(
+ Err(anyhow!(
"Root is neither the workspace root nor a direct dependency",
- ));
+ ))
}
} else {
Err(anyhow!(
@@ -271,8 +274,7 @@
// generate lines
let status = &self.pkg_status.borrow_mut()[&path];
if (status.compat.is_changed() || status.latest.is_changed())
- && (options.flag_packages.is_empty()
- || options.flag_packages.contains(&name))
+ && (options.flag_packages.is_empty() || options.flag_packages.contains(&name))
{
// name version compatible latest kind platform
let parent = path.get(path.len() - 2);
@@ -375,8 +377,7 @@
// generate lines
let status = &self.pkg_status.borrow_mut()[&path];
if (status.compat.is_changed() || status.latest.is_changed())
- && (options.flag_packages.is_empty()
- || options.flag_packages.contains(&name))
+ && (options.flag_packages.is_empty() || options.flag_packages.contains(&name))
{
// name version compatible latest kind platform
let parent = path.get(path.len() - 2);
diff --git a/src/cargo_ops/pkg_status.rs b/src/cargo_ops/pkg_status.rs
index 5830695..0156bfb 100644
--- a/src/cargo_ops/pkg_status.rs
+++ b/src/cargo_ops/pkg_status.rs
@@ -21,12 +21,7 @@
}
}
- pub fn is_changed(&self) -> bool {
- match *self {
- Status::Unchanged => false,
- _ => true,
- }
- }
+ pub fn is_changed(&self) -> bool { !matches!(*self, Status::Unchanged) }
}
impl ::std::string::ToString for Status {
diff --git a/src/cargo_ops/temp_project.rs b/src/cargo_ops/temp_project.rs
index f8e87cb..5d831e7 100644
--- a/src/cargo_ops/temp_project.rs
+++ b/src/cargo_ops/temp_project.rs
@@ -77,7 +77,11 @@
if om.package.contains_key("default-run") {
om.package.remove("default-run");
let om_serialized = ::toml::to_string(&om).expect("Cannot format as toml file");
- let mut cargo_toml = OpenOptions::new().read(true).write(true).truncate(true).open(&dest)?;
+ let mut cargo_toml = OpenOptions::new()
+ .read(true)
+ .write(true)
+ .truncate(true)
+ .open(&dest)?;
write!(cargo_toml, "{}", om_serialized)?;
}
@@ -86,14 +90,22 @@
if om.package.contains_key("links") {
om.package.remove("links");
let om_serialized = ::toml::to_string(&om).expect("Cannot format as toml file");
- let mut cargo_toml = OpenOptions::new().read(true).write(true).truncate(true).open(&dest)?;
+ let mut cargo_toml = OpenOptions::new()
+ .read(true)
+ .write(true)
+ .truncate(true)
+ .open(&dest)?;
write!(cargo_toml, "{}", om_serialized)?;
}
if om.package.contains_key("build") {
om.package.remove("build");
let om_serialized = ::toml::to_string(&om).expect("Cannot format as toml file");
- let mut cargo_toml = OpenOptions::new().read(true).write(true).truncate(true).open(&dest)?;
+ let mut cargo_toml = OpenOptions::new()
+ .read(true)
+ .write(true)
+ .truncate(true)
+ .open(&dest)?;
write!(cargo_toml, "{}", om_serialized)?;
}
@@ -120,15 +132,21 @@
// this is the preferred way
// https://doc.rust-lang.org/cargo/reference/config.html
if workspace_root.join(".cargo/config.toml").is_file() {
- fs::create_dir_all( temp_dir.path().join(".cargo"))?;
- fs::copy(&workspace_root.join(".cargo/config.toml"), temp_dir.path().join(".cargo/config.toml"))?;
+ fs::create_dir_all(temp_dir.path().join(".cargo"))?;
+ fs::copy(
+ &workspace_root.join(".cargo/config.toml"),
+ temp_dir.path().join(".cargo/config.toml"),
+ )?;
}
//.cargo/config
// this is legacy support for config files without the `.toml` extension
if workspace_root.join(".cargo/config").is_file() {
- fs::create_dir_all( temp_dir.path().join(".cargo"))?;
- fs::copy(&workspace_root.join(".cargo/config"), temp_dir.path().join(".cargo/config"))?;
+ fs::create_dir_all(temp_dir.path().join(".cargo"))?;
+ fs::copy(
+ &workspace_root.join(".cargo/config"),
+ temp_dir.path().join(".cargo/config"),
+ )?;
}
let relative_manifest = String::from(&orig_manifest[workspace_root_str.len() + 1..]);
@@ -165,19 +183,12 @@
// Check if $CARGO_HOME is set before capturing the config environment
// if it is, set it in the configure options
- let cargo_home_path = match std::env::var_os("CARGO_HOME") {
- Some(path) => Some(std::path::PathBuf::from(path)),
- None => None
- };
+ let cargo_home_path = std::env::var_os("CARGO_HOME").map(std::path::PathBuf::from);
let mut config = Config::new(shell, cwd, homedir);
config.configure(
0,
- if options.flag_verbose > 0 {
- false
- } else {
- true
- },
+ options.flag_verbose == 0,
options.flag_color.as_deref(),
options.frozen(),
options.locked(),
@@ -283,7 +294,6 @@
self.update_version_and_feature(deps, &features, workspace, &package_name, false)
})?;
-
Self::write_manifest(&manifest, manifest_path)?;
}
let root_manifest = self.temp_dir.path().join(&self.relative_manifest);
@@ -383,7 +393,6 @@
}
})
.unwrap_or_else(|| {
-
// If the version_req cannot be found use the version
// this happens when we use a git repository as a dependency, without specifying
// the version in Cargo.toml, preventing us from needing an unwrap below in the warn
@@ -392,7 +401,13 @@
None => format!("{}", version),
};
- self.warn(format!("cannot compare {} crate version found in toml {} with crates.io latest {}", name, ver_req, query_result[0].version())).unwrap();
+ self.warn(format!(
+ "cannot compare {} crate version found in toml {} with crates.io latest {}",
+ name,
+ ver_req,
+ query_result[0].version()
+ ))
+ .unwrap();
//this returns the latest version
&query_result[0]
});
@@ -518,7 +533,11 @@
_ => None,
};
let r_summary = self.find_update(
- if orig_name == "" { &name } else { &orig_name },
+ if orig_name.is_empty() {
+ &name
+ } else {
+ &orig_name
+ },
package_name,
requirement,
workspace,
@@ -674,17 +693,22 @@
// Checking if there's a CARGO_HOME set and that it is not an empty string
let cargo_home_path = match std::env::var_os("CARGO_HOME") {
- Some(path) if !path.is_empty() => Some(path.into_string().expect("Error getting string from OsString")),
- _ => None,
- };
+ Some(path) if !path.is_empty() => Some(
+ path.into_string()
+ .expect("Error getting string from OsString"),
+ ),
+ _ => None,
+ };
- // If there is a CARGO_HOME make sure we do not crawl the registry for more Cargo.toml files
- // Otherwise add all Cargo.toml files to the manifest paths
- if pkg.root().starts_with(PathBuf::from(workspace_path.clone())) {
- if cargo_home_path.is_none() || !pkg_path.starts_with(&cargo_home_path.expect("Error extracting CARGO_HOME string")) {
- manifest_paths.push(pkg.manifest_path().to_owned());
- }
- }
+ // If there is a CARGO_HOME make sure we do not crawl the registry for more Cargo.toml files
+ // Otherwise add all Cargo.toml files to the manifest paths
+ if pkg.root().starts_with(PathBuf::from(workspace_path))
+ && (cargo_home_path.is_none()
+ || !pkg_path
+ .starts_with(&cargo_home_path.expect("Error extracting CARGO_HOME string")))
+ {
+ manifest_paths.push(pkg.manifest_path().to_owned());
+ }
for &dep in elab.pkg_deps[&pkg_id].keys() {
manifest_paths_recursive(dep, elab, workspace_path, visited, manifest_paths)?;
@@ -720,8 +744,9 @@
(false, false) | (true, false) => true,
// both are unstable, must be in the same channel
(true, true) => {
- requirement = requirement.trim_start_matches(&['=',' ','~','^'][..]);
- let requirement_version = Version::parse(&requirement).expect("Error could not parse requirement into a semantic version");
+ requirement = requirement.trim_start_matches(&['=', ' ', '~', '^'][..]);
+ let requirement_version = Version::parse(&requirement)
+ .expect("Error could not parse requirement into a semantic version");
let requirement_channel = requirement_version.pre[0].to_string();
match (requirement_channel.is_empty(), &version.pre[0]) {
(true, &Identifier::Numeric(_)) => true,
diff --git a/src/main.rs b/src/main.rs
index 80eddff..5aa5983 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,8 +1,5 @@
#![deny(bare_trait_objects, anonymous_parameters, elided_lifetimes_in_paths)]
-use cargo;
-use env_logger;
-
#[macro_use]
mod macros;
mod cargo_ops;
@@ -15,7 +12,6 @@
use cargo::util::important_paths::find_root_manifest_for_wd;
use cargo::util::{CargoResult, CliError, Config};
use docopt::Docopt;
-use git2_curl;
pub const USAGE: &str = "
Displays information about project dependency versions
@@ -106,8 +102,6 @@
options
};
-
-
let mut config = match Config::default() {
Ok(cfg) => cfg,
Err(e) => {
@@ -119,21 +113,15 @@
// Only use a custom transport if any HTTP options are specified,
// such as proxies or custom certificate authorities. The custom
// transport, however, is not as well battle-tested.
- // See cargo-outdated issue #197 and
- // https://github.com/rust-lang/cargo/blob/master/src/bin/cargo/main.rs#L181
+ // See cargo-outdated issue #197 and
+ // https://github.com/rust-lang/cargo/blob/master/src/bin/cargo/main.rs#L181
// fn init_git_transports()
- match needs_custom_http_transport(&config) {
- Ok(true) => {
- match cargo::ops::http_handle(&config) {
- Ok(handle) => {
- unsafe {
- git2_curl::register(handle);
- }
- },
- Err(_) => {}
+ if let Ok(true) = needs_custom_http_transport(&config) {
+ if let Ok(handle) = cargo::ops::http_handle(&config) {
+ unsafe {
+ git2_curl::register(handle);
}
- },
- _ => {},
+ }
}
let exit_code = options.flag_exit_code;
@@ -155,12 +143,9 @@
}
pub fn execute(options: Options, config: &mut Config) -> CargoResult<i32> {
- // Check if $CARGO_HOME is set before capturing the config environment
- // if it is, set it in the configure options
- let cargo_home_path = match std::env::var_os("CARGO_HOME") {
- Some(path) => Some(std::path::PathBuf::from(path)),
- None => None
- };
+ // Check if $CARGO_HOME is set before capturing the config environment
+ // if it is, set it in the configure options
+ let cargo_home_path = std::env::var_os("CARGO_HOME").map(std::path::PathBuf::from);
config.configure(
options.flag_verbose,