Skip to content

Commit 73534f6

Browse files
committed
chore: Upgrade to 2025 edition
1 parent dfe05a9 commit 73534f6

81 files changed

Lines changed: 334 additions & 210 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ members = [
1313
[workspace.package]
1414
repository = "https://github.com/clap-rs/clap"
1515
license = "MIT OR Apache-2.0"
16-
edition = "2021"
16+
edition = "2024"
1717
rust-version = "1.85" # MSRV
1818
include = [
1919
"build.rs",

clap_bench/benches/complex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(elided_lifetimes_in_paths)] // needed for divan
22

3-
use clap::{arg, ArgMatches, Command};
3+
use clap::{ArgMatches, Command, arg};
44

55
macro_rules! create_app {
66
() => {{

clap_bench/benches/empty.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use clap::ArgMatches;
44
use clap::Command;
55

66
macro_rules! create_app {
7-
() => {{
8-
Command::new("claptests")
9-
}};
7+
() => {{ Command::new("claptests") }};
108
}
119

1210
#[divan::bench]

clap_bench/benches/ripgrep.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
use std::collections::HashMap;
99

10-
use clap::{value_parser, Arg, ArgAction, ArgMatches, Command};
10+
use clap::{Arg, ArgAction, ArgMatches, Command, value_parser};
1111
use lazy_static::lazy_static;
1212

1313
mod build {
14-
use super::{app_long, app_short, Command};
14+
use super::{Command, app_long, app_short};
1515

1616
#[divan::bench]
1717
fn short_help() -> Command {
@@ -41,7 +41,7 @@ mod render_help {
4141
}
4242

4343
mod startup {
44-
use super::{app_short, ArgMatches};
44+
use super::{ArgMatches, app_short};
4545

4646
#[divan::bench]
4747
fn simple() -> ArgMatches {

clap_bench/benches/rustup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn build() -> Command {
1212
}
1313

1414
mod startup {
15-
use super::{build_cli, ArgMatches};
15+
use super::{ArgMatches, build_cli};
1616

1717
#[divan::bench]
1818
fn empty() -> ArgMatches {

clap_bench/benches/simple.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(elided_lifetimes_in_paths)] // needed for divan
22

3-
use clap::{arg, ArgMatches, Command};
3+
use clap::{ArgMatches, Command, arg};
44

55
macro_rules! create_app {
66
() => {{
@@ -20,7 +20,7 @@ fn build() -> Command {
2020
}
2121

2222
mod startup {
23-
use super::{arg, ArgMatches, Command};
23+
use super::{ArgMatches, Command, arg};
2424

2525
#[divan::bench]
2626
fn flag() -> ArgMatches {

clap_builder/src/builder/arg.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ use std::{
1111

1212
// Internal
1313
use super::{ArgFlags, ArgSettings};
14-
#[cfg(feature = "unstable-ext")]
15-
use crate::builder::ext::Extension;
16-
use crate::builder::ext::Extensions;
14+
use crate::ArgAction;
15+
use crate::INTERNAL_ERROR_MSG;
16+
use crate::Id;
17+
use crate::ValueHint;
1718
use crate::builder::ArgPredicate;
1819
use crate::builder::IntoResettable;
1920
use crate::builder::OsStr;
@@ -22,11 +23,10 @@ use crate::builder::Str;
2223
use crate::builder::StyledStr;
2324
use crate::builder::Styles;
2425
use crate::builder::ValueRange;
26+
#[cfg(feature = "unstable-ext")]
27+
use crate::builder::ext::Extension;
28+
use crate::builder::ext::Extensions;
2529
use crate::util::AnyValueId;
26-
use crate::ArgAction;
27-
use crate::Id;
28-
use crate::ValueHint;
29-
use crate::INTERNAL_ERROR_MSG;
3030

3131
/// The abstract representation of a command line argument. Used to set all the options and
3232
/// relationships that define a valid argument for the program.
@@ -2065,8 +2065,9 @@ impl Arg {
20652065
/// # use clap_builder as clap;
20662066
/// # use std::env;
20672067
/// # use clap::{Command, Arg, ArgAction};
2068-
///
2068+
/// # unsafe {
20692069
/// env::set_var("MY_FLAG", "env");
2070+
/// # }
20702071
///
20712072
/// let m = Command::new("prog")
20722073
/// .arg(Arg::new("flag")
@@ -2094,8 +2095,10 @@ impl Arg {
20942095
/// # use clap::{Command, Arg, ArgAction};
20952096
/// # use clap::builder::FalseyValueParser;
20962097
///
2098+
/// # unsafe {
20972099
/// env::set_var("TRUE_FLAG", "true");
20982100
/// env::set_var("FALSE_FLAG", "0");
2101+
/// # }
20992102
///
21002103
/// let m = Command::new("prog")
21012104
/// .arg(Arg::new("true_flag")
@@ -2129,7 +2132,9 @@ impl Arg {
21292132
/// # use std::env;
21302133
/// # use clap::{Command, Arg, ArgAction};
21312134
///
2135+
/// # unsafe {
21322136
/// env::set_var("MY_FLAG", "env");
2137+
/// # }
21332138
///
21342139
/// let m = Command::new("prog")
21352140
/// .arg(Arg::new("flag")
@@ -2151,7 +2156,9 @@ impl Arg {
21512156
/// # use std::env;
21522157
/// # use clap::{Command, Arg, ArgAction};
21532158
///
2159+
/// # unsafe {
21542160
/// env::set_var("MY_FLAG", "env");
2161+
/// # }
21552162
///
21562163
/// let m = Command::new("prog")
21572164
/// .arg(Arg::new("flag")
@@ -2173,7 +2180,9 @@ impl Arg {
21732180
/// # use std::env;
21742181
/// # use clap::{Command, Arg, ArgAction};
21752182
///
2183+
/// # unsafe {
21762184
/// env::set_var("MY_FLAG_MULTI", "env1,env2");
2185+
/// # }
21772186
///
21782187
/// let m = Command::new("prog")
21792188
/// .arg(Arg::new("flag")

clap_builder/src/builder/command.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@ use std::ops::Index;
99
use std::path::Path;
1010

1111
// Internal
12-
use crate::builder::app_settings::{AppFlags, AppSettings};
13-
use crate::builder::arg_settings::ArgSettings;
14-
use crate::builder::ext::Extension;
15-
use crate::builder::ext::Extensions;
1612
use crate::builder::ArgAction;
1713
use crate::builder::IntoResettable;
1814
use crate::builder::PossibleValue;
1915
use crate::builder::Str;
2016
use crate::builder::StyledStr;
2117
use crate::builder::Styles;
18+
use crate::builder::app_settings::{AppFlags, AppSettings};
19+
use crate::builder::arg_settings::ArgSettings;
20+
use crate::builder::ext::Extension;
21+
use crate::builder::ext::Extensions;
2222
use crate::builder::{Arg, ArgGroup, ArgPredicate};
2323
use crate::error::ErrorKind;
2424
use crate::error::Result as ClapResult;
2525
use crate::mkeymap::MKeyMap;
2626
use crate::output::fmt::Stream;
27-
use crate::output::{fmt::Colorizer, write_help, Usage};
27+
use crate::output::{Usage, fmt::Colorizer, write_help};
2828
use crate::parser::{ArgMatcher, ArgMatches, Parser};
2929
use crate::util::ChildGraph;
30-
use crate::util::{color::ColorChoice, Id};
30+
use crate::util::{Id, color::ColorChoice};
3131
use crate::{Error, INTERNAL_ERROR_MSG};
3232

3333
#[cfg(debug_assertions)]
@@ -876,9 +876,13 @@ impl Command {
876876
let command = command.to_owned();
877877
debug!("Command::try_get_matches_from_mut: Parsed command {command} from argv");
878878

879-
debug!("Command::try_get_matches_from_mut: Reinserting command into arguments so subcommand parser matches it");
879+
debug!(
880+
"Command::try_get_matches_from_mut: Reinserting command into arguments so subcommand parser matches it"
881+
);
880882
raw_args.insert(&cursor, [&command]);
881-
debug!("Command::try_get_matches_from_mut: Clearing name and bin_name so that displayed command name starts with applet name");
883+
debug!(
884+
"Command::try_get_matches_from_mut: Clearing name and bin_name so that displayed command name starts with applet name"
885+
);
882886
self.name = "".into();
883887
self.bin_name = None;
884888
return self._do_parse(&mut raw_args, cursor);
@@ -4042,7 +4046,9 @@ impl Command {
40424046
.map(|id| self.find(id).expect(INTERNAL_ERROR_MSG)),
40434047
);
40444048
} else {
4045-
panic!("Command::get_arg_conflicts_with: The passed arg conflicts with an arg unknown to the cmd");
4049+
panic!(
4050+
"Command::get_arg_conflicts_with: The passed arg conflicts with an arg unknown to the cmd"
4051+
);
40464052
}
40474053
}
40484054
result
@@ -4696,11 +4702,12 @@ impl Command {
46964702
.map(|arg| arg.get_id().clone())
46974703
.collect();
46984704

4699-
debug_assert!(args_missing_help.is_empty(),
4700-
"Command::help_expected is enabled for the Command {}, but at least one of its arguments does not have either `help` or `long_help` set. List of such arguments: {}",
4701-
self.name,
4702-
args_missing_help.join(", ")
4703-
);
4705+
debug_assert!(
4706+
args_missing_help.is_empty(),
4707+
"Command::help_expected is enabled for the Command {}, but at least one of its arguments does not have either `help` or `long_help` set. List of such arguments: {}",
4708+
self.name,
4709+
args_missing_help.join(", ")
4710+
);
47044711
}
47054712

47064713
for sub_app in &self.subcommands {

0 commit comments

Comments
 (0)