]> git.proxmox.com Git - cargo.git/commitdiff
Fix more clippy warnings;
authorMatthias Krüger <matthias.krueger@famsik.de>
Wed, 6 Jan 2021 13:12:30 +0000 (14:12 +0100)
committerMatthias Krüger <matthias.krueger@famsik.de>
Wed, 6 Jan 2021 14:15:22 +0000 (15:15 +0100)
clippy::comparison_to_empty
clippy::needless_question_mark
clippy::needless_borrow
clippy::match_like_matches_macro
clippy::vec_init_then_push
clippy::redundant_clone
clippy::nonminimal_bool
clippy::ptr_arg

19 files changed:
src/cargo/core/compiler/build_context/target_info.rs
src/cargo/core/compiler/build_plan.rs
src/cargo/core/compiler/fingerprint.rs
src/cargo/core/compiler/job_queue.rs
src/cargo/core/compiler/mod.rs
src/cargo/core/package.rs
src/cargo/core/profiles.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_output_metadata.rs
src/cargo/ops/registry.rs
src/cargo/ops/tree/mod.rs
src/cargo/ops/vendor.rs
src/cargo/sources/config.rs
src/cargo/sources/git/source.rs
src/cargo/sources/git/utils.rs
src/cargo/util/config/mod.rs
src/cargo/util/config/target.rs
src/cargo/util/config/value.rs
src/cargo/util/paths.rs

index 53fe197707c23605b3d7fbfa4dee27658f302537..f37d0ef5bcf65a1d0e6b66d58f7f561edb2b0880 100644 (file)
@@ -408,13 +408,7 @@ impl TargetInfo {
 
         let error = str::from_utf8(&output.stderr).unwrap();
         let output = str::from_utf8(&output.stdout).unwrap();
-        Ok(parse_crate_type(
-            crate_type,
-            &process,
-            output,
-            error,
-            &mut output.lines(),
-        )?)
+        parse_crate_type(crate_type, &process, output, error, &mut output.lines())
     }
 
     /// Returns all the file types generated by rustc for the given mode/target_kind.
index b76e80287162684340088db9f4aaa19c9a1b1102..923894d076f3ed69989892aeadc5460395f53427 100644 (file)
@@ -7,7 +7,7 @@
 //! dependencies on other Invocations.
 
 use std::collections::BTreeMap;
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
 
 use serde::Serialize;
 
@@ -63,10 +63,10 @@ impl Invocation {
         }
     }
 
