From 540b86a0505c70863141279fb0fa6aaf82e8522f Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 28 Aug 2025 09:19:52 -0500 Subject: [PATCH 1/2] style: Make clippy happy --- src/bin/set-version/set_version.rs | 26 +++--- src/bin/upgrade/upgrade.rs | 136 ++++++++++++++--------------- src/dependency.rs | 8 +- src/index.rs | 11 ++- src/manifest.rs | 39 ++++----- 5 files changed, 106 insertions(+), 114 deletions(-) diff --git a/src/bin/set-version/set_version.rs b/src/bin/set-version/set_version.rs index 66e74f0976..840d9bcaac 100644 --- a/src/bin/set-version/set_version.rs +++ b/src/bin/set-version/set_version.rs @@ -179,20 +179,20 @@ fn exec(args: VersionArgs) -> CargoResult<()> { if update_workspace_version { let mut ws_manifest = LocalManifest::try_new(&root_manifest_path)?; - if let Some(current) = ws_manifest.get_workspace_version() { - if let Some(next) = target.bump(¤t, metadata.as_deref())? { - shell_status( - "Upgrading", - &format!("workspace version from {current} to {next}"), - )?; - ws_manifest.set_workspace_version(&next); - changed = true; - if !dry_run { - ws_manifest.write()?; - } - - // Deferring `update_dependents` to the per-package logic + if let Some(current) = ws_manifest.get_workspace_version() + && let Some(next) = target.bump(¤t, metadata.as_deref())? + { + shell_status( + "Upgrading", + &format!("workspace version from {current} to {next}"), + )?; + ws_manifest.set_workspace_version(&next); + changed = true; + if !dry_run { + ws_manifest.write()?; } + + // Deferring `update_dependents` to the per-package logic } } diff --git a/src/bin/upgrade/upgrade.rs b/src/bin/upgrade/upgrade.rs index a22cad84ef..4d52f49419 100644 --- a/src/bin/upgrade/upgrade.rs +++ b/src/bin/upgrade/upgrade.rs @@ -349,76 +349,75 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> { None }; - if new_version_req.is_none() { - if let Some(Some(explicit_version_req)) = + if new_version_req.is_none() + && let Some(Some(explicit_version_req)) = selected_dependencies.get(&dependency.name) - { + { + if is_pinned_dep && !args.pinned.as_bool() { + // `--pinned` is required in case the user meant an unpinned version + // in the dependency tree + reason.get_or_insert(Reason::Pinned); + pinned_present = true; + } else { + new_version_req = Some(explicit_version_req.to_owned()) + } + } + + if new_version_req.is_none() + && let Some(latest_incompatible) = &latest_incompatible + { + let new_version: semver::Version = latest_incompatible.parse()?; + let req_candidate = + match cargo_edit::upgrade_requirement(&old_version_req, &new_version) { + Ok(Some(version_req)) => Some(version_req), + Err(_) => { + // Didn't know how to preserve existing format, so abandon it + Some(latest_incompatible.clone()) + } + _ => { + // Already at latest + None + } + }; + + if req_candidate.is_some() { if is_pinned_dep && !args.pinned.as_bool() { - // `--pinned` is required in case the user meant an unpinned version - // in the dependency tree + // `--pinned` is required for incompatible upgrades reason.get_or_insert(Reason::Pinned); pinned_present = true; + } else if !args.incompatible.as_bool() && !is_pinned_dep { + // `--incompatible` is required for non-pinned deps + reason.get_or_insert(Reason::Incompatible); + incompatible_present = true; } else { - new_version_req = Some(explicit_version_req.to_owned()) + new_version_req = req_candidate; } } } - if new_version_req.is_none() { - if let Some(latest_incompatible) = &latest_incompatible { - let new_version: semver::Version = latest_incompatible.parse()?; - let req_candidate = - match cargo_edit::upgrade_requirement(&old_version_req, &new_version) { - Ok(Some(version_req)) => Some(version_req), - Err(_) => { - // Didn't know how to preserve existing format, so abandon it - Some(latest_incompatible.clone()) - } - _ => { - // Already at latest - None - } - }; - - if req_candidate.is_some() { - if is_pinned_dep && !args.pinned.as_bool() { - // `--pinned` is required for incompatible upgrades - reason.get_or_insert(Reason::Pinned); - pinned_present = true; - } else if !args.incompatible.as_bool() && !is_pinned_dep { - // `--incompatible` is required for non-pinned deps - reason.get_or_insert(Reason::Incompatible); - incompatible_present = true; - } else { - new_version_req = req_candidate; + if new_version_req.is_none() + && let Some(latest_compatible) = &latest_compatible + { + // Compatible upgrades are allowed for pinned + let new_version: semver::Version = latest_compatible.parse()?; + let req_candidate = + match cargo_edit::upgrade_requirement(&old_version_req, &new_version) { + Ok(Some(version_req)) => Some(version_req), + Err(_) => { + // Do not change syntax for compatible upgrades + Some(old_version_req.clone()) } - } - } - } - - if new_version_req.is_none() { - if let Some(latest_compatible) = &latest_compatible { - // Compatible upgrades are allowed for pinned - let new_version: semver::Version = latest_compatible.parse()?; - let req_candidate = - match cargo_edit::upgrade_requirement(&old_version_req, &new_version) { - Ok(Some(version_req)) => Some(version_req), - Err(_) => { - // Do not change syntax for compatible upgrades - Some(old_version_req.clone()) - } - _ => { - // Already at latest - None - } - }; - - if req_candidate.is_some() { - if !args.compatible.as_bool() { - reason.get_or_insert(Reason::Compatible); - } else { - new_version_req = req_candidate; + _ => { + // Already at latest + None } + }; + + if req_candidate.is_some() { + if !args.compatible.as_bool() { + reason.get_or_insert(Reason::Compatible); + } else { + new_version_req = req_candidate; } } } @@ -787,14 +786,11 @@ impl Dep { .latest_version .as_ref() .and_then(|v| semver::Version::parse(v).ok()) + && let Some(new_version_req) = &self.new_version_req + && let Ok(new_version_req) = VersionReq::parse(new_version_req) + && !new_version_req.matches(&latest_version) { - if let Some(new_version_req) = &self.new_version_req { - if let Ok(new_version_req) = VersionReq::parse(new_version_req) { - if !new_version_req.matches(&latest_version) { - spec.set_fg(Some(Color::Red)); - } - } - } + spec.set_fg(Some(Color::Red)); } spec } @@ -846,12 +842,10 @@ impl Dep { .latest_version .as_ref() .and_then(|v| semver::Version::parse(v).ok()) + && let Some(old_version_req) = &self.old_version_req + && let Ok(old_version_req) = VersionReq::parse(old_version_req) { - if let Some(old_version_req) = &self.old_version_req { - if let Ok(old_version_req) = VersionReq::parse(old_version_req) { - return old_version_req.matches(&latest_version); - } - } + return old_version_req.matches(&latest_version); } true } diff --git a/src/dependency.rs b/src/dependency.rs index c2785d8279..a9df22642a 100644 --- a/src/dependency.rs +++ b/src/dependency.rs @@ -363,10 +363,10 @@ impl Dependency { } None => {} } - if table.contains_key("version") { - if let Some(r) = self.registry.as_deref() { - table.insert("registry", r.into()); - } + if table.contains_key("version") + && let Some(r) = self.registry.as_deref() + { + table.insert("registry", r.into()); } if self.rename.is_some() { diff --git a/src/index.rs b/src/index.rs index b65b570332..053281bdfe 100644 --- a/src/index.rs +++ b/src/index.rs @@ -243,13 +243,12 @@ impl RemoteIndex { if let Some(etag) = res .headers() .get(tame_index::external::reqwest::header::ETAG) + && let Ok(etag) = etag.to_str() { - if let Ok(etag) = etag.to_str() { - if let Some(i) = self.etags.iter().position(|(krate, _)| krate == name) { - etag.clone_into(&mut self.etags[i].1); - } else { - self.etags.push((name.to_owned(), etag.to_owned())); - } + if let Some(i) = self.etags.iter().position(|(krate, _)| krate == name) { + etag.clone_into(&mut self.etags[i].1); + } else { + self.etags.push((name.to_owned(), etag.to_owned())); } } diff --git a/src/manifest.rs b/src/manifest.rs index ab4f35a6df..eaf6852812 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -366,15 +366,14 @@ impl LocalManifest { /// Remove references to `dep_key` if its no longer present pub fn gc_dep(&mut self, dep_key: &str) { let status = self.dep_feature(dep_key); - if matches!(status, FeatureStatus::None | FeatureStatus::DepFeature) { - if let toml_edit::Item::Table(feature_table) = &mut self.data.as_table_mut()["features"] - { - for (_feature, mut activated_crates) in feature_table.iter_mut() { - if let toml_edit::Item::Value(toml_edit::Value::Array(feature_activations)) = - &mut activated_crates - { - remove_feature_activation(feature_activations, dep_key, status); - } + if matches!(status, FeatureStatus::None | FeatureStatus::DepFeature) + && let toml_edit::Item::Table(feature_table) = &mut self.data.as_table_mut()["features"] + { + for (_feature, mut activated_crates) in feature_table.iter_mut() { + if let toml_edit::Item::Value(toml_edit::Value::Array(feature_activations)) = + &mut activated_crates + { + remove_feature_activation(feature_activations, dep_key, status); } } } @@ -383,17 +382,17 @@ impl LocalManifest { fn dep_feature(&self, dep_key: &str) -> FeatureStatus { let mut status = FeatureStatus::None; for (_, tbl) in self.get_sections() { - if let toml_edit::Item::Table(tbl) = tbl { - if let Some(dep_item) = tbl.get(dep_key) { - let optional = dep_item.get("optional"); - let optional = optional.and_then(|i| i.as_value()); - let optional = optional.and_then(|i| i.as_bool()); - let optional = optional.unwrap_or(false); - if optional { - return FeatureStatus::Feature; - } else { - status = FeatureStatus::DepFeature; - } + if let toml_edit::Item::Table(tbl) = tbl + && let Some(dep_item) = tbl.get(dep_key) + { + let optional = dep_item.get("optional"); + let optional = optional.and_then(|i| i.as_value()); + let optional = optional.and_then(|i| i.as_bool()); + let optional = optional.unwrap_or(false); + if optional { + return FeatureStatus::Feature; + } else { + status = FeatureStatus::DepFeature; } } } From d93d0b8d3c271498f5ac7593fbdc360650d6d564 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 28 Aug 2025 09:25:14 -0500 Subject: [PATCH 2/2] style: Adopt epage/_rust lints --- Cargo.toml | 70 ++++++++++++++++++++++++++++++ src/bin/add/add.rs | 4 +- src/bin/add/cli.rs | 6 +-- src/bin/rm/cli.rs | 6 +-- src/bin/rm/rm.rs | 4 +- src/bin/set-version/cli.rs | 6 +-- src/bin/set-version/errors.rs | 4 +- src/bin/set-version/set_version.rs | 8 ++-- src/bin/set-version/version.rs | 10 ++--- src/bin/upgrade/cli.rs | 6 +-- src/bin/upgrade/upgrade.rs | 6 +-- src/crate_spec.rs | 2 +- src/dependency.rs | 2 +- src/index.rs | 2 +- src/lib.rs | 2 + src/manifest.rs | 10 ++--- src/metadata.rs | 2 +- src/registry.rs | 10 ++--- src/util.rs | 2 +- src/version.rs | 6 +-- 20 files changed, 120 insertions(+), 48 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6d4ece2226..a8fe2b896e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -110,3 +110,73 @@ set-version = ["cli"] cli = ["color", "clap"] color = ["concolor-control/auto"] test-external-apis = [] + +[lints.rust] +rust_2018_idioms = { level = "warn", priority = -1 } +unnameable_types = "warn" +unreachable_pub = "warn" +unsafe_op_in_unsafe_fn = "warn" +unused_lifetimes = "warn" +unused_macro_rules = "warn" +unused_qualifications = "warn" + +[lints.clippy] +bool_assert_comparison = "allow" +branches_sharing_code = "allow" +checked_conversions = "warn" +collapsible_else_if = "allow" +create_dir = "warn" +dbg_macro = "warn" +debug_assert_with_mut_call = "warn" +doc_markdown = "warn" +empty_enum = "warn" +enum_glob_use = "warn" +expl_impl_clone_on_copy = "warn" +explicit_deref_methods = "warn" +explicit_into_iter_loop = "warn" +fallible_impl_from = "warn" +filter_map_next = "warn" +flat_map_option = "warn" +float_cmp_const = "warn" +fn_params_excessive_bools = "warn" +from_iter_instead_of_collect = "warn" +if_same_then_else = "allow" +implicit_clone = "warn" +imprecise_flops = "warn" +inconsistent_struct_constructor = "warn" +inefficient_to_string = "warn" +infinite_loop = "warn" +invalid_upcast_comparisons = "warn" +large_digit_groups = "warn" +large_stack_arrays = "warn" +large_types_passed_by_value = "warn" +let_and_return = "allow" # sometimes good to name what you are returning +linkedlist = "warn" +lossy_float_literal = "warn" +macro_use_imports = "warn" +mem_forget = "warn" +mutex_integer = "warn" +needless_continue = "allow" +needless_for_each = "warn" +negative_feature_names = "warn" +path_buf_push_overwrite = "warn" +ptr_as_ptr = "warn" +rc_mutex = "warn" +redundant_feature_names = "warn" +ref_option_ref = "warn" +rest_pat_in_fully_bound_structs = "warn" +result_large_err = "allow" +same_functions_in_if_condition = "warn" +self_named_module_files = "allow" # false positive +semicolon_if_nothing_returned = "warn" +str_to_string = "warn" +string_add = "warn" +string_add_assign = "warn" +string_lit_as_bytes = "warn" +string_to_string = "warn" +todo = "warn" +trait_duplication_in_bounds = "warn" +uninlined_format_args = "warn" +verbose_file_reads = "warn" +wildcard_imports = "warn" +zero_sized_map_values = "warn" diff --git a/src/bin/add/add.rs b/src/bin/add/add.rs index 73c4b28d7f..e50369a661 100644 --- a/src/bin/add/add.rs +++ b/src/bin/add/add.rs @@ -16,7 +16,7 @@ Examples: #[command(override_usage = "\ cargo add [OPTIONS] [@] [+,...] ... cargo add [OPTIONS] [+,...] ...")] -pub struct AddArgs { +pub(crate) struct AddArgs { /// Reference to a package to add as a dependency /// /// You can reference a packages by:{n} @@ -146,7 +146,7 @@ pub struct AddArgs { } impl AddArgs { - pub fn exec(self) -> CargoResult<()> { + pub(crate) fn exec(self) -> CargoResult<()> { anyhow::bail!( "`cargo add` has been merged into cargo 1.62+ as of cargo-edit 0.10, either - Upgrade cargo, like with `rustup update` diff --git a/src/bin/add/cli.rs b/src/bin/add/cli.rs index f15f7e0b52..c25fd246d3 100644 --- a/src/bin/add/cli.rs +++ b/src/bin/add/cli.rs @@ -3,12 +3,12 @@ use clap::Parser; #[derive(Debug, Parser)] #[command(bin_name = "cargo")] -pub enum Command { +pub(crate) enum Command { Add(crate::add::AddArgs), } impl Command { - pub fn exec(self) -> CargoResult<()> { + pub(crate) fn exec(self) -> CargoResult<()> { match self { Self::Add(add) => add.exec(), } @@ -18,5 +18,5 @@ impl Command { #[test] fn verify_app() { use clap::CommandFactory; - Command::command().debug_assert() + Command::command().debug_assert(); } diff --git a/src/bin/rm/cli.rs b/src/bin/rm/cli.rs index 3d160a308f..255f3281c8 100644 --- a/src/bin/rm/cli.rs +++ b/src/bin/rm/cli.rs @@ -3,12 +3,12 @@ use clap::Parser; #[derive(Debug, Parser)] #[command(bin_name = "cargo")] -pub enum Command { +pub(crate) enum Command { Rm(crate::rm::RmArgs), } impl Command { - pub fn exec(self) -> CargoResult<()> { + pub(crate) fn exec(self) -> CargoResult<()> { match self { Self::Rm(add) => add.exec(), } @@ -18,5 +18,5 @@ impl Command { #[test] fn verify_app() { use clap::CommandFactory; - Command::command().debug_assert() + Command::command().debug_assert(); } diff --git a/src/bin/rm/rm.rs b/src/bin/rm/rm.rs index 9347dd379e..4c9bc8ccb8 100644 --- a/src/bin/rm/rm.rs +++ b/src/bin/rm/rm.rs @@ -5,7 +5,7 @@ use std::path::PathBuf; /// Remove a dependency from a Cargo.toml manifest file. #[derive(Debug, Args)] #[command(version)] -pub struct RmArgs { +pub(crate) struct RmArgs { /// Dependencies to be removed #[arg(value_name = "DEP_ID", required = true)] crates: Vec, @@ -44,7 +44,7 @@ pub struct RmArgs { } impl RmArgs { - pub fn exec(&self) -> CargoResult<()> { + pub(crate) fn exec(&self) -> CargoResult<()> { anyhow::bail!( "`cargo rm` has been merged into cargo 1.66+ as of cargo-edit 0.12, either - Upgrade cargo, like with `rustup update` diff --git a/src/bin/set-version/cli.rs b/src/bin/set-version/cli.rs index 70158ce1dd..d0af26fdbd 100644 --- a/src/bin/set-version/cli.rs +++ b/src/bin/set-version/cli.rs @@ -4,12 +4,12 @@ use clap::Parser; #[derive(Debug, Parser)] #[command(bin_name = "cargo")] #[command(styles = clap_cargo::style::CLAP_STYLING)] -pub enum Command { +pub(crate) enum Command { SetVersion(crate::set_version::VersionArgs), } impl Command { - pub fn exec(self) -> CargoResult<()> { + pub(crate) fn exec(self) -> CargoResult<()> { match self { Self::SetVersion(add) => add.exec(), } @@ -19,5 +19,5 @@ impl Command { #[test] fn verify_app() { use clap::CommandFactory; - Command::command().debug_assert() + Command::command().debug_assert(); } diff --git a/src/bin/set-version/errors.rs b/src/bin/set-version/errors.rs index 15bca470e3..1483752a6f 100644 --- a/src/bin/set-version/errors.rs +++ b/src/bin/set-version/errors.rs @@ -1,8 +1,8 @@ use std::fmt::Display; -pub use cargo_edit::CargoResult; +pub(crate) use cargo_edit::CargoResult; -pub use cargo_edit::Error; +pub(crate) use cargo_edit::Error; /// User requested to downgrade a crate pub(crate) fn version_downgrade_err(current: impl Display, requested: impl Display) -> Error { diff --git a/src/bin/set-version/set_version.rs b/src/bin/set-version/set_version.rs index 840d9bcaac..a235b353b2 100644 --- a/src/bin/set-version/set_version.rs +++ b/src/bin/set-version/set_version.rs @@ -4,7 +4,7 @@ use std::path::PathBuf; use cargo_edit::{LocalManifest, shell_status, shell_warn, upgrade_requirement}; use clap::Args; -use crate::errors::*; +use crate::errors::CargoResult; use crate::version::BumpLevel; use crate::version::TargetVersion; @@ -12,7 +12,7 @@ use crate::version::TargetVersion; #[derive(Debug, Args)] #[command(version)] #[command(group = clap::ArgGroup::new("ver").multiple(false))] -pub struct VersionArgs { +pub(crate) struct VersionArgs { /// Version to change manifests to #[arg(group = "ver")] target: Option, @@ -77,7 +77,7 @@ pub struct VersionArgs { } impl VersionArgs { - pub fn exec(self) -> CargoResult<()> { + pub(crate) fn exec(self) -> CargoResult<()> { exec(self) } } @@ -229,7 +229,7 @@ fn exec(args: VersionArgs) -> CargoResult<()> { &root_manifest_path, &workspace_members, dry_run, - )? + )?; } } diff --git a/src/bin/set-version/version.rs b/src/bin/set-version/version.rs index 254ade9ebc..ad85b3446f 100644 --- a/src/bin/set-version/version.rs +++ b/src/bin/set-version/version.rs @@ -2,16 +2,16 @@ use std::str::FromStr; use cargo_edit::VersionExt; -use crate::errors::*; +use crate::errors::{CargoResult, version_downgrade_err}; #[derive(Clone, Debug)] -pub enum TargetVersion { +pub(crate) enum TargetVersion { Relative(BumpLevel), Absolute(semver::Version), } impl TargetVersion { - pub fn bump( + pub(crate) fn bump( &self, current: &semver::Version, metadata: Option<&str>, @@ -56,7 +56,7 @@ impl Default for TargetVersion { } #[derive(Debug, Clone, Copy)] -pub enum BumpLevel { +pub(crate) enum BumpLevel { Major, Minor, Patch, @@ -87,7 +87,7 @@ impl FromStr for BumpLevel { } impl BumpLevel { - pub fn bump_version( + pub(crate) fn bump_version( self, version: &mut semver::Version, metadata: Option<&str>, diff --git a/src/bin/upgrade/cli.rs b/src/bin/upgrade/cli.rs index 084b3d15f8..d035e56735 100644 --- a/src/bin/upgrade/cli.rs +++ b/src/bin/upgrade/cli.rs @@ -4,12 +4,12 @@ use clap::Parser; #[derive(Debug, Parser)] #[command(bin_name = "cargo")] #[command(styles = clap_cargo::style::CLAP_STYLING)] -pub enum Command { +pub(crate) enum Command { Upgrade(crate::upgrade::UpgradeArgs), } impl Command { - pub fn exec(self) -> CargoResult<()> { + pub(crate) fn exec(self) -> CargoResult<()> { match self { Self::Upgrade(add) => add.exec(), } @@ -19,5 +19,5 @@ impl Command { #[test] fn verify_app() { use clap::CommandFactory; - Command::command().debug_assert() + Command::command().debug_assert(); } diff --git a/src/bin/upgrade/upgrade.rs b/src/bin/upgrade/upgrade.rs index 4d52f49419..1afdfcf9f7 100644 --- a/src/bin/upgrade/upgrade.rs +++ b/src/bin/upgrade/upgrade.rs @@ -17,7 +17,7 @@ use termcolor::{Color, ColorSpec}; /// Upgrade dependency version requirements in Cargo.toml manifest files #[derive(Debug, Args)] #[command(version)] -pub struct UpgradeArgs { +pub(crate) struct UpgradeArgs { /// Print changes to be made without making them. #[arg(long, short = 'n')] dry_run: bool, @@ -112,7 +112,7 @@ pub struct UpgradeArgs { } impl UpgradeArgs { - pub fn exec(self) -> CargoResult<()> { + pub(crate) fn exec(self) -> CargoResult<()> { exec(self) } @@ -359,7 +359,7 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> { reason.get_or_insert(Reason::Pinned); pinned_present = true; } else { - new_version_req = Some(explicit_version_req.to_owned()) + new_version_req = Some(explicit_version_req.to_owned()); } } diff --git a/src/crate_spec.rs b/src/crate_spec.rs index 047b0ada5c..4eca607690 100644 --- a/src/crate_spec.rs +++ b/src/crate_spec.rs @@ -1,5 +1,5 @@ //! Crate name parsing. -use super::errors::*; +use super::errors::{CargoResult, Context, Error}; /// User-specified crate /// diff --git a/src/dependency.rs b/src/dependency.rs index a9df22642a..a6074fb9c9 100644 --- a/src/dependency.rs +++ b/src/dependency.rs @@ -391,7 +391,7 @@ impl Dependency { } /// Modify existing entry to match this dependency - pub fn update_toml(&self, crate_root: &Path, key: &mut KeyMut, item: &mut toml_edit::Item) { + pub fn update_toml(&self, crate_root: &Path, key: &mut KeyMut<'_>, item: &mut toml_edit::Item) { if str_or_1_len_table(item) { // Nothing to preserve *item = self.to_toml(crate_root); diff --git a/src/index.rs b/src/index.rs index 053281bdfe..bab4955835 100644 --- a/src/index.rs +++ b/src/index.rs @@ -3,7 +3,7 @@ use tame_index::utils::flock::FileLock; use url::Url; -use super::errors::*; +use super::errors::{CargoResult, Context}; #[derive(Default, Debug, Clone, Copy, PartialEq, Eq)] pub enum CertsSource { diff --git a/src/lib.rs b/src/lib.rs index dd96b2b46f..9de1793644 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,9 +34,11 @@ mod version; pub use crate_spec::CrateSpec; pub use dependency::Dependency; +pub use dependency::GitSource; pub use dependency::PathSource; pub use dependency::RegistrySource; pub use dependency::Source; +pub use dependency::WorkspaceSource; pub use errors::*; pub use fetch::{RustVersion, find_compatible_version, find_latest_version}; pub use index::*; diff --git a/src/manifest.rs b/src/manifest.rs index eaf6852812..d4cb2e04e1 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -5,11 +5,11 @@ use std::{env, str}; use semver::Version; -use super::errors::*; +use super::errors::{CargoResult, Context, non_existent_dependency_err, non_existent_table_err}; use super::metadata::find_manifest_path; #[derive(PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Debug, Copy)] -pub enum DepKind { +pub(crate) enum DepKind { Normal, Development, Build, @@ -17,7 +17,7 @@ pub enum DepKind { /// Dependency table to add dep to #[derive(Clone, Debug, PartialEq, Eq)] -pub struct DepTable { +pub(crate) struct DepTable { kind: DepKind, target: Option, } @@ -103,7 +103,7 @@ impl Manifest { .map(|t| t.is_table_like()) .unwrap_or(false) { - sections.push((table.clone(), self.data[dependency_type].clone())) + sections.push((table.clone(), self.data[dependency_type].clone())); } // ... and in `target..(build-/dev-)dependencies`. @@ -505,6 +505,6 @@ fn overwrite_value(item: &mut toml_edit::Item, value: impl Into bool { +pub(crate) fn str_or_1_len_table(item: &toml_edit::Item) -> bool { item.is_str() || item.as_table_like().map(|t| t.len() == 1).unwrap_or(false) } diff --git a/src/metadata.rs b/src/metadata.rs index 48940f0fae..d91d3e1a26 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -1,4 +1,4 @@ -use super::errors::*; +use super::errors::{CargoResult, Context}; use cargo_metadata::Package; use std::path::Path; diff --git a/src/registry.rs b/src/registry.rs index 3d53ec36e6..12706dae29 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -1,4 +1,4 @@ -use super::errors::*; +use super::errors::{CargoResult, Context}; use std::collections::HashMap; use std::path::Path; use url::Url; @@ -68,7 +68,7 @@ pub fn registry_url(manifest_path: &Path, registry: Option<&str>) -> CargoResult let mut source = registries.remove(CRATES_IO_REGISTRY).unwrap_or_default(); source .registry - .get_or_insert_with(|| CRATES_IO_INDEX.to_string()); + .get_or_insert_with(|| CRATES_IO_INDEX.to_owned()); source } Some(r) => registries @@ -85,7 +85,7 @@ pub fn registry_url(manifest_path: &Path, registry: Option<&str>) -> CargoResult if is_crates_io { source .registry - .get_or_insert_with(|| CRATES_IO_INDEX.to_string()); + .get_or_insert_with(|| CRATES_IO_INDEX.to_owned()); } } @@ -122,7 +122,7 @@ mod code_from_cargo { #![allow(dead_code)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] - pub enum Kind { + pub(super) enum Kind { Git(GitReference), Path, Registry, @@ -131,7 +131,7 @@ mod code_from_cargo { } #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] - pub enum GitReference { + pub(super) enum GitReference { Tag(String), Branch(String), Rev(String), diff --git a/src/util.rs b/src/util.rs index c490a42b71..f6e20eb978 100644 --- a/src/util.rs +++ b/src/util.rs @@ -15,7 +15,7 @@ pub fn colorize_stderr() -> ColorChoice { } /// Whether to color logged output -pub fn colorize_stdout() -> ColorChoice { +pub(crate) fn colorize_stdout() -> ColorChoice { if concolor_control::get(concolor_control::Stream::Stdout).color() { ColorChoice::Always } else { diff --git a/src/version.rs b/src/version.rs index 28e69aa853..f5713b9432 100644 --- a/src/version.rs +++ b/src/version.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -use super::errors::*; +use super::errors::{CargoResult, invalid_release_level, unsupported_version_req}; /// Additional version functionality pub trait VersionExt { @@ -143,7 +143,7 @@ fn prerelease_id_version(version: &semver::Version) -> CargoResult CargoResult> { - let req_text = req.to_string(); + let req_text = req.to_owned(); let raw_req = semver::VersionReq::parse(&req_text) .expect("semver to generate valid version requirements"); if raw_req.comparators.is_empty() { @@ -167,7 +167,7 @@ pub fn upgrade_requirement(req: &str, version: &semver::Version) -> CargoResult< assert!( new_req.matches(version), "Invalid req created: {new_req_text}" - ) + ); } if new_req_text == req_text { Ok(None)