diff --git a/crates/cargo-test-support/src/paths.rs b/crates/cargo-test-support/src/paths.rs index 61f9c03aea4..f0f867b7aa3 100644 --- a/crates/cargo-test-support/src/paths.rs +++ b/crates/cargo-test-support/src/paths.rs @@ -127,10 +127,8 @@ impl CargoPathExt for Path { if let Err(e) = remove_dir_all::remove_dir_all(self) { panic!("failed to remove {:?}: {:?}", self, e) } - } else { - if let Err(e) = fs::remove_file(self) { - panic!("failed to remove {:?}: {:?}", self, e) - } + } else if let Err(e) = fs::remove_file(self) { + panic!("failed to remove {:?}: {:?}", self, e) } } diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index 53fe197707c..f37d0ef5bcf 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -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. diff --git a/src/cargo/core/compiler/build_plan.rs b/src/cargo/core/compiler/build_plan.rs index b76e8028716..923894d076f 100644 --- a/src/cargo/core/compiler/build_plan.rs +++ b/src/cargo/core/compiler/build_plan.rs @@ -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) { - self.outputs.push(path.clone()); + pub fn add_output(&mut self, path: &Path, link: &Option) { + 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()); } } diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index cf38449fcf1..3a32f02df3d 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -750,7 +750,7 @@ pub fn build_map(cx: &mut Context<'_, '_>) -> CargoResult<()> { // Load any dependency declarations from a previous run. if unit.mode.is_run_custom_build() { - parse_previous_explicit_deps(cx, unit)?; + parse_previous_explicit_deps(cx, unit); } // We want to invoke the compiler deterministically to be cache-friendly @@ -787,13 +787,12 @@ pub fn build_map(cx: &mut Context<'_, '_>) -> CargoResult<()> { } } - fn parse_previous_explicit_deps(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<()> { + fn parse_previous_explicit_deps(cx: &mut Context<'_, '_>, unit: &Unit) { let script_run_dir = cx.files().build_script_run_dir(unit); let output_file = script_run_dir.join("output"); let (prev_output, _) = prev_build_output(cx, unit); let deps = BuildDeps::new(&output_file, prev_output.as_ref()); cx.build_explicit_deps.insert(unit.clone(), deps); - Ok(()) } } diff --git a/src/cargo/core/compiler/job_queue.rs b/src/cargo/core/compiler/job_queue.rs index 6109f137c7c..aa78ef341f3 100644 --- a/src/cargo/core/compiler/job_queue.rs +++ b/src/cargo/core/compiler/job_queue.rs @@ -780,14 +780,12 @@ impl<'cfg> DrainState<'cfg> { if err_state.is_some() { // Already encountered one error. log::warn!("{:?}", new_err); + } else if !self.active.is_empty() { + crate::display_error(&new_err, shell); + drop(shell.warn("build failed, waiting for other jobs to finish...")); + *err_state = Some(anyhow::format_err!("build failed")); } else { - if !self.active.is_empty() { - crate::display_error(&new_err, shell); - drop(shell.warn("build failed, waiting for other jobs to finish...")); - *err_state = Some(anyhow::format_err!("build failed")); - } else { - *err_state = Some(new_err); - } + *err_state = Some(new_err); } } @@ -917,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, diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 7ac3842f4df..34e92afba62 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -24,7 +24,7 @@ use std::env; use std::ffi::{OsStr, OsString}; use std::fs::{self, File}; use std::io::{BufRead, Write}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::sync::Arc; use anyhow::Error; @@ -276,7 +276,7 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc) -> Car )?; add_plugin_deps(&mut rustc, &script_outputs, &build_scripts, &root_output)?; } - add_custom_env(&mut rustc, &script_outputs, current_id, script_metadata)?; + add_custom_env(&mut rustc, &script_outputs, current_id, script_metadata); } for output in outputs.iter() { @@ -396,17 +396,14 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc) -> Car build_script_outputs: &BuildScriptOutputs, current_id: PackageId, metadata: Option, - ) -> CargoResult<()> { - let metadata = match metadata { - Some(metadata) => metadata, - None => return Ok(()), - }; - 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); + } } } - Ok(()) } } @@ -491,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(); @@ -515,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 +fn filter_dynamic_search_path<'a, I>(paths: I, root_output: &Path) -> Vec where I: Iterator, { @@ -603,7 +600,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { rustdoc.arg("--cfg").arg(&format!("feature=\"{}\"", feat)); } - add_error_format_and_color(cx, &mut rustdoc, false)?; + add_error_format_and_color(cx, &mut rustdoc, false); if let Some(args) = cx.bcx.extra_args_for(unit) { rustdoc.args(args); @@ -725,11 +722,7 @@ fn add_cap_lints(bcx: &BuildContext<'_, '_>, unit: &Unit, cmd: &mut ProcessBuild /// intercepting messages like rmeta artifacts, etc. rustc includes a /// "rendered" field in the JSON message with the message properly formatted, /// which Cargo will extract and display to the user. -fn add_error_format_and_color( - cx: &Context<'_, '_>, - cmd: &mut ProcessBuilder, - pipelined: bool, -) -> CargoResult<()> { +fn add_error_format_and_color(cx: &Context<'_, '_>, cmd: &mut ProcessBuilder, pipelined: bool) { cmd.arg("--error-format=json"); let mut json = String::from("--json=diagnostic-rendered-ansi"); if pipelined { @@ -764,8 +757,6 @@ fn add_error_format_and_color( _ => (), } } - - Ok(()) } fn build_base_args( @@ -799,7 +790,7 @@ fn build_base_args( } add_path_args(bcx, unit, cmd); - add_error_format_and_color(cx, cmd, cx.rmeta_required(unit))?; + add_error_format_and_color(cx, cmd, cx.rmeta_required(unit)); if !test { for crate_type in crate_types.iter() { diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index 88bc43c7311..76bef34df13 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -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> { - 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> { diff --git a/src/cargo/core/profiles.rs b/src/cargo/core/profiles.rs index 0dc7266feaa..9be09d847ad 100644 --- a/src/cargo/core/profiles.rs +++ b/src/cargo/core/profiles.rs @@ -100,7 +100,7 @@ impl Profiles { requested_profile, }; - Self::add_root_profiles(&mut profile_makers, &profiles)?; + Self::add_root_profiles(&mut profile_makers, &profiles); // Merge with predefined profiles. use std::collections::btree_map::Entry; @@ -143,7 +143,7 @@ impl Profiles { fn add_root_profiles( profile_makers: &mut Profiles, profiles: &BTreeMap, - ) -> CargoResult<()> { + ) { profile_makers.by_name.insert( InternedString::new("dev"), ProfileMaker::new(Profile::default_dev(), profiles.get("dev").cloned()), @@ -153,7 +153,6 @@ impl Profiles { InternedString::new("release"), ProfileMaker::new(Profile::default_release(), profiles.get("release").cloned()), ); - Ok(()) } /// Returns the built-in profiles (not including dev/release, which are diff --git a/src/cargo/core/summary.rs b/src/cargo/core/summary.rs index 073d4b59496..7bd5f99dc41 100644 --- a/src/cargo/core/summary.rs +++ b/src/cargo/core/summary.rs @@ -108,7 +108,7 @@ impl Summary { if !weak_dep_features { for (feat_name, features) in self.features() { for fv in features { - if matches!(fv, FeatureValue::DepFeature{weak: true, ..}) { + if matches!(fv, FeatureValue::DepFeature { weak: true, .. }) { bail!( "optional dependency features with `?` syntax are only \ allowed on the nightly channel and requires the \ @@ -416,7 +416,14 @@ impl FeatureValue { /// Returns `true` if this feature explicitly used `dep:` syntax. pub fn has_dep_prefix(&self) -> bool { - matches!(self, FeatureValue::Dep{..} | FeatureValue::DepFeature{dep_prefix:true, ..}) + matches!( + self, + FeatureValue::Dep { .. } + | FeatureValue::DepFeature { + dep_prefix: true, + .. + } + ) } } diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 4a6adccdc83..e78814233b4 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -437,14 +437,14 @@ impl<'cfg> Workspace<'cfg> { /// Returns an error if `manifest_path` isn't actually a valid manifest or /// if some other transient error happens. fn find_root(&mut self, manifest_path: &Path) -> CargoResult> { - fn read_root_pointer(member_manifest: &Path, root_link: &str) -> CargoResult { + fn read_root_pointer(member_manifest: &Path, root_link: &str) -> PathBuf { let path = member_manifest .parent() .unwrap() .join(root_link) .join("Cargo.toml"); debug!("find_root - pointer {}", path.display()); - Ok(paths::normalize_path(&path)) + paths::normalize_path(&path) } { @@ -456,7 +456,7 @@ impl<'cfg> Workspace<'cfg> { } WorkspaceConfig::Member { root: Some(ref path_to_root), - } => return Ok(Some(read_root_pointer(manifest_path, path_to_root)?)), + } => return Ok(Some(read_root_pointer(manifest_path, path_to_root))), WorkspaceConfig::Member { root: None } => {} } } @@ -481,7 +481,7 @@ impl<'cfg> Workspace<'cfg> { root: Some(ref path_to_root), } => { debug!("find_root - found pointer"); - return Ok(Some(read_root_pointer(&ances_manifest_path, path_to_root)?)); + return Ok(Some(read_root_pointer(&ances_manifest_path, path_to_root))); } WorkspaceConfig::Member { .. } => {} } @@ -957,7 +957,7 @@ impl<'cfg> Workspace<'cfg> { if self.allows_new_cli_feature_behavior() { self.members_with_features_new(specs, requested_features) } else { - self.members_with_features_old(specs, requested_features) + Ok(self.members_with_features_old(specs, requested_features)) } } @@ -1067,7 +1067,7 @@ impl<'cfg> Workspace<'cfg> { &self, specs: &[PackageIdSpec], requested_features: &RequestedFeatures, - ) -> CargoResult> { + ) -> Vec<(&Package, RequestedFeatures)> { // Split off any features with the syntax `member-name/feature-name` into a map // so that those features can be applied directly to those workspace-members. let mut member_specific_features: HashMap<&str, BTreeSet> = HashMap::new(); @@ -1131,7 +1131,7 @@ impl<'cfg> Workspace<'cfg> { } } }); - Ok(ms.collect()) + ms.collect() } } diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 86e281ec0f9..8a53c5b9b56 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -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"); diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs index 1c7f5df9985..98b18cd1741 100644 --- a/src/cargo/ops/cargo_install.rs +++ b/src/cargo/ops/cargo_install.rs @@ -175,14 +175,12 @@ fn install_one( if let Some(krate) = krate { let vers = if let Some(vers_flag) = vers { Some(parse_semver_flag(vers_flag)?.to_string()) + } else if source_id.is_registry() { + // Avoid pre-release versions from crate.io + // unless explicitly asked for + Some(String::from("*")) } else { - if source_id.is_registry() { - // Avoid pre-release versions from crate.io - // unless explicitly asked for - Some(String::from("*")) - } else { - None - } + None }; Some(Dependency::parse_no_deprecated( krate, @@ -233,33 +231,25 @@ fn install_one( |path: &mut PathSource<'_>| path.read_packages(), config, )? + } else if let Some(dep) = dep { + let mut source = map.load(source_id, &HashSet::new())?; + if let Ok(Some(pkg)) = + installed_exact_package(dep.clone(), &mut source, config, opts, root, &dst, force) + { + let msg = format!( + "package `{}` is already installed, use --force to override", + pkg + ); + config.shell().status("Ignored", &msg)?; + return Ok(true); + } + select_dep_pkg(&mut source, dep, config, needs_update_if_source_is_index)? } else { - if let Some(dep) = dep { - let mut source = map.load(source_id, &HashSet::new())?; - if let Ok(Some(pkg)) = installed_exact_package( - dep.clone(), - &mut source, - config, - opts, - root, - &dst, - force, - ) { - let msg = format!( - "package `{}` is already installed, use --force to override", - pkg - ); - config.shell().status("Ignored", &msg)?; - return Ok(true); - } - select_dep_pkg(&mut source, dep, config, needs_update_if_source_is_index)? - } else { - bail!( - "must specify a crate to install from \ + bail!( + "must specify a crate to install from \ crates.io, or use --path or --git to \ specify alternate source" - ) - } + ) } }; @@ -336,15 +326,13 @@ fn install_one( if no_track { // Check for conflicts. no_track_duplicates()?; - } else { - if is_installed(&pkg, config, opts, &rustc, &target, root, &dst, force)? { - let msg = format!( - "package `{}` is already installed, use --force to override", - pkg - ); - config.shell().status("Ignored", &msg)?; - return Ok(false); - } + } else if is_installed(&pkg, config, opts, &rustc, &target, root, &dst, force)? { + let msg = format!( + "package `{}` is already installed, use --force to override", + pkg + ); + config.shell().status("Ignored", &msg)?; + return Ok(false); } config.shell().status("Installing", &pkg)?; diff --git a/src/cargo/ops/cargo_output_metadata.rs b/src/cargo/ops/cargo_output_metadata.rs index d4d911f17cd..ed99602f722 100644 --- a/src/cargo/ops/cargo_output_metadata.rs +++ b/src/cargo/ops/cargo_output_metadata.rs @@ -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 { diff --git a/src/cargo/ops/common_for_install_and_uninstall.rs b/src/cargo/ops/common_for_install_and_uninstall.rs index 9b4c87407b6..3ab77a50389 100644 --- a/src/cargo/ops/common_for_install_and_uninstall.rs +++ b/src/cargo/ops/common_for_install_and_uninstall.rs @@ -120,7 +120,7 @@ impl InstallTracker { serde_json::from_str(&contents) .chain_err(|| format_err!("invalid JSON found for metadata"))? }; - v2.sync_v1(&v1)?; + v2.sync_v1(&v1); Ok(v2) })() .chain_err(|| { @@ -367,7 +367,7 @@ impl CrateListingV2 { /// where v2 is in use, and a v1 update is made, then v2 is used again. /// i.e., `cargo +new install foo ; cargo +old install bar ; cargo +new install bar` /// For now, v1 is the source of truth, so its values are trusted over v2. - fn sync_v1(&mut self, v1: &CrateListingV1) -> CargoResult<()> { + fn sync_v1(&mut self, v1: &CrateListingV1) { // Make the `bins` entries the same. for (pkg_id, bins) in &v1.v1 { self.installs @@ -385,7 +385,6 @@ impl CrateListingV2 { for pkg_id in to_remove { self.installs.remove(&pkg_id); } - Ok(()) } fn package_for_bin(&self, bin_name: &str) -> Option { diff --git a/src/cargo/ops/lockfile.rs b/src/cargo/ops/lockfile.rs index 2409d2177ce..4cf82d0cee4 100644 --- a/src/cargo/ops/lockfile.rs +++ b/src/cargo/ops/lockfile.rs @@ -28,12 +28,12 @@ pub fn load_pkg_lockfile(ws: &Workspace<'_>) -> CargoResult> { /// Generate a toml String of Cargo.lock from a Resolve. pub fn resolve_to_string(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoResult { - let (_orig, out, _ws_root) = resolve_to_string_orig(ws, resolve)?; + let (_orig, out, _ws_root) = resolve_to_string_orig(ws, resolve); Ok(out) } pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoResult<()> { - let (orig, mut out, ws_root) = resolve_to_string_orig(ws, resolve)?; + let (orig, mut out, ws_root) = resolve_to_string_orig(ws, resolve); // If the lock file contents haven't changed so don't rewrite it. This is // helpful on read-only filesystems. @@ -87,7 +87,7 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoRes fn resolve_to_string_orig( ws: &Workspace<'_>, resolve: &mut Resolve, -) -> CargoResult<(Option, String, Filesystem)> { +) -> (Option, String, Filesystem) { // Load the original lock file if it exists. let ws_root = Filesystem::new(ws.root().to_path_buf()); let orig = ws_root.open_ro("Cargo.lock", ws.config(), "Cargo.lock file"); @@ -97,7 +97,7 @@ fn resolve_to_string_orig( Ok(s) }); let out = serialize_resolve(resolve, orig.as_ref().ok().map(|s| &**s)); - Ok((orig.ok(), out, ws_root)) + (orig.ok(), out, ws_root) } fn serialize_resolve(resolve: &Resolve, orig: Option<&str>) -> String { diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 9589d379ab6..afb1adbf9d2 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -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(®istry, "registry name", "")?; - let index = Some(config.get_registry_index(®istry)?.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 diff --git a/src/cargo/ops/tree/mod.rs b/src/cargo/ops/tree/mod.rs index a9820e71ee5..3ab7da748ea 100644 --- a/src/cargo/ops/tree/mod.rs +++ b/src/cargo/ops/tree/mod.rs @@ -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)) diff --git a/src/cargo/ops/vendor.rs b/src/cargo/ops/vendor.rs index 05bbb22523e..afaf6ff52a1 100644 --- a/src/cargo/ops/vendor.rs +++ b/src/cargo/ops/vendor.rs @@ -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(()) diff --git a/src/cargo/sources/config.rs b/src/cargo/sources/config.rs index 71a9a7194c0..2af108d21c9 100644 --- a/src/cargo/sources/config.rs +++ b/src/cargo/sources/config.rs @@ -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; diff --git a/src/cargo/sources/git/source.rs b/src/cargo/sources/git/source.rs index 3e66dd3cda8..0723e360628 100644 --- a/src/cargo/sources/git/source.rs +++ b/src/cargo/sources/git/source.rs @@ -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())) } diff --git a/src/cargo/sources/git/utils.rs b/src/cargo/sources/git/utils.rs index a520a92d193..bdb3638b61c 100644 --- a/src/cargo/sources/git/utils.rs +++ b/src/cargo/sources/git/utils.rs @@ -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); } diff --git a/src/cargo/util/config/mod.rs b/src/cargo/util/config/mod.rs index 6d04407aeea..5cd6bd85232 100644 --- a/src/cargo/util/config/mod.rs +++ b/src/cargo/util/config/mod.rs @@ -1174,17 +1174,17 @@ impl Config { pub fn http_config(&self) -> CargoResult<&CargoHttpConfig> { self.http_config - .try_borrow_with(|| Ok(self.get::("http")?)) + .try_borrow_with(|| self.get::("http")) } pub fn net_config(&self) -> CargoResult<&CargoNetConfig> { self.net_config - .try_borrow_with(|| Ok(self.get::("net")?)) + .try_borrow_with(|| self.get::("net")) } pub fn build_config(&self) -> CargoResult<&CargoBuildConfig> { self.build_config - .try_borrow_with(|| Ok(self.get::("build")?)) + .try_borrow_with(|| self.get::("build")) } pub fn progress_config(&self) -> &ProgressConfig { @@ -1698,13 +1698,11 @@ pub fn save_credentials( rtable.remove("token"); } } - } else { - if let Some(registry) = table.get_mut("registry") { - let reg_table = registry - .as_table_mut() - .ok_or_else(|| format_err!("expected `[registry]` to be a table"))?; - reg_table.remove("token"); - } + } else if let Some(registry) = table.get_mut("registry") { + let reg_table = registry + .as_table_mut() + .ok_or_else(|| format_err!("expected `[registry]` to be a table"))?; + reg_table.remove("token"); } } diff --git a/src/cargo/util/config/target.rs b/src/cargo/util/config/target.rs index 13b77e262d0..e22cab92ee5 100644 --- a/src/cargo/util/config/target.rs +++ b/src/cargo/util/config/target.rs @@ -77,7 +77,7 @@ pub(super) fn load_target_triple(config: &Config, triple: &str) -> CargoResult parse_links_overrides(&target_key, links.val, &config)?, + Some(links) => parse_links_overrides(&target_key, links.val, config)?, None => BTreeMap::new(), }; Ok(TargetConfig { diff --git a/src/cargo/util/config/value.rs b/src/cargo/util/config/value.rs index a424ea4d290..65b0bffe46b 100644 --- a/src/cargo/util/config/value.rs +++ b/src/cargo/util/config/value.rs @@ -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(_)) + ) } } diff --git a/src/cargo/util/paths.rs b/src/cargo/util/paths.rs index 9698ae2252e..4a3e6cb103d 100644 --- a/src/cargo/util/paths.rs +++ b/src/cargo/util/paths.rs @@ -90,7 +90,7 @@ pub fn resolve_executable(exec: &Path) -> CargoResult { 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))