-    pub fn add_output(&mut self, path: &PathBuf, link: &Option<PathBuf>) {
-        self.outputs.push(path.clone());
+    pub fn add_output(&mut self, path: &Path, link: &Option<PathBuf>) {
+        self.outputs.push(path.to_path_buf());
         if let Some(ref link) = *link {
-            self.links.insert(link.clone(), path.clone());
+            self.links.insert(link.clone(), path.to_path_buf());
         }
     }
 
index 1f954006fea5326f666a968091adbb39607e7025..5077c33645f0e384aa82fb6f1d6f53db0ba36a32 100644 (file)
@@ -1432,9 +1432,9 @@ fn build_script_local_fingerprints(
 ) -> (
     Box<
         dyn FnOnce(
-            &BuildDeps,
-            Option<&dyn Fn() -> CargoResult<String>>,
-        ) -> CargoResult<Option<Vec<LocalFingerprint>>>
+                &BuildDeps,
+                Option<&dyn Fn() -> CargoResult<String>>,
+            ) -> CargoResult<Option<Vec<LocalFingerprint>>>
             + Send,
     >,
     bool,
index 880b0aa61756a6107ce17b7d88df5d7c67901295..aa78ef341f3e6a8a48768bfd941d1f1a829915a8 100644 (file)
@@ -915,7 +915,7 @@ impl<'cfg> DrainState<'cfg> {
                 // thread to run the job.
                 doit(JobState {
                     id,
-                    messages: messages.clone(),
+                    messages,
                     output: Some(cx.bcx.config),
                     rmeta_required: Cell::new(rmeta_required),
                     _marker: marker::PhantomData,
index 0263bfb749a8e451bb3250a86d53e95aa61b8431..34e92afba62b3917359c8093db2306ed7fb30b40 100644 (file)
@@ -397,15 +397,11 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
         current_id: PackageId,
         metadata: Option<Metadata>,
     ) {
-        let metadata = match metadata {
-            Some(metadata) => metadata,
-            None => {
-                return;
-            }
-        };
-        if let Some(output) = build_script_outputs.get(current_id, metadata) {
-            for &(ref name, ref value) in output.env.iter() {
-                rustc.env(name, value);
+        if let Some(metadata) = metadata {
+            if let Some(output) = build_script_outputs.get(current_id, metadata) {
+                for &(ref name, ref value) in output.env.iter() {
+                    rustc.env(name, value);
+                }
             }
         }
     }
@@ -492,7 +488,7 @@ fn add_plugin_deps(
     rustc: &mut ProcessBuilder,
     build_script_outputs: &BuildScriptOutputs,
     build_scripts: &BuildScripts,
-    root_output: &PathBuf,
+    root_output: &Path,
 ) -> CargoResult<()> {
     let var = util::dylib_path_envvar();
     let search_path = rustc.get_env(var).unwrap_or_default();
@@ -516,7 +512,7 @@ fn add_plugin_deps(
 // Strip off prefixes like "native=" or "framework=" and filter out directories
 // **not** inside our output directory since they are likely spurious and can cause
 // clashes with system shared libraries (issue #3366).
-fn filter_dynamic_search_path<'a, I>(paths: I, root_output: &PathBuf) -> Vec<PathBuf>
+fn filter_dynamic_search_path<'a, I>(paths: I, root_output: &Path) -> Vec<PathBuf>
 where
     I: Iterator<Item = &'a PathBuf>,
 {
index 88bc43c7311c31af30b8ee649e9fcb93a94ebb72..76bef34df139710b2785b3d8b718964c824fd9d2 100644 (file)
@@ -607,9 +607,8 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
     /// eventually be returned from `wait_for_download`. Returns `Some(pkg)` if
     /// the package is ready and doesn't need to be downloaded.
     pub fn start(&mut self, id: PackageId) -> CargoResult<Option<&'a Package>> {
-        Ok(self
-            .start_inner(id)
-            .chain_err(|| format!("failed to download `{}`", id))?)
+        self.start_inner(id)
+            .chain_err(|| format!("failed to download `{}`", id))
     }
 
     fn start_inner(&mut self, id: PackageId) -> CargoResult<Option<&'a Package>> {
index bab01f50cc842a746ccd3e0b8c2e61e7e27eafd8..9be09d847ad0df674244bd281d7a7e2b2746855a 100644 (file)
@@ -143,7 +143,7 @@ impl Profiles {
     fn add_root_profiles(
         profile_makers: &mut Profiles,
         profiles: &BTreeMap<InternedString, TomlProfile>,
-    )  {
+    ) {
         profile_makers.by_name.insert(
             InternedString::new("dev"),
             ProfileMaker::new(Profile::default_dev(), profiles.get("dev").cloned()),
index 86e281ec0f97a3d49621ccc40344eca598cbe312..8a53c5b9b5636990a1a4d5bf7c12469528fd227f 100644 (file)
@@ -282,7 +282,7 @@ pub fn compile_ws<'a>(
     let bcx = create_bcx(ws, options, &interner)?;
     if options.build_config.unit_graph {
         unit_graph::emit_serialized_unit_graph(&bcx.roots, &bcx.unit_graph)?;
-        return Ok(Compilation::new(&bcx)?);
+        return Compilation::new(&bcx);
     }
 
     let _p = profile::start("compiling");
index d4d911f17cd0e13ee7bd2bd8918fc579f3037e78..ed99602f72298efab4834b9baa8b4730ab768ebd 100644 (file)
@@ -120,7 +120,7 @@ fn build_resolve_graph(
         metadata_opts.all_features,
         !metadata_opts.no_default_features,
     );
-    let resolve_opts = ResolveOpts::new(/*dev_deps*/ true, requested_features.clone());
+    let resolve_opts = ResolveOpts::new(/*dev_deps*/ true, requested_features);
     let force_all = if metadata_opts.filter_platforms.is_empty() {
         crate::core::resolver::features::ForceAllTargets::Yes
     } else {
index 9589d379ab6f8e461fd5812c5b5d24b2f4ab4c75..afb1adbf9d20a5a9671a6f25d04486e2c179985d 100644 (file)
@@ -366,8 +366,8 @@ pub fn registry_configuration(
     // `registry.default` is handled in command-line parsing.
     let (index, token, process) = match registry {
         Some(registry) => {
-            validate_package_name(&registry, "registry name", "")?;
-            let index = Some(config.get_registry_index(&registry)?.to_string());
+            validate_package_name(registry, "registry name", "")?;
+            let index = Some(config.get_registry_index(registry)?.to_string());
             let token_key = format!("registries.{}.token", registry);
             let token = config.get_string(&token_key)?.map(|p| p.val);
             let process = if config.cli_unstable().credential_process {
@@ -471,7 +471,7 @@ fn registry(
     };
     let token = if validate_token {
         if index.is_some() {
-            if !token.is_some() {
+            if token.is_none() {
                 bail!("command-line argument --index requires --token to be specified");
             }
             token
index a9820e71ee591f8ca5a0470ca53ac787ebc5f2f4..3ab7da748ea9969e8bf5e63fa33e19d22e52c514 100644 (file)
@@ -143,7 +143,7 @@ pub fn build_and_print(ws: &Workspace<'_>, opts: &TreeOptions) -> CargoResult<()
         opts.all_features,
         !opts.no_default_features,
     );
-    let resolve_opts = ResolveOpts::new(/*dev_deps*/ true, requested_features.clone());
+    let resolve_opts = ResolveOpts::new(/*dev_deps*/ true, requested_features);
     let has_dev = if opts
         .edge_kinds
         .contains(&EdgeKind::Dep(DepKind::Development))
index 05bbb22523e5978030829aa5f0cb718c31f2c628..afaf6ff52a1be42265852a0a681185af35150d71 100644 (file)
@@ -338,7 +338,7 @@ fn cp_sources(
 
         paths::create_dir_all(dst.parent().unwrap())?;
 
-        let cksum = copy_and_checksum(&p, &dst, tmp_buf)?;
+        let cksum = copy_and_checksum(p, &dst, tmp_buf)?;
         cksums.insert(relative.to_str().unwrap().replace("\\", "/"), cksum);
     }
     Ok(())
index 71a9a7194c0c3b8fab42593259b3d6defb6c8cd3..2af108d21c9a28cfd184ab775e43258d5061eb21 100644 (file)
@@ -108,7 +108,7 @@ impl<'cfg> SourceConfigMap<'cfg> {
 
         let mut name = match self.id2name.get(&id) {
             Some(name) => name,
-            None => return Ok(id.load(self.config, yanked_whitelist)?),
+            None => return id.load(self.config, yanked_whitelist),
         };
         let mut cfg_loc = "";
         let orig_name = name;
@@ -130,7 +130,7 @@ impl<'cfg> SourceConfigMap<'cfg> {
                     name = s;
                     cfg_loc = c;
                 }
-                None if id == cfg.id => return Ok(id.load(self.config, yanked_whitelist)?),
+                None if id == cfg.id => return id.load(self.config, yanked_whitelist),
                 None => {
                     new_id = cfg.id.with_precise(id.precise().map(|s| s.to_string()));
                     break;
index 3e66dd3cda8f59ff0224699df10e9b79f77807a9..0723e360628cf95033adb1e2bada9a60bdc26b93 100644 (file)
@@ -66,7 +66,7 @@ fn ident(id: &SourceId) -> String {
         .and_then(|s| s.rev().next())
         .unwrap_or("");
 
-    let ident = if ident == "" { "_empty" } else { ident };
+    let ident = if ident.is_empty() { "_empty" } else { ident };
 
     format!("{}-{}", ident, short_hash(id.canonical_url()))
 }
index a520a92d193dc50a8acf020f03f8ccc5ca31dd00..bdb3638b61c2ddc5aaed665feb0625f361b8e5dd 100644 (file)
@@ -689,8 +689,7 @@ where
     // call our callback, `f`, in a loop here.
     if ssh_username_requested {
         debug_assert!(res.is_err());
-        let mut attempts = Vec::new();
-        attempts.push("git".to_string());
+        let mut attempts = vec![String::from("git")];
         if let Ok(s) = env::var("USER").or_else(|_| env::var("USERNAME")) {
             attempts.push(s);
         }
index a408ee78496f28500f3d7f8b08b715ebd5471bba..5cd6bd85232a470926d857960a1159da0aa8f7d3 100644 (file)
@@ -1174,17 +1174,17 @@ impl Config {
 
     pub fn http_config(&self) -> CargoResult<&CargoHttpConfig> {
         self.http_config
-            .try_borrow_with(|| Ok(self.get::<CargoHttpConfig>("http")?))
+            .try_borrow_with(|| self.get::<CargoHttpConfig>("http"))
     }
 
     pub fn net_config(&self) -> CargoResult<&CargoNetConfig> {
         self.net_config
-            .try_borrow_with(|| Ok(self.get::<CargoNetConfig>("net")?))
+            .try_borrow_with(|| self.get::<CargoNetConfig>("net"))
     }
 
     pub fn build_config(&self) -> CargoResult<&CargoBuildConfig> {
         self.build_config
-            .try_borrow_with(|| Ok(self.get::<CargoBuildConfig>("build")?))
+            .try_borrow_with(|| self.get::<CargoBuildConfig>("build"))
     }
 
     pub fn progress_config(&self) -> &ProgressConfig {
index 13b77e262d0afb1f59fc1cc2b546d893577eca87..e22cab92ee58a2394b096667867709fe90be1408 100644 (file)
@@ -77,7 +77,7 @@ pub(super) fn load_target_triple(config: &Config, triple: &str) -> CargoResult<T
     // Links do not support environment variables.
     let target_key = ConfigKey::from_str(&format!("target.{}", triple));
     let links_overrides = match config.get_table(&target_key)? {
-        Some(links) => parse_links_overrides(&target_key, links.val, &config)?,
+        Some(links) => parse_links_overrides(&target_key, links.val, config)?,
         None => BTreeMap::new(),
     };
     Ok(TargetConfig {
index a424ea4d290dceed011b7c7188af597565fe6c93..65b0bffe46b9b7648abc390dba219a7e874649b4 100644 (file)
@@ -78,12 +78,12 @@ impl Definition {
     ///
     /// CLI is preferred over environment, which is preferred over files.
     pub fn is_higher_priority(&self, other: &Definition) -> bool {
-        match (self, other) {
-            (Definition::Cli, Definition::Environment(_)) => true,
-            (Definition::Cli, Definition::Path(_)) => true,
-            (Definition::Environment(_), Definition::Path(_)) => true,
-            _ => false,
-        }
+        matches!(
+            (self, other),
+            (Definition::Cli, Definition::Environment(_))
+                | (Definition::Cli, Definition::Path(_))
+                | (Definition::Environment(_), Definition::Path(_))
+        )
     }
 }
 
index 9698ae2252ebda972d900177be6799f0076e2348..4a3e6cb103d316c0ea4963ab196ec23b5a99ab9f 100644 (file)
@@ -90,7 +90,7 @@ pub fn resolve_executable(exec: &Path) -> CargoResult<PathBuf> {
         let paths = env::var_os("PATH").ok_or_else(|| anyhow::format_err!("no PATH"))?;
         let candidates = env::split_paths(&paths).flat_map(|path| {
             let candidate = path.join(&exec);
-            let with_exe = if env::consts::EXE_EXTENSION == "" {
+            let with_exe = if env::consts::EXE_EXTENSION.is_empty() {
                 None
             } else {
                 Some(candidate.with_extension(env::consts::EXE_EXTENSION))