Skip to content

Commit 2de5919

Browse files
committed
fix!: Prefer IntoIterator over &[]
The main breakinge change cases: - `&[char]`: now requires removing `&` - All other non-ID `&[_]`: hopefully clap-rs#1041 will make these non-breaking Fixes clap-rs#2870
1 parent dcfbee9 commit 2de5919

17 files changed

+165
-139
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
4242
`Command::disable_version_flag`) and mark the custom flags as `global(true)`.
4343
- Looking up a group in `ArgMatches` now returns the arg `Id`s, rather than the values.
4444
- Various `Arg`, `Command`, and `ArgGroup` calls were switched from accepting `&[]` to `[]` via `IntoIterator`
45+
- `Arg::short_aliases` and other builder functions that took `&[]` need the `&` dropped
4546
- *(help)* Make `DeriveDisplayOrder` the default and removed the setting. To sort help, set `next_display_order(None)` (#2808)
4647
- *(help)* Subcommand display order respects `Command::next_display_order` instead of `DeriveDisplayOrder` and using its own initial display order value (#2808)
4748
- *(env)* Parse `--help` and `--version` like any `ArgAction::SetTrue` flag (#3776)

Diff for: clap_bench/benches/03_complex.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ macro_rules! create_app {
1313
.arg(arg!(-o --option <opt> ... "tests options").required(false))
1414
.arg(arg!([positional] "tests positionals"))
1515
.arg(arg!(-f --flag ... "tests flags").global(true))
16-
.args(&[
16+
.args([
1717
arg!(flag2: -F "tests flags with exclusions")
1818
.conflicts_with("flag")
1919
.requires("option2"),
@@ -27,10 +27,10 @@ macro_rules! create_app {
2727
.value_parser(OPT3_VALS),
2828
arg!([positional3] ... "tests positionals with specific values")
2929
.value_parser(POS3_VALS),
30-
arg!(--multvals <s> "Tests multiple values not mult occs").required(false).value_names(&["one", "two"]),
30+
arg!(--multvals <s> "Tests multiple values not mult occs").required(false).value_names(["one", "two"]),
3131
arg!(
3232
--multvalsmo <s> "Tests multiple values, not mult occs"
33-
).required(false).value_names(&["one", "two"]),
33+
).required(false).value_names(["one", "two"]),
3434
arg!(--minvals2 <minvals> ... "Tests 2 min vals").num_args(2..).required(false),
3535
arg!(--maxvals3 <maxvals> ... "Tests 3 max vals").num_args(1..=3).required(false),
3636
])
@@ -109,14 +109,14 @@ pub fn build_from_builder(c: &mut Criterion) {
109109
Arg::new("multvals")
110110
.long("multvals")
111111
.help("Tests multiple values, not mult occs")
112-
.value_names(&["one", "two"]),
112+
.value_names(["one", "two"]),
113113
)
114114
.arg(
115115
Arg::new("multvalsmo")
116116
.long("multvalsmo")
117117
.action(ArgAction::Append)
118118
.help("Tests multiple values, not mult occs")
119-
.value_names(&["one", "two"]),
119+
.value_names(["one", "two"]),
120120
)
121121
.arg(
122122
Arg::new("minvals")

Diff for: clap_bench/benches/04_new_help.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn app_example3<'c>() -> Command<'c> {
4545
.short('d')
4646
.action(ArgAction::SetTrue),
4747
)
48-
.args(&[
48+
.args([
4949
Arg::new("config")
5050
.help("sets the config file to use")
5151
.action(ArgAction::Set)

Diff for: clap_derive/src/attrs.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ impl Attrs {
561561
static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy<Vec<&str>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
562562
iter_to_vals(#expr)
563563
});
564-
&*DEFAULT_VALUES.as_slice()
564+
DEFAULT_VALUES.iter().copied()
565565
}
566566
})
567567
} else {
@@ -582,7 +582,7 @@ impl Attrs {
582582
static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy<Vec<&str>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
583583
DEFAULT_STRINGS.iter().map(::std::string::String::as_str).collect()
584584
});
585-
&*DEFAULT_VALUES.as_slice()
585+
DEFAULT_VALUES.iter().copied()
586586
}
587587
})
588588
};
@@ -677,7 +677,7 @@ impl Attrs {
677677
static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy<Vec<&::std::ffi::OsStr>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
678678
iter_to_vals(#expr)
679679
});
680-
&*DEFAULT_VALUES.as_slice()
680+
DEFAULT_VALUES.iter().copied()
681681
}
682682
})
683683
} else {
@@ -698,7 +698,7 @@ impl Attrs {
698698
static DEFAULT_VALUES: clap::__macro_refs::once_cell::sync::Lazy<Vec<&::std::ffi::OsStr>> = clap::__macro_refs::once_cell::sync::Lazy::new(|| {
699699
DEFAULT_OS_STRINGS.iter().map(::std::ffi::OsString::as_os_str).collect()
700700
});
701-
&*DEFAULT_VALUES.as_slice()
701+
DEFAULT_VALUES.iter().copied()
702702
}
703703
})
704704
};

0 commit comments

Comments
 (0)