From 947e8902495c2a3e6da0a207d8c5be17e5d1ee9b Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Mon, 2 Apr 2018 21:25:59 +0200 Subject: [PATCH] chore(clippy): Simplify minor stuff found by clippy --- src/cargo/core/dependency.rs | 2 +- src/cargo/core/interning.rs | 8 +++++--- src/cargo/core/resolver/context.rs | 2 +- src/cargo/core/resolver/mod.rs | 4 ++-- src/cargo/core/resolver/types.rs | 4 ++-- src/cargo/ops/cargo_new.rs | 14 +++++++------- src/cargo/ops/cargo_package.rs | 2 +- src/cargo/ops/cargo_run.rs | 2 +- .../ops/cargo_rustc/context/compilation_files.rs | 2 +- src/cargo/ops/registry.rs | 8 ++++---- src/cargo/sources/git/utils.rs | 12 +++++------- src/cargo/util/paths.rs | 10 ++++------ 12 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/cargo/core/dependency.rs b/src/cargo/core/dependency.rs index a22302da5..441e34a2a 100644 --- a/src/cargo/core/dependency.rs +++ b/src/cargo/core/dependency.rs @@ -186,7 +186,7 @@ impl Dependency { } pub fn new_override(name: &str, source_id: &SourceId) -> Dependency { - assert!(name.len() > 0); + assert!(!name.is_empty()); Dependency { inner: Rc::new(Inner { name: InternedString::new(name), diff --git a/src/cargo/core/interning.rs b/src/cargo/core/interning.rs index d8c18df2d..e5b582dee 100644 --- a/src/cargo/core/interning.rs +++ b/src/cargo/core/interning.rs @@ -51,9 +51,11 @@ impl InternedString { InternedString { inner: s } } - - pub fn as_str(&self) -> &'static str { - self.inner + pub fn to_inner(&self) -> &'static str { + unsafe { + let slice = slice::from_raw_parts(self.ptr, self.len); + str::from_utf8_unchecked(slice) + } } } diff --git a/src/cargo/core/resolver/context.rs b/src/cargo/core/resolver/context.rs index 82786eb71..ea15e0501 100644 --- a/src/cargo/core/resolver/context.rs +++ b/src/cargo/core/resolver/context.rs @@ -340,7 +340,7 @@ struct Requirements<'a> { } impl<'r> Requirements<'r> { - fn new<'a>(summary: &'a Summary) -> Requirements<'a> { + fn new(summary: &Summary) -> Requirements { Requirements { summary, deps: HashMap::new(), diff --git a/src/cargo/core/resolver/mod.rs b/src/cargo/core/resolver/mod.rs index 0e123ded5..6c2a63e10 100644 --- a/src/cargo/core/resolver/mod.rs +++ b/src/cargo/core/resolver/mod.rs @@ -432,7 +432,7 @@ fn activate_deps_loop( .remaining_siblings .clone() .filter_map(|(_, (ref new_dep, _, _))| { - past_conflicting_activations.conflicting(&cx, &new_dep) + past_conflicting_activations.conflicting(&cx, new_dep) }) .next() { @@ -818,7 +818,7 @@ fn compatible(a: &semver::Version, b: &semver::Version) -> bool { /// /// Read /// For several more detailed explanations of the logic here. -fn find_candidate<'a>( +fn find_candidate( backtrack_stack: &mut Vec, parent: &Summary, conflicting_activations: &HashMap, diff --git a/src/cargo/core/resolver/types.rs b/src/cargo/core/resolver/types.rs index 8de61be77..37db6b92b 100644 --- a/src/cargo/core/resolver/types.rs +++ b/src/cargo/core/resolver/types.rs @@ -134,8 +134,8 @@ impl<'a> RegistryQueryer<'a> { let previous_cmp = a_in_previous.cmp(&b_in_previous).reverse(); match previous_cmp { Ordering::Equal => { - let cmp = a.summary.version().cmp(&b.summary.version()); - if self.minimal_versions == true { + let cmp = a.summary.version().cmp(b.summary.version()); + if self.minimal_versions { // Lower version ordered first. cmp } else { diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index 7ac60bdfe..2f0e94157 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -318,7 +318,7 @@ pub fn new(opts: &NewOptions, config: &Config) -> CargoResult<()> { let mkopts = MkOptions { version_control: opts.version_control, - path: &path, + path, name, source_files: vec![plan_new_source_file(opts.kind.is_bin(), name.to_string())], bin: opts.kind.is_bin(), @@ -341,12 +341,12 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<()> { bail!("`cargo init` cannot be run on existing Cargo projects") } - let name = get_name(&path, opts)?; + let name = get_name(path, opts)?; check_name(name, opts)?; let mut src_paths_types = vec![]; - detect_source_paths_and_types(&path, name, &mut src_paths_types)?; + detect_source_paths_and_types(path, name, &mut src_paths_types)?; if src_paths_types.is_empty() { src_paths_types.push(plan_new_source_file(opts.kind.is_bin(), name.to_string())); @@ -444,7 +444,7 @@ fn mk(config: &Config, opts: &MkOptions) -> CargoResult<()> { match vcs { VersionControl::Git => { - if !fs::metadata(&path.join(".git")).is_ok() { + if fs::metadata(&path.join(".git")).is_err() { GitRepo::init(path, config.cwd())?; } let ignore = match fs::metadata(&path.join(".gitignore")) { @@ -454,7 +454,7 @@ fn mk(config: &Config, opts: &MkOptions) -> CargoResult<()> { paths::append(&path.join(".gitignore"), ignore.as_bytes())?; } VersionControl::Hg => { - if !fs::metadata(&path.join(".hg")).is_ok() { + if fs::metadata(&path.join(".hg")).is_err() { HgRepo::init(path, config.cwd())?; } let hgignore = match fs::metadata(&path.join(".hgignore")) { @@ -464,7 +464,7 @@ fn mk(config: &Config, opts: &MkOptions) -> CargoResult<()> { paths::append(&path.join(".hgignore"), hgignore.as_bytes())?; } VersionControl::Pijul => { - if !fs::metadata(&path.join(".pijul")).is_ok() { + if fs::metadata(&path.join(".pijul")).is_err() { PijulRepo::init(path, config.cwd())?; } let ignore = match fs::metadata(&path.join(".ignore")) { @@ -474,7 +474,7 @@ fn mk(config: &Config, opts: &MkOptions) -> CargoResult<()> { paths::append(&path.join(".ignore"), ignore.as_bytes())?; } VersionControl::Fossil => { - if !fs::metadata(&path.join(".fossil")).is_ok() { + if fs::metadata(&path.join(".fossil")).is_err() { FossilRepo::init(path, config.cwd())?; } } diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index 8bf04979c..0e29b30b8 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -47,7 +47,7 @@ pub fn package(ws: &Workspace, opts: &PackageOpts) -> CargoResult match xs.len() { 0 => ws.current()?, 1 => ws.members() - .find(|pkg| &*pkg.name() == xs[0]) + .find(|pkg| *pkg.name() == xs[0]) .ok_or_else(|| { format_err!("package `{}` is not a member of the workspace", xs[0]) })?, diff --git a/src/cargo/ops/cargo_rustc/context/compilation_files.rs b/src/cargo/ops/cargo_rustc/context/compilation_files.rs index 1f1d0cd3b..db844bcce 100644 --- a/src/cargo/ops/cargo_rustc/context/compilation_files.rs +++ b/src/cargo/ops/cargo_rustc/context/compilation_files.rs @@ -384,7 +384,7 @@ fn compute_metadata<'a, 'cfg>( && (unit.target.is_dylib() || unit.target.is_cdylib() || (unit.target.is_bin() && cx.target_triple().starts_with("wasm32-"))) && unit.pkg.package_id().source_id().is_path() - && !__cargo_default_lib_metadata.is_ok() + && __cargo_default_lib_metadata.is_err() { return None; } diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 463f5c4e2..33683c6b1 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -604,15 +604,15 @@ pub fn search( } let search_max_limit = 100; - if total_crates > u32::from(limit) && limit < search_max_limit { + if total_crates > limit && limit < search_max_limit { println!( "... and {} crates more (use --limit N to see more)", - total_crates - u32::from(limit) + total_crates - limit ); - } else if total_crates > u32::from(limit) && limit >= search_max_limit { + } else if total_crates > limit && limit >= search_max_limit { println!( "... and {} crates more (go to http://crates.io/search?q={} to see more)", - total_crates - u32::from(limit), + total_crates - limit, percent_encode(query.as_bytes(), QUERY_ENCODE_SET) ); } diff --git a/src/cargo/sources/git/utils.rs b/src/cargo/sources/git/utils.rs index 5ecb5b1b6..61d28a143 100644 --- a/src/cargo/sources/git/utils.rs +++ b/src/cargo/sources/git/utils.rs @@ -212,13 +212,11 @@ impl GitReference { })() .chain_err(|| format!("failed to find tag `{}`", s))?, GitReference::Branch(ref s) => { - (|| { - let b = repo.find_branch(s, git2::BranchType::Local)?; - b.get() - .target() - .ok_or_else(|| format_err!("branch `{}` did not have a target", s)) - })() - .chain_err(|| format!("failed to find branch `{}`", s))? + let b = repo.find_branch(s, git2::BranchType::Local) + .chain_err(|| format!("failed to find branch `{}`", s))?; + b.get() + .target() + .ok_or_else(|| format_err!("branch `{}` did not have a target", s))? } GitReference::Rev(ref s) => { let obj = repo.revparse_single(s)?; diff --git a/src/cargo/util/paths.rs b/src/cargo/util/paths.rs index 7cf540f8f..0cd231e70 100644 --- a/src/cargo/util/paths.rs +++ b/src/cargo/util/paths.rs @@ -237,12 +237,10 @@ fn _remove_file(p: &Path) -> CargoResult<()> { Err(e) => e, }; - if err.kind() == io::ErrorKind::PermissionDenied { - if set_not_readonly(p).unwrap_or(false) { - match fs::remove_file(p) { - Ok(()) => return Ok(()), - Err(e) => err = e, - } + if err.kind() == io::ErrorKind::PermissionDenied && set_not_readonly(p).unwrap_or(false) { + match fs::remove_file(p) { + Ok(()) => return Ok(()), + Err(e) => err = e, } } -- 2.30.2