Skip to content

Commit

Permalink
refactor: Migrate to Edition 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Feb 20, 2025
1 parent 8b080f5 commit 0833451
Show file tree
Hide file tree
Showing 30 changed files with 51 additions and 71 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resolver = "2"
[workspace.package]
repository = "https://github.com/crate-ci/cargo-release"
license = "MIT OR Apache-2.0"
edition = "2021"
edition = "2024"
rust-version = "1.85" # MSRV
include = [
"build.rs",
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ pub enum Command {
impl Command {
pub fn args(&self) -> Vec<&str> {
match self {
Command::Line(ref s) => vec![s.as_str()],
Command::Args(ref a) => a.iter().map(|s| s.as_str()).collect(),
Command::Line(s) => vec![s.as_str()],
Command::Args(a) => a.iter().map(|s| s.as_str()).collect(),
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions src/ops/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,7 @@ fn upgrade_req(
log::debug!("unsupported dependency {}", name);
return false;
};
let existing_req = if let Ok(existing_req) = semver::VersionReq::parse(existing_req_str) {
existing_req
} else {
let Ok(existing_req) = semver::VersionReq::parse(existing_req_str) else {
log::debug!("unsupported dependency req {}={}", name, existing_req_str);
return false;
};
Expand Down Expand Up @@ -461,11 +459,7 @@ pub fn sort_workspace(ws_meta: &cargo_metadata::Metadata) -> Vec<&cargo_metadata
.iter()
.all(|info| info.kind == cargo_metadata::DependencyKind::Development);

if dev_only {
None
} else {
Some(&dep.pkg)
}
if dev_only { None } else { Some(&dep.pkg) }
});

Some((&n.id, non_dev_pkgs.collect()))
Expand Down
2 changes: 1 addition & 1 deletion src/ops/shell.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::io::{stdin, stdout, Write};
use std::io::{Write, stdin, stdout};

use anyhow::Context as _;
use clap::builder::styling::Style;
Expand Down
14 changes: 9 additions & 5 deletions src/steps/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,21 @@ pub fn changes(
CommitStatus::Ignore => None,
};
if let Some(suggested) = suggested {
let _ = crate::ops::shell::note(format!("to update the version, run `cargo release version -p {crate_name} {suggested}`"));
let _ = crate::ops::shell::note(format!(
"to update the version, run `cargo release version -p {crate_name} {suggested}`"
));
} else if unbumped {
let _ = crate::ops::shell::note(format!("to update the version, run `cargo release version -p {crate_name} <LEVEL|VERSION>`"));
let _ = crate::ops::shell::note(format!(
"to update the version, run `cargo release version -p {crate_name} <LEVEL|VERSION>`"
));
}
}
}
} else {
log::debug!(
"Cannot detect changes for {} because no tag was found. Try setting `--prev-tag-name <TAG>`.",
crate_name,
);
"Cannot detect changes for {} because no tag was found. Try setting `--prev-tag-name <TAG>`.",
crate_name,
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/steps/commit.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::config;
use crate::error::CliError;
use crate::ops::git;
use crate::ops::replace::{Template, NOW};
use crate::ops::replace::{NOW, Template};
use crate::steps::plan;

/// Commit the specified packages
Expand Down
4 changes: 2 additions & 2 deletions src/steps/config.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::io::Write;

use crate::config::load_package_config;
use crate::config::load_workspace_config;
use crate::config::Config;
use crate::config::ConfigArgs;
use crate::config::load_package_config;
use crate::config::load_workspace_config;
use crate::error::CliError;

/// Dump workspace configuration
Expand Down
6 changes: 2 additions & 4 deletions src/steps/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::path::Path;
use crate::error::CliError;
use crate::ops::cmd;
use crate::ops::git;
use crate::ops::replace::{Template, NOW};
use crate::ops::replace::{NOW, Template};
use crate::steps::plan;

/// Run pre-release hooks
Expand Down Expand Up @@ -70,9 +70,7 @@ impl HookStep {

let (_selected_pkgs, excluded_pkgs) = self.workspace.partition_packages(&ws_meta);
for excluded_pkg in excluded_pkgs {
let pkg = if let Some(pkg) = pkgs.get_mut(&excluded_pkg.id) {
pkg
} else {
let Some(pkg) = pkgs.get_mut(&excluded_pkg.id) else {
// Either not in workspace or marked as `release = false`.
continue;
};
Expand Down
14 changes: 7 additions & 7 deletions src/steps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,16 +373,16 @@ pub fn warn_changed(
}
} else {
log::debug!(
"cannot detect changes for {} because tag {} is missing. Try setting `--prev-tag-name <TAG>`.",
crate_name,
prior_tag_name
);
"cannot detect changes for {} because tag {} is missing. Try setting `--prev-tag-name <TAG>`.",
crate_name,
prior_tag_name
);
}
} else {
log::debug!(
"cannot detect changes for {} because no tag was found. Try setting `--prev-tag-name <TAG>`.",
crate_name,
);
"cannot detect changes for {} because no tag was found. Try setting `--prev-tag-name <TAG>`.",
crate_name,
);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/steps/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ impl OwnerStep {

let (_selected_pkgs, excluded_pkgs) = self.workspace.partition_packages(&ws_meta);
for excluded_pkg in excluded_pkgs {
let pkg = if let Some(pkg) = pkgs.get_mut(&excluded_pkg.id) {
pkg
} else {
let Some(pkg) = pkgs.get_mut(&excluded_pkg.id) else {
// Either not in workspace or marked as `release = false`.
continue;
};
Expand Down
4 changes: 1 addition & 3 deletions src/steps/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ impl PublishStep {

let (_selected_pkgs, excluded_pkgs) = self.workspace.partition_packages(&ws_meta);
for excluded_pkg in excluded_pkgs {
let pkg = if let Some(pkg) = pkgs.get_mut(&excluded_pkg.id) {
pkg
} else {
let Some(pkg) = pkgs.get_mut(&excluded_pkg.id) else {
// Either not in workspace or marked as `release = false`.
continue;
};
Expand Down
4 changes: 1 addition & 3 deletions src/steps/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ impl PushStep {

let (_selected_pkgs, excluded_pkgs) = self.workspace.partition_packages(&ws_meta);
for excluded_pkg in excluded_pkgs {
let pkg = if let Some(pkg) = pkgs.get_mut(&excluded_pkg.id) {
pkg
} else {
let Some(pkg) = pkgs.get_mut(&excluded_pkg.id) else {
// Either not in workspace or marked as `release = false`.
continue;
};
Expand Down
8 changes: 2 additions & 6 deletions src/steps/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ impl ReleaseStep {

let (_selected_pkgs, excluded_pkgs) = self.workspace.partition_packages(&ws_meta);
for excluded_pkg in &excluded_pkgs {
let pkg = if let Some(pkg) = pkgs.get_mut(&excluded_pkg.id) {
pkg
} else {
let Some(pkg) = pkgs.get_mut(&excluded_pkg.id) else {
// Either not in workspace or marked as `release = false`.
continue;
};
Expand Down Expand Up @@ -154,9 +152,7 @@ impl ReleaseStep {
let pkgs = plan::plan(pkgs)?;

for excluded_pkg in &excluded_pkgs {
let pkg = if let Some(pkg) = pkgs.get(&excluded_pkg.id) {
pkg
} else {
let Some(pkg) = pkgs.get(&excluded_pkg.id) else {
// Either not in workspace or marked as `release = false`.
continue;
};
Expand Down
6 changes: 2 additions & 4 deletions src/steps/replace.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::error::CliError;
use crate::ops::git;
use crate::ops::replace::{do_file_replacements, Template, NOW};
use crate::ops::replace::{NOW, Template, do_file_replacements};
use crate::steps::plan;

/// Perform pre-release replacements
Expand Down Expand Up @@ -66,9 +66,7 @@ impl ReplaceStep {

let (_selected_pkgs, excluded_pkgs) = self.workspace.partition_packages(&ws_meta);
for excluded_pkg in excluded_pkgs {
let pkg = if let Some(pkg) = pkgs.get_mut(&excluded_pkg.id) {
pkg
} else {
let Some(pkg) = pkgs.get_mut(&excluded_pkg.id) else {
// Either not in workspace or marked as `release = false`.
continue;
};
Expand Down
6 changes: 2 additions & 4 deletions src/steps/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::collections::HashSet;

use crate::error::CliError;
use crate::ops::git;
use crate::ops::replace::Template;
use crate::ops::replace::NOW;
use crate::ops::replace::Template;
use crate::steps::plan;

/// Tag the released commits
Expand Down Expand Up @@ -69,9 +69,7 @@ impl TagStep {

let (_selected_pkgs, excluded_pkgs) = self.workspace.partition_packages(&ws_meta);
for excluded_pkg in excluded_pkgs {
let pkg = if let Some(pkg) = pkgs.get_mut(&excluded_pkg.id) {
pkg
} else {
let Some(pkg) = pkgs.get_mut(&excluded_pkg.id) else {
// Either not in workspace or marked as `release = false`.
continue;
};
Expand Down
4 changes: 1 addition & 3 deletions src/steps/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ impl VersionStep {

let (_selected_pkgs, excluded_pkgs) = self.workspace.partition_packages(&ws_meta);
for excluded_pkg in excluded_pkgs {
let pkg = if let Some(pkg) = pkgs.get_mut(&excluded_pkg.id) {
pkg
} else {
let Some(pkg) = pkgs.get_mut(&excluded_pkg.id) else {
// Either not in workspace or marked as `release = false`.
continue;
};
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/version/downgrade_error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;

use crate::CargoCommand;
use crate::git_from;
use crate::init_registry;
use crate::CargoCommand;

#[cargo_test]
fn case() {
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/version/dry_run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;

use crate::CargoCommand;
use crate::git_from;
use crate::init_registry;
use crate::CargoCommand;

#[cargo_test]
fn case() {
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/version/ignore_dependent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;

use crate::CargoCommand;
use crate::git_from;
use crate::init_registry;
use crate::CargoCommand;

#[cargo_test]
fn case() {
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/version/set_absolute_version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;

use crate::CargoCommand;
use crate::git_from;
use crate::init_registry;
use crate::CargoCommand;

#[cargo_test]
fn case() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;

use crate::CargoCommand;
use crate::git_from;
use crate::init_registry;
use crate::CargoCommand;

#[cargo_test]
fn case() {
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/version/set_relative_version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;

use crate::CargoCommand;
use crate::git_from;
use crate::init_registry;
use crate::CargoCommand;

#[cargo_test]
fn case() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;

use crate::CargoCommand;
use crate::git_from;
use crate::init_registry;
use crate::CargoCommand;

#[cargo_test]
fn case() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;

use crate::CargoCommand;
use crate::git_from;
use crate::init_registry;
use crate::CargoCommand;

#[cargo_test]
fn case() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;

use crate::CargoCommand;
use crate::git_from;
use crate::init_registry;
use crate::CargoCommand;

#[cargo_test]
fn case() {
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/version/upgrade_workspace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;

use crate::CargoCommand;
use crate::git_from;
use crate::init_registry;
use crate::CargoCommand;

#[cargo_test]
fn case() {
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/version/virtual_workspace_deps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;

use crate::CargoCommand;
use crate::git_from;
use crate::init_registry;
use crate::CargoCommand;

#[cargo_test]
fn case() {
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/version/workspace_deps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;

use crate::CargoCommand;
use crate::git_from;
use crate::init_registry;
use crate::CargoCommand;

#[cargo_test]
fn case() {
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/version/workspace_version_exclude/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;

use crate::CargoCommand;
use crate::git_from;
use crate::init_registry;
use crate::CargoCommand;

#[cargo_test]
fn case() {
Expand Down
Loading

0 comments on commit 0833451

Please sign in to comment.