diff --git a/clap_complete/src/shells/bash.rs b/clap_complete/src/shells/bash.rs index 5db6693da3a..22ad400e4f4 100644 --- a/clap_complete/src/shells/bash.rs +++ b/clap_complete/src/shells/bash.rs @@ -59,7 +59,7 @@ impl Generator for Bash { complete -F _{name} -o bashdefault -o default {name} ", name = bin_name, - cmd = bin_name.replace("-", "__"), + cmd = bin_name.replace('-', "__"), name_opts = all_options_for_path(app, bin_name), name_opts_details = option_details_for_path(app, bin_name), subcmds = all_subcommands(app), @@ -88,7 +88,7 @@ fn all_subcommands(app: &App) -> String { cmd+=\"__{fn_name}\" ;;", name = sc, - fn_name = sc.replace("-", "__") + fn_name = sc.replace('-', "__") ) })); @@ -101,7 +101,7 @@ fn subcommand_details(app: &App) -> String { let mut subcmd_dets = vec![String::new()]; let mut scs = utils::all_subcommands(app) .iter() - .map(|x| x.1.replace(" ", "__")) + .map(|x| x.1.replace(' ', "__")) .collect::>(); scs.sort(); @@ -122,7 +122,7 @@ fn subcommand_details(app: &App) -> String { COMPREPLY=( $(compgen -W \"${{opts}}\" -- \"${{cur}}\") ) return 0 ;;", - subcmd = sc.replace("-", "__"), + subcmd = sc.replace('-', "__"), sc_opts = all_options_for_path(app, &*sc), level = sc.split("__").map(|_| 1).sum::(), opts_details = option_details_for_path(app, &*sc) diff --git a/clap_complete/src/shells/elvish.rs b/clap_complete/src/shells/elvish.rs index 17cd98eeeca..bbcd7ee7fd9 100644 --- a/clap_complete/src/shells/elvish.rs +++ b/clap_complete/src/shells/elvish.rs @@ -54,7 +54,7 @@ set edit:completion:arg-completer[{bin_name}] = [@words]{{ // Escape string inside single quotes fn escape_string(string: &str) -> String { - string.replace("'", "''") + string.replace('\'', "''") } fn get_tooltip(help: Option<&str>, data: T) -> String { diff --git a/clap_complete/src/shells/fish.rs b/clap_complete/src/shells/fish.rs index 0cd165cea11..f5fd87df874 100644 --- a/clap_complete/src/shells/fish.rs +++ b/clap_complete/src/shells/fish.rs @@ -26,7 +26,7 @@ impl Generator for Fish { // Escape string inside single quotes fn escape_string(string: &str) -> String { - string.replace("\\", "\\\\").replace("'", "\\'") + string.replace('\\', "\\\\").replace('\'', "\\'") } fn gen_fish_inner(root_command: &str, parent_commands: &[&str], app: &App, buffer: &mut String) { diff --git a/clap_complete/src/shells/powershell.rs b/clap_complete/src/shells/powershell.rs index 4e3ad4253ae..7d9cadeb10e 100644 --- a/clap_complete/src/shells/powershell.rs +++ b/clap_complete/src/shells/powershell.rs @@ -58,7 +58,7 @@ Register-ArgumentCompleter -Native -CommandName '{bin_name}' -ScriptBlock {{ // Escape string inside single quotes fn escape_string(string: &str) -> String { - string.replace("'", "''") + string.replace('\'', "''") } fn get_tooltip(help: Option<&str>, data: T) -> String { diff --git a/clap_complete/src/shells/zsh.rs b/clap_complete/src/shells/zsh.rs index 84ee0e8ae64..9bc6e182106 100644 --- a/clap_complete/src/shells/zsh.rs +++ b/clap_complete/src/shells/zsh.rs @@ -92,7 +92,7 @@ _{bin_name_underscore}_commands() {{ local commands; commands=({subcommands_and_args}) _describe -t commands '{bin_name} commands' commands \"$@\" }}", - bin_name_underscore = name.replace(" ", "__"), + bin_name_underscore = name.replace(' ', "__"), bin_name = name, subcommands_and_args = subcommands_of(p) ); @@ -114,7 +114,7 @@ _{bin_name_underscore}_commands() {{ local commands; commands=({subcommands_and_args}) _describe -t commands '{bin_name} commands' commands \"$@\" }}", - bin_name_underscore = bin_name.replace(" ", "__"), + bin_name_underscore = bin_name.replace(' ', "__"), bin_name = bin_name, subcommands_and_args = subcommands_of(parser_of(p, bin_name).expect(INTERNAL_ERROR_MSG)) @@ -259,7 +259,7 @@ fn get_subcommands_of(parent: &App) -> String { ;; esac", name = parent.get_name(), - name_hyphen = parent.get_bin_name().unwrap().replace(" ", "-"), + name_hyphen = parent.get_bin_name().unwrap().replace(' ', "-"), subcommands = all_subcommands.join("\n"), pos = parent.get_positionals().count() + 1 ) @@ -328,7 +328,7 @@ fn get_args_of(parent: &App, p_global: Option<&App>) -> String { if parent.has_subcommands() { let subcommand_bin_name = format!( "\":: :_{name}_commands\" \\", - name = parent.get_bin_name().as_ref().unwrap().replace(" ", "__") + name = parent.get_bin_name().as_ref().unwrap().replace(' ', "__") ); segments.push(subcommand_bin_name); @@ -406,20 +406,20 @@ fn value_completion(arg: &Arg) -> Option { /// Escape help string inside single quotes and brackets fn escape_help(string: &str) -> String { string - .replace("\\", "\\\\") - .replace("'", "'\\''") - .replace("[", "\\[") - .replace("]", "\\]") + .replace('\\', "\\\\") + .replace('\'', "'\\''") + .replace('[', "\\[") + .replace(']', "\\]") } /// Escape value string inside single quotes and parentheses fn escape_value(string: &str) -> String { string - .replace("\\", "\\\\") - .replace("'", "'\\''") - .replace("(", "\\(") - .replace(")", "\\)") - .replace(" ", "\\ ") + .replace('\\', "\\\\") + .replace('\'', "'\\''") + .replace('(', "\\(") + .replace(')', "\\)") + .replace(' ', "\\ ") } fn write_opts_of(p: &App, p_global: Option<&App>) -> String { @@ -631,9 +631,9 @@ fn write_positionals_of(p: &App) -> String { help = arg .get_help() .map_or("".to_owned(), |v| " -- ".to_owned() + v) - .replace("[", "\\[") - .replace("]", "\\]") - .replace(":", "\\:"), + .replace('[', "\\[") + .replace(']', "\\]") + .replace(':', "\\:"), value_completion = value_completion(arg).unwrap_or_else(|| "".to_string()) ); diff --git a/clap_complete_fig/src/fig.rs b/clap_complete_fig/src/fig.rs index 74403f09343..924fce49741 100644 --- a/clap_complete_fig/src/fig.rs +++ b/clap_complete_fig/src/fig.rs @@ -38,7 +38,7 @@ impl Generator for Fig { // Escape string inside double quotes fn escape_string(string: &str) -> String { - string.replace("\\", "\\\\").replace("\"", "\\\"") + string.replace('\\', "\\\\").replace('\"', "\\\"") } fn gen_fig_inner( diff --git a/clap_derive/src/attrs.rs b/clap_derive/src/attrs.rs index 1f4eaacaeba..9cb31a8420c 100644 --- a/clap_derive/src/attrs.rs +++ b/clap_derive/src/attrs.rs @@ -879,8 +879,8 @@ impl Name { Camel => s.to_lower_camel_case(), ScreamingSnake => s.to_shouty_snake_case(), Snake => s.to_snake_case(), - Lower => s.to_snake_case().replace("_", ""), - Upper => s.to_shouty_snake_case().replace("_", ""), + Lower => s.to_snake_case().replace('_', ""), + Upper => s.to_shouty_snake_case().replace('_', ""), Verbatim => s, }; quote_spanned!(ident.span()=> #s) diff --git a/clap_derive/src/parse.rs b/clap_derive/src/parse.rs index 64d80a77c48..5eb0eb50f27 100644 --- a/clap_derive/src/parse.rs +++ b/clap_derive/src/parse.rs @@ -252,8 +252,8 @@ fn raw_method_suggestion(ts: ParseBuffer) -> String { fn to_string(val: &T) -> String { val.to_token_stream() .to_string() - .replace(" ", "") - .replace(",", ", ") + .replace(' ', "") + .replace(',', ", ") } if let Ok((name, exprs)) = do_parse() { diff --git a/clap_derive/src/utils/doc_comments.rs b/clap_derive/src/utils/doc_comments.rs index 7ac872cf364..f0a5034d700 100644 --- a/clap_derive/src/utils/doc_comments.rs +++ b/clap_derive/src/utils/doc_comments.rs @@ -78,7 +78,7 @@ fn split_paragraphs(lines: &[&str]) -> Vec { let len = slice .iter() .position(|s| is_blank(s)) - .unwrap_or_else(|| slice.len()); + .unwrap_or(slice.len()); last_line += start + len; diff --git a/examples/tutorial_derive/04_04_custom.rs b/examples/tutorial_derive/04_04_custom.rs index fc713adfe5d..c06719453b7 100644 --- a/examples/tutorial_derive/04_04_custom.rs +++ b/examples/tutorial_derive/04_04_custom.rs @@ -72,10 +72,13 @@ fn main() { // Check for usage of -c if let Some(config) = cli.config.as_deref() { + // todo: remove `#[allow(clippy::or_fun_call)]` lint when MSRV is bumped. + #[allow(clippy::or_fun_call)] let input = cli .input_file .as_deref() - .or_else(|| cli.spec_in.as_deref()) + // 'or' is preferred to 'or_else' here since `Option::as_deref` is 'const' + .or(cli.spec_in.as_deref()) .unwrap_or_else(|| { let mut app = Cli::into_app(); app.error( diff --git a/src/build/app/mod.rs b/src/build/app/mod.rs index 0e68f034d36..9f6c30eb11e 100644 --- a/src/build/app/mod.rs +++ b/src/build/app/mod.rs @@ -160,6 +160,7 @@ impl<'help> App<'help> { /// # ; /// ``` /// [argument]: Arg + #[must_use] pub fn arg>>(mut self, a: A) -> Self { let mut arg = a.into(); arg.help_heading.get_or_insert(self.current_help_heading); @@ -181,6 +182,7 @@ impl<'help> App<'help> { /// # ; /// ``` /// [arguments]: Arg + #[must_use] pub fn args(mut self, args: I) -> Self where I: IntoIterator, @@ -190,7 +192,7 @@ impl<'help> App<'help> { let (lower, _) = args.size_hint(); self.args.reserve(lower); - for arg in args.into_iter() { + for arg in args { self = self.arg(arg); } self @@ -220,6 +222,7 @@ impl<'help> App<'help> { /// let res = app.try_get_matches_from_mut(vec!["foo", "-B"]); /// assert!(res.is_ok()); /// ``` + #[must_use] pub fn mut_arg(mut self, arg_id: T, f: F) -> Self where F: FnOnce(Arg<'help>) -> Arg<'help>, @@ -274,6 +277,7 @@ impl<'help> App<'help> { /// # ; /// ``` #[inline] + #[must_use] pub fn group>>(mut self, group: G) -> Self { self.groups.push(group.into()); self @@ -301,6 +305,7 @@ impl<'help> App<'help> { /// ]) /// # ; /// ``` + #[must_use] pub fn groups(mut self, groups: I) -> Self where I: IntoIterator, @@ -333,6 +338,7 @@ impl<'help> App<'help> { /// # ; /// ``` #[inline] + #[must_use] pub fn subcommand>>(mut self, subcmd: S) -> Self { self.subcommands.push(subcmd.into()); self @@ -352,6 +358,7 @@ impl<'help> App<'help> { /// # ; /// ``` /// [`IntoIterator`]: std::iter::IntoIterator + #[must_use] pub fn subcommands(mut self, subcmds: I) -> Self where I: IntoIterator, @@ -829,6 +836,7 @@ impl<'help> App<'help> { /// /// // continued logic goes here, such as `app.get_matches()` etc. /// ``` + #[must_use] pub fn name>(mut self, name: S) -> Self { self.name = name.into(); self @@ -854,6 +862,7 @@ impl<'help> App<'help> { /// .bin_name("my_binary") /// # ; /// ``` + #[must_use] pub fn bin_name>(mut self, name: S) -> Self { self.bin_name = Some(name.into()); self @@ -874,6 +883,7 @@ impl<'help> App<'help> { /// # ; /// ``` /// [`crate_authors!`]: ./macro.crate_authors!.html + #[must_use] pub fn author>(mut self, author: S) -> Self { self.author = Some(author.into()); self @@ -896,6 +906,7 @@ impl<'help> App<'help> { /// .about("Does really amazing things for great people") /// # ; /// ``` + #[must_use] pub fn about>>(mut self, about: O) -> Self { self.about = about.into(); self @@ -920,6 +931,7 @@ impl<'help> App<'help> { /// # ; /// ``` /// [`App::about`]: App::about() + #[must_use] pub fn long_about>>(mut self, long_about: O) -> Self { self.long_about = long_about.into(); self @@ -941,6 +953,7 @@ impl<'help> App<'help> { /// # ; /// ``` /// + #[must_use] pub fn after_help>(mut self, help: S) -> Self { self.after_help = Some(help.into()); self @@ -962,6 +975,7 @@ impl<'help> App<'help> { /// like, for real, be careful with this!") /// # ; /// ``` + #[must_use] pub fn after_long_help>(mut self, help: S) -> Self { self.after_long_help = Some(help.into()); self @@ -981,6 +995,7 @@ impl<'help> App<'help> { /// .before_help("Some info I'd like to appear before the help info") /// # ; /// ``` + #[must_use] pub fn before_help>(mut self, help: S) -> Self { self.before_help = Some(help.into()); self @@ -1000,6 +1015,7 @@ impl<'help> App<'help> { /// .before_long_help("Some verbose and long info I'd like to appear before the help info") /// # ; /// ``` + #[must_use] pub fn before_long_help>(mut self, help: S) -> Self { self.before_long_help = Some(help.into()); self @@ -1022,6 +1038,7 @@ impl<'help> App<'help> { /// # ; /// ``` /// [`crate_version!`]: ./macro.crate_version!.html + #[must_use] pub fn version>(mut self, ver: S) -> Self { self.version = Some(ver.into()); self @@ -1049,6 +1066,7 @@ impl<'help> App<'help> { /// # ; /// ``` /// [`crate_version!`]: ./macro.crate_version!.html + #[must_use] pub fn long_version>(mut self, ver: S) -> Self { self.long_version = Some(ver.into()); self @@ -1069,6 +1087,7 @@ impl<'help> App<'help> { /// # ; /// ``` /// [`ArgMatches::usage`]: ArgMatches::usage() + #[must_use] pub fn override_usage>(mut self, usage: S) -> Self { self.usage_str = Some(usage.into()); self @@ -1105,6 +1124,7 @@ impl<'help> App<'help> { /// work Do some work") /// # ; /// ``` + #[must_use] pub fn override_help>(mut self, help: S) -> Self { self.help_str = Some(help.into()); self @@ -1153,6 +1173,7 @@ impl<'help> App<'help> { /// [`App::after_long_help`]: App::after_long_help() /// [`App::before_help`]: App::before_help() /// [`App::before_long_help`]: App::before_long_help() + #[must_use] pub fn help_template>(mut self, s: S) -> Self { self.template = Some(s.into()); self @@ -1181,6 +1202,7 @@ impl<'help> App<'help> { /// # ; /// ``` #[inline] + #[must_use] pub fn setting(mut self, setting: F) -> Self where F: Into, @@ -1210,6 +1232,7 @@ impl<'help> App<'help> { /// # ; /// ``` #[inline] + #[must_use] pub fn unset_setting(mut self, setting: F) -> Self where F: Into, @@ -1233,6 +1256,7 @@ impl<'help> App<'help> { /// # ; /// ``` #[inline] + #[must_use] pub fn global_setting(mut self, setting: AppSettings) -> Self { self.settings.set(setting); self.g_settings.set(setting); @@ -1253,6 +1277,7 @@ impl<'help> App<'help> { /// ``` /// [global]: App::global_setting() #[inline] + #[must_use] pub fn unset_global_setting(mut self, setting: AppSettings) -> Self { self.settings.unset(setting); self.g_settings.unset(setting); @@ -1276,6 +1301,7 @@ impl<'help> App<'help> { /// [`ColorChoice::Auto`]: crate::ColorChoice::Auto #[cfg(feature = "color")] #[inline] + #[must_use] pub fn color(self, color: ColorChoice) -> Self { #[allow(deprecated)] match color { @@ -1297,6 +1323,7 @@ impl<'help> App<'help> { /// [`App::arg`]: App::arg() /// [`Arg::help_heading`]: crate::Arg::help_heading() #[inline] + #[must_use] pub fn help_heading(mut self, heading: O) -> Self where O: Into>, @@ -1323,6 +1350,7 @@ impl<'help> App<'help> { /// # ; /// ``` #[inline] + #[must_use] pub fn term_width(mut self, width: usize) -> Self { self.term_w = Some(width); self @@ -1346,6 +1374,7 @@ impl<'help> App<'help> { /// # ; /// ``` #[inline] + #[must_use] pub fn max_term_width(mut self, w: usize) -> Self { self.max_w = Some(w); self @@ -1456,6 +1485,7 @@ impl<'help> App<'help> { /// [`App::replace`]: App::replace() #[inline] #[cfg(feature = "unstable-replace")] + #[must_use] pub fn replace(mut self, name: &'help str, target: &'help [&'help str]) -> Self { self.replacers.insert(name, target); self @@ -1488,6 +1518,7 @@ impl<'help> App<'help> { /// assert!(sync_matches.is_present("search")); /// ``` /// [`Arg::short`]: Arg::short() + #[must_use] pub fn short_flag(mut self, short: char) -> Self { self.short_flag = Some(short); self @@ -1524,6 +1555,7 @@ impl<'help> App<'help> { /// ``` /// /// [`Arg::long`]: Arg::long() + #[must_use] pub fn long_flag(mut self, long: &'help str) -> Self { self.long_flag = Some(long.trim_start_matches(|c| c == '-')); self @@ -1554,6 +1586,7 @@ impl<'help> App<'help> { /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` /// [`App::visible_alias`]: App::visible_alias() + #[must_use] pub fn alias>(mut self, name: S) -> Self { self.aliases.push((name.into(), false)); self @@ -1575,8 +1608,9 @@ impl<'help> App<'help> { /// .get_matches_from(vec!["myprog", "-d"]); /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` + #[must_use] pub fn short_flag_alias(mut self, name: char) -> Self { - assert!(!(name == '-'), "short alias name cannot be `-`"); + assert!(name != '-', "short alias name cannot be `-`"); self.short_flag_aliases.push((name, false)); self } @@ -1597,6 +1631,7 @@ impl<'help> App<'help> { /// .get_matches_from(vec!["myprog", "--testing"]); /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` + #[must_use] pub fn long_flag_alias(mut self, name: &'help str) -> Self { self.long_flag_aliases.push((name, false)); self @@ -1631,6 +1666,7 @@ impl<'help> App<'help> { /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` /// [`App::visible_aliases`]: App::visible_aliases() + #[must_use] pub fn aliases(mut self, names: &[&'help str]) -> Self { self.aliases.extend(names.iter().map(|n| (*n, false))); self @@ -1656,6 +1692,7 @@ impl<'help> App<'help> { /// .get_matches_from(vec!["myprog", "-a"]); /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` + #[must_use] pub fn short_flag_aliases(mut self, names: &[char]) -> Self { for s in names { assert!(s != &'-', "short alias name cannot be `-`"); @@ -1684,6 +1721,7 @@ impl<'help> App<'help> { /// .get_matches_from(vec!["myprog", "--testing"]); /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` + #[must_use] pub fn long_flag_aliases(mut self, names: &[&'help str]) -> Self { for s in names { self.long_flag_aliases.push((s, false)); @@ -1718,6 +1756,7 @@ impl<'help> App<'help> { /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` /// [`App::alias`]: App::alias() + #[must_use] pub fn visible_alias>(mut self, name: S) -> Self { self.aliases.push((name.into(), true)); self @@ -1742,6 +1781,7 @@ impl<'help> App<'help> { /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` /// [`App::short_flag_alias`]: App::short_flag_alias() + #[must_use] pub fn visible_short_flag_alias(mut self, name: char) -> Self { assert!(name != '-', "short alias name cannot be `-`"); self.short_flag_aliases.push((name, true)); @@ -1767,6 +1807,7 @@ impl<'help> App<'help> { /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` /// [`App::long_flag_alias`]: App::long_flag_alias() + #[must_use] pub fn visible_long_flag_alias(mut self, name: &'help str) -> Self { self.long_flag_aliases.push((name, true)); self @@ -1799,6 +1840,7 @@ impl<'help> App<'help> { /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` /// [`App::alias`]: App::alias() + #[must_use] pub fn visible_aliases(mut self, names: &[&'help str]) -> Self { self.aliases.extend(names.iter().map(|n| (*n, true))); self @@ -1819,9 +1861,10 @@ impl<'help> App<'help> { /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` /// [`App::short_flag_aliases`]: App::short_flag_aliases() + #[must_use] pub fn visible_short_flag_aliases(mut self, names: &[char]) -> Self { for s in names { - assert!(!(s == &'-'), "short alias name cannot be `-`"); + assert!(s != &'-', "short alias name cannot be `-`"); self.short_flag_aliases.push((*s, true)); } self @@ -1842,6 +1885,7 @@ impl<'help> App<'help> { /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` /// [`App::long_flag_aliases`]: App::long_flag_aliases() + #[must_use] pub fn visible_long_flag_aliases(mut self, names: &[&'help str]) -> Self { for s in names { self.long_flag_aliases.push((s, true)); @@ -1898,6 +1942,7 @@ impl<'help> App<'help> { /// alpha Some help and text /// ``` #[inline] + #[must_use] pub fn display_order(mut self, ord: usize) -> Self { self.disp_ord = Some(ord); self @@ -1963,6 +2008,7 @@ impl<'help> App<'help> { /// help Print this message or the help of the given subcommand(s) /// sub1 /// ``` + #[must_use] pub fn subcommand_value_name(mut self, value_name: S) -> Self where S: Into<&'help str>, @@ -2031,6 +2077,7 @@ impl<'help> App<'help> { /// help Print this message or the help of the given subcommand(s) /// sub1 /// ``` + #[must_use] pub fn subcommand_help_heading(mut self, heading: T) -> Self where T: Into<&'help str>, @@ -2393,48 +2440,56 @@ impl<'help> App<'help> { /// Deprecated, replaced with [`App::override_usage`] #[deprecated(since = "3.0.0", note = "Replaced with `App::override_usage`")] + #[must_use] pub fn usage>(self, usage: S) -> Self { self.override_usage(usage) } /// Deprecated, replaced with [`App::override_help`] #[deprecated(since = "3.0.0", note = "Replaced with `App::override_help`")] + #[must_use] pub fn help>(self, help: S) -> Self { self.override_help(help) } /// Deprecated, replaced with [`App::mut_arg`] #[deprecated(since = "3.0.0", note = "Replaced with `App::mut_arg`")] + #[must_use] pub fn help_short(self, c: char) -> Self { self.mut_arg("help", |a| a.short(c)) } /// Deprecated, replaced with [`App::mut_arg`] #[deprecated(since = "3.0.0", note = "Replaced with `App::mut_arg`")] + #[must_use] pub fn version_short(self, c: char) -> Self { self.mut_arg("version", |a| a.short(c)) } /// Deprecated, replaced with [`App::mut_arg`] #[deprecated(since = "3.0.0", note = "Replaced with `App::mut_arg`")] + #[must_use] pub fn help_message(self, s: impl Into<&'help str>) -> Self { self.mut_arg("help", |a| a.help(s.into())) } /// Deprecated, replaced with [`App::mut_arg`] #[deprecated(since = "3.0.0", note = "Replaced with `App::mut_arg`")] + #[must_use] pub fn version_message(self, s: impl Into<&'help str>) -> Self { self.mut_arg("version", |a| a.help(s.into())) } /// Deprecated, replaced with [`App::help_template`] #[deprecated(since = "3.0.0", note = "Replaced with `App::help_template`")] + #[must_use] pub fn template>(self, s: S) -> Self { self.help_template(s) } /// Deprecated, replaced with [`App::setting(a| b)`] #[deprecated(since = "3.0.0", note = "Replaced with `App::setting(a | b)`")] + #[must_use] pub fn settings(mut self, settings: &[AppSettings]) -> Self { for s in settings { self.settings.insert((*s).into()); @@ -2444,6 +2499,7 @@ impl<'help> App<'help> { /// Deprecated, replaced with [`App::unset_setting(a| b)`] #[deprecated(since = "3.0.0", note = "Replaced with `App::unset_setting(a | b)`")] + #[must_use] pub fn unset_settings(mut self, settings: &[AppSettings]) -> Self { for s in settings { self.settings.remove((*s).into()); @@ -2453,6 +2509,7 @@ impl<'help> App<'help> { /// Deprecated, replaced with [`App::global_setting(a| b)`] #[deprecated(since = "3.0.0", note = "Replaced with `App::global_setting(a | b)`")] + #[must_use] pub fn global_settings(mut self, settings: &[AppSettings]) -> Self { for s in settings { self.settings.insert((*s).into()); @@ -2463,12 +2520,14 @@ impl<'help> App<'help> { /// Deprecated, replaced with [`App::term_width`] #[deprecated(since = "3.0.0", note = "Replaced with `App::term_width`")] + #[must_use] pub fn set_term_width(self, width: usize) -> Self { self.term_width(width) } /// Deprecated in [Issue #3086](https://github.com/clap-rs/clap/issues/3086), see [`arg!`][crate::arg!]. #[deprecated(since = "3.0.0", note = "Deprecated in Issue #3086, see `clap::arg!")] + #[must_use] pub fn arg_from_usage(self, usage: &'help str) -> Self { #![allow(deprecated)] self.arg(Arg::from_usage(usage)) @@ -2476,6 +2535,7 @@ impl<'help> App<'help> { /// Deprecated in [Issue #3086](https://github.com/clap-rs/clap/issues/3086), see [`arg!`][crate::arg!]. #[deprecated(since = "3.0.0", note = "Deprecated in Issue #3086, see `clap::arg!")] + #[must_use] pub fn args_from_usage(mut self, usage: &'help str) -> Self { #![allow(deprecated)] for line in usage.lines() { @@ -2925,7 +2985,7 @@ impl<'help> App<'help> { if let Some(bn) = self.bin_name.as_ref() { if bn.contains(' ') { // In case we're dealing with subcommands i.e. git mv is translated to git-mv - format!("{} {}\n", bn.replace(" ", "-"), ver) + format!("{} {}\n", bn.replace(' ', "-"), ver) } else { format!("{} {}\n", &self.name[..], ver) } diff --git a/src/build/arg/mod.rs b/src/build/arg/mod.rs index ec887f44049..053cb2dd4a5 100644 --- a/src/build/arg/mod.rs +++ b/src/build/arg/mod.rs @@ -127,6 +127,7 @@ impl<'help> Arg<'help> { /// Set the identifier used for referencing this argument in the clap API. /// /// See [`Arg::new`] for more details. + #[must_use] pub fn name>(mut self, n: S) -> Self { let name = n.into(); self.id = Id::from(&*name); @@ -158,6 +159,7 @@ impl<'help> Arg<'help> { /// assert!(m.is_present("config")); /// ``` #[inline] + #[must_use] pub fn short(mut self, s: char) -> Self { assert!(s != '-', "short option name cannot be `-`"); @@ -194,6 +196,7 @@ impl<'help> Arg<'help> { /// assert!(m.is_present("cfg")); /// ``` #[inline] + #[must_use] pub fn long(mut self, l: &'help str) -> Self { self.long = Some(l.trim_start_matches(|c| c == '-')); self @@ -219,6 +222,7 @@ impl<'help> Arg<'help> { /// assert!(m.is_present("test")); /// assert_eq!(m.value_of("test"), Some("cool")); /// ``` + #[must_use] pub fn alias>(mut self, name: S) -> Self { self.aliases.push((name.into(), false)); self @@ -244,6 +248,7 @@ impl<'help> Arg<'help> { /// assert!(m.is_present("test")); /// assert_eq!(m.value_of("test"), Some("cool")); /// ``` + #[must_use] pub fn short_alias(mut self, name: char) -> Self { assert!(name != '-', "short alias name cannot be `-`"); @@ -271,6 +276,7 @@ impl<'help> Arg<'help> { /// ]); /// assert!(m.is_present("test")); /// ``` + #[must_use] pub fn aliases(mut self, names: &[&'help str]) -> Self { self.aliases.extend(names.iter().map(|&x| (x, false))); self @@ -296,6 +302,7 @@ impl<'help> Arg<'help> { /// ]); /// assert!(m.is_present("test")); /// ``` + #[must_use] pub fn short_aliases(mut self, names: &[char]) -> Self { for s in names { assert!(s != &'-', "short alias name cannot be `-`"); @@ -324,6 +331,7 @@ impl<'help> Arg<'help> { /// assert_eq!(m.value_of("test"), Some("coffee")); /// ``` /// [`App::alias`]: Arg::alias() + #[must_use] pub fn visible_alias>(mut self, name: S) -> Self { self.aliases.push((name.into(), true)); self @@ -348,6 +356,7 @@ impl<'help> Arg<'help> { /// assert!(m.is_present("test")); /// assert_eq!(m.value_of("test"), Some("coffee")); /// ``` + #[must_use] pub fn visible_short_alias(mut self, name: char) -> Self { assert!(name != '-', "short alias name cannot be `-`"); @@ -373,6 +382,7 @@ impl<'help> Arg<'help> { /// assert!(m.is_present("test")); /// ``` /// [`App::aliases`]: Arg::aliases() + #[must_use] pub fn visible_aliases(mut self, names: &[&'help str]) -> Self { self.aliases.extend(names.iter().map(|n| (*n, true))); self @@ -395,6 +405,7 @@ impl<'help> Arg<'help> { /// ]); /// assert!(m.is_present("test")); /// ``` + #[must_use] pub fn visible_short_aliases(mut self, names: &[char]) -> Self { for n in names { assert!(n != &'-', "short alias name cannot be `-`"); @@ -454,6 +465,7 @@ impl<'help> Arg<'help> { /// [`panic!`]: https://doc.rust-lang.org/std/macro.panic!.html /// [`App`]: crate::App #[inline] + #[must_use] pub fn index(mut self, idx: usize) -> Self { self.index = Some(idx); self @@ -535,6 +547,7 @@ impl<'help> Arg<'help> { /// [index]: Arg::index() /// [`UnknownArgument`]: crate::ErrorKind::UnknownArgument #[inline] + #[must_use] pub fn last(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::Last) @@ -597,6 +610,7 @@ impl<'help> Arg<'help> { /// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument); /// ``` #[inline] + #[must_use] pub fn required(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::Required) @@ -663,6 +677,7 @@ impl<'help> Arg<'help> { /// [`Arg::requires(name)`]: Arg::requires() /// [Conflicting]: Arg::conflicts_with() /// [override]: Arg::overrides_with() + #[must_use] pub fn requires(mut self, arg_id: T) -> Self { self.requires.push((None, arg_id.into())); self @@ -701,6 +716,7 @@ impl<'help> Arg<'help> { /// assert_eq!(res.unwrap_err().kind, ErrorKind::ArgumentConflict); /// ``` #[inline] + #[must_use] pub fn exclusive(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::Exclusive) @@ -743,6 +759,7 @@ impl<'help> Arg<'help> { /// [`Subcommand`]: crate::Subcommand /// [`ArgMatches::is_present("flag")`]: ArgMatches::is_present() #[inline] + #[must_use] pub fn global(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::Global) @@ -797,6 +814,7 @@ impl<'help> Arg<'help> { /// assert_eq!(files, ["file1", "file2", "file3"]); /// ``` #[inline] + #[must_use] pub fn multiple_occurrences(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::MultipleOccurrences) @@ -855,6 +873,7 @@ impl<'help> Arg<'help> { /// ``` /// [`Arg::multiple_occurrences(true)`]: Arg::multiple_occurrences() #[inline] + #[must_use] pub fn max_occurrences(mut self, qty: usize) -> Self { self.max_occurs = Some(qty); if qty > 1 { @@ -893,6 +912,7 @@ impl<'help> Arg<'help> { /// # ; /// ``` #[inline] + #[must_use] pub fn setting(mut self, setting: F) -> Self where F: Into, @@ -922,6 +942,7 @@ impl<'help> Arg<'help> { /// # ; /// ``` #[inline] + #[must_use] pub fn unset_setting(mut self, setting: F) -> Self where F: Into, @@ -965,6 +986,7 @@ impl<'help> Arg<'help> { /// [`Arg::value_delimiter(char)`]: Arg::value_delimiter() /// [multiple values]: Arg::multiple_values #[inline] + #[must_use] pub fn takes_value(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::TakesValue) @@ -1139,6 +1161,7 @@ impl<'help> Arg<'help> { /// [maximum]: Arg::max_values() /// [specific]: Arg::number_of_values() #[inline] + #[must_use] pub fn multiple_values(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::MultipleValues) @@ -1187,6 +1210,7 @@ impl<'help> Arg<'help> { /// ``` /// [`Arg::multiple_occurrences(true)`]: Arg::multiple_occurrences() #[inline] + #[must_use] pub fn number_of_values(mut self, qty: usize) -> Self { self.num_vals = Some(qty); self.takes_value(true).multiple_values(true) @@ -1250,6 +1274,7 @@ impl<'help> Arg<'help> { /// ``` /// [`Arg::multiple_occurrences(true)`]: Arg::multiple_occurrences() #[inline] + #[must_use] pub fn max_values(mut self, qty: usize) -> Self { self.max_vals = Some(qty); self.takes_value(true).multiple_values(true) @@ -1314,6 +1339,7 @@ impl<'help> Arg<'help> { /// ``` /// [`Arg::multiple_occurrences(true)`]: Arg::multiple_occurrences() #[inline] + #[must_use] pub fn min_values(mut self, qty: usize) -> Self { self.min_vals = Some(qty); self.takes_value(true).multiple_values(true) @@ -1366,6 +1392,7 @@ impl<'help> Arg<'help> { /// [positional]: Arg::index() /// [`Arg::takes_value(true)`]: Arg::takes_value() #[inline] + #[must_use] pub fn value_name(self, name: &'help str) -> Self { self.value_names(&[name]) } @@ -1423,6 +1450,7 @@ impl<'help> Arg<'help> { /// [`Arg::number_of_values`]: Arg::number_of_values() /// [`Arg::takes_value(true)`]: Arg::takes_value() /// [`Arg::multiple_values(true)`]: Arg::multiple_values() + #[must_use] pub fn value_names(mut self, names: &[&'help str]) -> Self { self.val_names = names.to_vec(); self.takes_value(true) @@ -1457,6 +1485,7 @@ impl<'help> Arg<'help> { /// .value_hint(ValueHint::CommandWithArguments) /// ); /// ``` + #[must_use] pub fn value_hint(mut self, value_hint: ValueHint) -> Self { self.value_hint = value_hint; self.takes_value(true) @@ -1500,6 +1529,7 @@ impl<'help> Arg<'help> { /// [`Result`]: std::result::Result /// [`Err(String)`]: std::result::Result::Err /// [`Arc`]: std::sync::Arc + #[must_use] pub fn validator(mut self, mut f: F) -> Self where F: FnMut(&str) -> Result + Send + 'help, @@ -1542,6 +1572,7 @@ impl<'help> Arg<'help> { /// [`Result`]: std::result::Result /// [`Err(String)`]: std::result::Result::Err /// [`Rc`]: std::rc::Rc + #[must_use] pub fn validator_os(mut self, mut f: F) -> Self where F: FnMut(&OsStr) -> Result + Send + 'help, @@ -1607,6 +1638,7 @@ impl<'help> Arg<'help> { /// assert_eq!(res.err().unwrap().kind, ErrorKind::ValueValidation) /// ``` #[cfg(feature = "regex")] + #[must_use] pub fn validator_regex( self, regex: impl Into>, @@ -1692,6 +1724,7 @@ impl<'help> Arg<'help> { /// ``` /// [options]: Arg::takes_value() /// [positional arguments]: Arg::index() + #[must_use] pub fn possible_value(mut self, value: T) -> Self where T: Into>, @@ -1767,6 +1800,7 @@ impl<'help> Arg<'help> { /// ``` /// [options]: Arg::takes_value() /// [positional arguments]: Arg::index() + #[must_use] pub fn possible_values(mut self, values: I) -> Self where I: IntoIterator, @@ -1826,6 +1860,7 @@ impl<'help> Arg<'help> { /// assert_eq!(&*matched_vals, &["TeSt123", "teST123", "tESt321"]); /// ``` #[inline] + #[must_use] pub fn ignore_case(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::IgnoreCase) @@ -1885,6 +1920,7 @@ impl<'help> Arg<'help> { /// ``` /// [`Arg::number_of_values(1)`]: Arg::number_of_values() #[inline] + #[must_use] pub fn allow_hyphen_values(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::AllowHyphenValues) @@ -1925,6 +1961,7 @@ impl<'help> Arg<'help> { /// [`ArgMatches::value_of_lossy`]: crate::ArgMatches::value_of_lossy() /// [`ArgMatches::values_of_lossy`]: crate::ArgMatches::values_of_lossy() #[inline] + #[must_use] pub fn allow_invalid_utf8(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::AllowInvalidUtf8) @@ -1979,6 +2016,7 @@ impl<'help> Arg<'help> { /// assert_eq!(res.unwrap_err().kind, ErrorKind::EmptyValue); /// ``` #[inline] + #[must_use] pub fn forbid_empty_values(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::ForbidEmptyValues) @@ -2030,6 +2068,7 @@ impl<'help> Arg<'help> { /// assert_eq!(res.unwrap_err().kind, ErrorKind::NoEquals); /// ``` #[inline] + #[must_use] pub fn require_equals(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::RequireEquals) @@ -2088,6 +2127,7 @@ impl<'help> Arg<'help> { /// ``` /// [`Arg::value_delimiter`]: Arg::value_delimiter() #[inline] + #[must_use] pub fn use_delimiter(mut self, yes: bool) -> Self { if yes { if self.val_delim.is_none() { @@ -2125,6 +2165,7 @@ impl<'help> Arg<'help> { /// [`Arg::use_delimiter(true)`]: Arg::use_delimiter() /// [`Arg::takes_value(true)`]: Arg::takes_value() #[inline] + #[must_use] pub fn value_delimiter(mut self, d: char) -> Self { self.val_delim = Some(d); self.takes_value(true).use_delimiter(true) @@ -2207,6 +2248,7 @@ impl<'help> Arg<'help> { /// assert_eq!(delims.values_of("opt").unwrap().collect::>(), ["val1", "val2", "val3"]); /// ``` #[inline] + #[must_use] pub fn require_delimiter(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::RequireDelimiter) @@ -2265,6 +2307,7 @@ impl<'help> Arg<'help> { /// [`number_of_values`]: Arg::number_of_values() /// [`max_values`]: Arg::max_values() #[inline] + #[must_use] pub fn value_terminator(mut self, term: &'help str) -> Self { self.terminator = Some(term); self.takes_value(true) @@ -2293,6 +2336,7 @@ impl<'help> Arg<'help> { /// [`Arg::allow_hyphen_values(true)`]: Arg::allow_hyphen_values() /// [`Arg::last(true)`]: Arg::last() #[inline] + #[must_use] pub fn raw(self, yes: bool) -> Self { self.takes_value(yes) .multiple_values(yes) @@ -2364,6 +2408,7 @@ impl<'help> Arg<'help> { /// [`ArgMatches::is_present`]: crate::ArgMatches::is_present() /// [`Arg::default_value_if`]: Arg::default_value_if() #[inline] + #[must_use] pub fn default_value(self, val: &'help str) -> Self { self.default_values_os(&[OsStr::new(val)]) } @@ -2375,6 +2420,7 @@ impl<'help> Arg<'help> { /// [`Arg::default_value`]: Arg::default_value() /// [`OsStr`]: std::ffi::OsStr #[inline] + #[must_use] pub fn default_value_os(self, val: &'help OsStr) -> Self { self.default_values_os(&[val]) } @@ -2385,6 +2431,7 @@ impl<'help> Arg<'help> { /// /// [`Arg::default_value`]: Arg::default_value() #[inline] + #[must_use] pub fn default_values(self, vals: &[&'help str]) -> Self { let vals_vec: Vec<_> = vals.iter().map(|val| OsStr::new(*val)).collect(); self.default_values_os(&vals_vec[..]) @@ -2397,6 +2444,7 @@ impl<'help> Arg<'help> { /// [`Arg::default_values`]: Arg::default_values() /// [`OsStr`]: std::ffi::OsStr #[inline] + #[must_use] pub fn default_values_os(mut self, vals: &[&'help OsStr]) -> Self { self.default_vals = vals.to_vec(); self.takes_value(true) @@ -2474,6 +2522,7 @@ impl<'help> Arg<'help> { /// [`ArgMatches::is_present`]: ArgMatches::is_present() /// [`Arg::default_value`]: Arg::default_value() #[inline] + #[must_use] pub fn default_missing_value(self, val: &'help str) -> Self { self.default_missing_values_os(&[OsStr::new(val)]) } @@ -2485,6 +2534,7 @@ impl<'help> Arg<'help> { /// [`Arg::default_missing_value`]: Arg::default_missing_value() /// [`OsStr`]: std::ffi::OsStr #[inline] + #[must_use] pub fn default_missing_value_os(self, val: &'help OsStr) -> Self { self.default_missing_values_os(&[val]) } @@ -2495,6 +2545,7 @@ impl<'help> Arg<'help> { /// /// [`Arg::default_missing_value`]: Arg::default_missing_value() #[inline] + #[must_use] pub fn default_missing_values(self, vals: &[&'help str]) -> Self { let vals_vec: Vec<_> = vals.iter().map(|val| OsStr::new(*val)).collect(); self.default_missing_values_os(&vals_vec[..]) @@ -2507,6 +2558,7 @@ impl<'help> Arg<'help> { /// [`Arg::default_missing_values`]: Arg::default_missing_values() /// [`OsStr`]: std::ffi::OsStr #[inline] + #[must_use] pub fn default_missing_values_os(mut self, vals: &[&'help OsStr]) -> Self { self.default_missing_vals = vals.to_vec(); self.takes_value(true) @@ -2652,6 +2704,7 @@ impl<'help> Arg<'help> { /// [`Arg::use_delimiter(true)`]: Arg::use_delimiter() #[cfg(feature = "env")] #[inline] + #[must_use] pub fn env(self, name: &'help str) -> Self { self.env_os(OsStr::new(name)) } @@ -2661,6 +2714,7 @@ impl<'help> Arg<'help> { /// See [`Arg::env`]. #[cfg(feature = "env")] #[inline] + #[must_use] pub fn env_os(mut self, name: &'help OsStr) -> Self { self.env = Some((name, env::var_os(name))); self @@ -2712,6 +2766,7 @@ impl<'help> Arg<'help> { /// ``` /// [`Arg::long_help`]: Arg::long_help() #[inline] + #[must_use] pub fn help(mut self, h: impl Into>) -> Self { self.help = h.into(); self @@ -2773,6 +2828,7 @@ impl<'help> Arg<'help> { /// ``` /// [`Arg::help`]: Arg::help() #[inline] + #[must_use] pub fn long_help(mut self, h: impl Into>) -> Self { self.long_help = h.into(); self @@ -2832,6 +2888,7 @@ impl<'help> Arg<'help> { /// [positional arguments]: Arg::index() /// [index]: Arg::index() #[inline] + #[must_use] pub fn display_order(mut self, ord: usize) -> Self { self.disp_ord = Some(ord); self @@ -2841,6 +2898,7 @@ impl<'help> Arg<'help> { /// /// [current]: crate::App::help_heading #[inline] + #[must_use] pub fn help_heading(mut self, heading: O) -> Self where O: Into>, @@ -2893,6 +2951,7 @@ impl<'help> Arg<'help> { /// on a line after the option /// ``` #[inline] + #[must_use] pub fn next_line_help(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::NextLineHelp) @@ -2934,6 +2993,7 @@ impl<'help> Arg<'help> { /// -V, --version Print version information /// ``` #[inline] + #[must_use] pub fn hide(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::Hidden) @@ -2966,6 +3026,7 @@ impl<'help> Arg<'help> { /// If we were to run the above program with `--help` the `[values: fast, slow]` portion of /// the help text would be omitted. #[inline] + #[must_use] pub fn hide_possible_values(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::HidePossibleValues) @@ -2996,6 +3057,7 @@ impl<'help> Arg<'help> { /// If we were to run the above program with `--help` the `[default: localhost]` portion of /// the help text would be omitted. #[inline] + #[must_use] pub fn hide_default_value(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::HideDefaultValue) @@ -3024,6 +3086,7 @@ impl<'help> Arg<'help> { /// text would be omitted. #[cfg(feature = "env")] #[inline] + #[must_use] pub fn hide_env(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::HideEnv) @@ -3053,6 +3116,7 @@ impl<'help> Arg<'help> { /// `[default: CONNECT=super_secret]` portion of the help text would be omitted. #[cfg(feature = "env")] #[inline] + #[must_use] pub fn hide_env_values(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::HideEnvValues) @@ -3131,6 +3195,7 @@ impl<'help> Arg<'help> { /// -V, --version Print version information /// ``` #[inline] + #[must_use] pub fn hide_short_help(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::HiddenShortHelp) @@ -3203,6 +3268,7 @@ impl<'help> Arg<'help> { /// -V, --version Print version information /// ``` #[inline] + #[must_use] pub fn hide_long_help(self, yes: bool) -> Self { if yes { self.setting(ArgSettings::HiddenLongHelp) @@ -3245,6 +3311,7 @@ impl<'help> Arg<'help> { /// ``` /// /// [`ArgGroup`]: crate::ArgGroup + #[must_use] pub fn group(mut self, group_id: T) -> Self { self.groups.push(group_id.into()); self @@ -3282,6 +3349,7 @@ impl<'help> Arg<'help> { /// ``` /// /// [`ArgGroup`]: crate::ArgGroup + #[must_use] pub fn groups(mut self, group_ids: &[T]) -> Self { self.groups.extend(group_ids.iter().map(Id::from)); self @@ -3396,6 +3464,7 @@ impl<'help> Arg<'help> { /// ``` /// [`Arg::takes_value(true)`]: Arg::takes_value() /// [`Arg::default_value`]: Arg::default_value() + #[must_use] pub fn default_value_if( self, arg_id: T, @@ -3410,6 +3479,7 @@ impl<'help> Arg<'help> { /// /// [`Arg::default_value_if`]: Arg::default_value_if() /// [`OsStr`]: std::ffi::OsStr + #[must_use] pub fn default_value_if_os( mut self, arg_id: T, @@ -3497,6 +3567,7 @@ impl<'help> Arg<'help> { /// ``` /// [`Arg::takes_value(true)`]: Arg::takes_value() /// [`Arg::default_value_if`]: Arg::default_value_if() + #[must_use] pub fn default_value_ifs( mut self, ifs: &[(T, Option<&'help str>, Option<&'help str>)], @@ -3512,6 +3583,7 @@ impl<'help> Arg<'help> { /// /// [`Arg::default_value_ifs`]: Arg::default_value_ifs() /// [`OsStr`]: std::ffi::OsStr + #[must_use] pub fn default_value_ifs_os( mut self, ifs: &[(T, Option<&'help OsStr>, Option<&'help OsStr>)], @@ -3574,6 +3646,7 @@ impl<'help> Arg<'help> { /// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument); /// ``` /// [required]: Arg::required() + #[must_use] pub fn required_unless_present(mut self, arg_id: T) -> Self { self.r_unless.push(arg_id.into()); self @@ -3644,6 +3717,7 @@ impl<'help> Arg<'help> { /// [required]: Arg::required() /// [`Arg::required_unless_present_any`]: Arg::required_unless_present_any() /// [`Arg::required_unless_present_all(names)`]: Arg::required_unless_present_all() + #[must_use] pub fn required_unless_present_all(mut self, names: I) -> Self where I: IntoIterator, @@ -3720,6 +3794,7 @@ impl<'help> Arg<'help> { /// [required]: Arg::required() /// [`Arg::required_unless_present_any(names)`]: Arg::required_unless_present_any() /// [`Arg::required_unless_present_all`]: Arg::required_unless_present_all() + #[must_use] pub fn required_unless_present_any(mut self, names: I) -> Self where I: IntoIterator, @@ -3810,6 +3885,7 @@ impl<'help> Arg<'help> { /// [`Arg::requires(name)`]: Arg::requires() /// [Conflicting]: Arg::conflicts_with() /// [required]: Arg::required() + #[must_use] pub fn required_if_eq(mut self, arg_id: T, val: &'help str) -> Self { self.r_ifs.push((arg_id.into(), val)); self @@ -3888,6 +3964,7 @@ impl<'help> Arg<'help> { /// [`Arg::requires(name)`]: Arg::requires() /// [Conflicting]: Arg::conflicts_with() /// [required]: Arg::required() + #[must_use] pub fn required_if_eq_any(mut self, ifs: &[(T, &'help str)]) -> Self { self.r_ifs .extend(ifs.iter().map(|(id, val)| (Id::from_ref(id), *val))); @@ -3965,6 +4042,7 @@ impl<'help> Arg<'help> { /// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument); /// ``` /// [required]: Arg::required() + #[must_use] pub fn required_if_eq_all(mut self, ifs: &[(T, &'help str)]) -> Self { self.r_ifs_all .extend(ifs.iter().map(|(id, val)| (Id::from_ref(id), *val))); @@ -4028,6 +4106,7 @@ impl<'help> Arg<'help> { /// [`Arg::requires(name)`]: Arg::requires() /// [Conflicting]: Arg::conflicts_with() /// [override]: Arg::overrides_with() + #[must_use] pub fn requires_if(mut self, val: &'help str, arg_id: T) -> Self { self.requires.push((Some(val), arg_id.into())); self @@ -4079,6 +4158,7 @@ impl<'help> Arg<'help> { /// [`Arg::requires(name)`]: Arg::requires() /// [Conflicting]: Arg::conflicts_with() /// [override]: Arg::overrides_with() + #[must_use] pub fn requires_ifs(mut self, ifs: &[(&'help str, T)]) -> Self { self.requires .extend(ifs.iter().map(|(val, arg)| (Some(*val), Id::from(arg)))); @@ -4149,6 +4229,7 @@ impl<'help> Arg<'help> { /// ``` /// [Conflicting]: Arg::conflicts_with() /// [override]: Arg::overrides_with() + #[must_use] pub fn requires_all(mut self, names: &[T]) -> Self { self.requires.extend(names.iter().map(|s| (None, s.into()))); self @@ -4199,6 +4280,7 @@ impl<'help> Arg<'help> { /// /// [`Arg::conflicts_with_all(names)`]: Arg::conflicts_with_all() /// [`Arg::exclusive(true)`]: Arg::exclusive() + #[must_use] pub fn conflicts_with(mut self, arg_id: T) -> Self { self.blacklist.push(arg_id.into()); self @@ -4251,6 +4333,7 @@ impl<'help> Arg<'help> { /// ``` /// [`Arg::conflicts_with`]: Arg::conflicts_with() /// [`Arg::exclusive(true)`]: Arg::exclusive() + #[must_use] pub fn conflicts_with_all(mut self, names: &[&str]) -> Self { self.blacklist.extend(names.iter().map(Id::from)); self @@ -4366,6 +4449,7 @@ impl<'help> Arg<'help> { /// assert_eq!(m.occurrences_of("opt"), 2); /// assert_eq!(m.values_of("opt").unwrap().collect::>(), &["first", "over", "other", "val"]); /// ``` + #[must_use] pub fn overrides_with(mut self, arg_id: T) -> Self { self.overrides.push(arg_id.into()); self @@ -4399,6 +4483,7 @@ impl<'help> Arg<'help> { /// assert!(!m.is_present("debug")); /// assert!(!m.is_present("flag")); /// ``` + #[must_use] pub fn overrides_with_all(mut self, names: &[T]) -> Self { self.overrides.extend(names.iter().map(Id::from)); self @@ -4686,6 +4771,7 @@ impl<'help> Arg<'help> { /// Deprecated, replaced with [`Arg::required_unless_present`] #[deprecated(since = "3.0.0", note = "Replaced with `Arg::required_unless_present`")] + #[must_use] pub fn required_unless(self, arg_id: T) -> Self { self.required_unless_present(arg_id) } @@ -4695,6 +4781,7 @@ impl<'help> Arg<'help> { since = "3.0.0", note = "Replaced with `Arg::required_unless_present_all`" )] + #[must_use] pub fn required_unless_all(self, names: I) -> Self where I: IntoIterator, @@ -4708,6 +4795,7 @@ impl<'help> Arg<'help> { since = "3.0.0", note = "Replaced with `Arg::required_unless_present_any`" )] + #[must_use] pub fn required_unless_one(self, names: I) -> Self where I: IntoIterator, @@ -4718,12 +4806,14 @@ impl<'help> Arg<'help> { /// Deprecated, replaced with [`Arg::required_if_eq`] #[deprecated(since = "3.0.0", note = "Replaced with `Arg::required_if_eq`")] + #[must_use] pub fn required_if(self, arg_id: T, val: &'help str) -> Self { self.required_if_eq(arg_id, val) } /// Deprecated, replaced with [`Arg::required_if_eq_any`] #[deprecated(since = "3.0.0", note = "Replaced with `Arg::required_if_eq_any`")] + #[must_use] pub fn required_ifs(self, ifs: &[(T, &'help str)]) -> Self { self.required_if_eq_any(ifs) } @@ -4731,6 +4821,7 @@ impl<'help> Arg<'help> { /// Deprecated, replaced with [`Arg::hide`] #[deprecated(since = "3.0.0", note = "Replaced with `Arg::hide`")] #[inline] + #[must_use] pub fn hidden(self, yes: bool) -> Self { self.hide(yes) } @@ -4738,12 +4829,14 @@ impl<'help> Arg<'help> { /// Deprecated, replaced with [`Arg::ignore_case`] #[deprecated(since = "3.0.0", note = "Replaced with `Arg::ignore_case`")] #[inline] + #[must_use] pub fn case_insensitive(self, yes: bool) -> Self { self.ignore_case(yes) } /// Deprecated, replaced with [`Arg::forbid_empty_values`] #[deprecated(since = "3.0.0", note = "Replaced with `Arg::forbid_empty_values`")] + #[must_use] pub fn empty_values(self, yes: bool) -> Self { self.forbid_empty_values(!yes) } @@ -4754,6 +4847,7 @@ impl<'help> Arg<'help> { since = "3.0.0", note = "Split into `Arg::multiple_occurrences` (most likely what you want) and `Arg::multiple_values`" )] + #[must_use] pub fn multiple(self, yes: bool) -> Self { self.multiple_occurrences(yes).multiple_values(yes) } @@ -4761,6 +4855,7 @@ impl<'help> Arg<'help> { /// Deprecated, replaced with [`Arg::hide_short_help`] #[deprecated(since = "3.0.0", note = "Replaced with `Arg::hide_short_help`")] #[inline] + #[must_use] pub fn hidden_short_help(self, yes: bool) -> Self { self.hide_short_help(yes) } @@ -4768,18 +4863,21 @@ impl<'help> Arg<'help> { /// Deprecated, replaced with [`Arg::hide_long_help`] #[deprecated(since = "3.0.0", note = "Replaced with `Arg::hide_long_help`")] #[inline] + #[must_use] pub fn hidden_long_help(self, yes: bool) -> Self { self.hide_long_help(yes) } /// Deprecated, replaced with [`Arg::setting`] #[deprecated(since = "3.0.0", note = "Replaced with `Arg::setting`")] + #[must_use] pub fn set(self, s: ArgSettings) -> Self { self.setting(s) } /// Deprecated, replaced with [`Arg::unset_setting`] #[deprecated(since = "3.0.0", note = "Replaced with `Arg::unset_setting`")] + #[must_use] pub fn unset(self, s: ArgSettings) -> Self { self.unset_setting(s) } diff --git a/src/build/arg/possible_value.rs b/src/build/arg/possible_value.rs index f9433315aa9..0bd795c3f3a 100644 --- a/src/build/arg/possible_value.rs +++ b/src/build/arg/possible_value.rs @@ -71,6 +71,7 @@ impl<'help> PossibleValue<'help> { /// # ; /// ``` #[inline] + #[must_use] pub fn help(mut self, help: &'help str) -> Self { self.help = Some(help); self @@ -91,6 +92,7 @@ impl<'help> PossibleValue<'help> { /// ``` /// [`Arg::hide_possible_values(true)`]: crate::Arg::hide_possible_values() #[inline] + #[must_use] pub fn hide(mut self, yes: bool) -> Self { self.hide = yes; self @@ -106,6 +108,7 @@ impl<'help> PossibleValue<'help> { /// .alias("not-fast") /// # ; /// ``` + #[must_use] pub fn alias(mut self, name: &'help str) -> Self { self.aliases.push(name); self @@ -121,6 +124,7 @@ impl<'help> PossibleValue<'help> { /// .aliases(["not-fast", "snake-like"]) /// # ; /// ``` + #[must_use] pub fn aliases(mut self, names: I) -> Self where I: IntoIterator, diff --git a/src/build/arg_group.rs b/src/build/arg_group.rs index 3b9b015b446..49d95a869fe 100644 --- a/src/build/arg_group.rs +++ b/src/build/arg_group.rs @@ -121,6 +121,7 @@ impl<'help> ArgGroup<'help> { /// ArgGroup::default().name("config") /// # ; /// ``` + #[must_use] pub fn name>(mut self, n: S) -> Self { self.name = n.into(); self.id = Id::from(&self.name); @@ -148,6 +149,7 @@ impl<'help> ArgGroup<'help> { /// assert!(m.is_present("flag")); /// ``` /// [argument]: crate::Arg + #[must_use] pub fn arg(mut self, arg_id: T) -> Self { self.args.push(arg_id.into()); self @@ -173,6 +175,7 @@ impl<'help> ArgGroup<'help> { /// assert!(m.is_present("flag")); /// ``` /// [arguments]: crate::Arg + #[must_use] pub fn args(mut self, ns: &[T]) -> Self { for n in ns { self = self.arg(n); @@ -222,6 +225,7 @@ impl<'help> ArgGroup<'help> { /// /// [`Arg`]: crate::Arg #[inline] + #[must_use] pub fn multiple(mut self, yes: bool) -> Self { self.multiple = yes; self @@ -266,6 +270,7 @@ impl<'help> ArgGroup<'help> { /// [`ArgGroup::multiple`]: ArgGroup::multiple() /// [`App`]: crate::App #[inline] + #[must_use] pub fn required(mut self, yes: bool) -> Self { self.required = yes; self @@ -305,6 +310,7 @@ impl<'help> ArgGroup<'help> { /// ``` /// [required group]: ArgGroup::required() /// [argument requirement rules]: crate::Arg::requires() + #[must_use] pub fn requires(mut self, id: T) -> Self { self.requires.push(id.into()); self @@ -346,6 +352,7 @@ impl<'help> ArgGroup<'help> { /// ``` /// [required group]: ArgGroup::required() /// [argument requirement rules]: crate::Arg::requires_all() + #[must_use] pub fn requires_all(mut self, ns: &[&'help str]) -> Self { for n in ns { self = self.requires(n); @@ -385,6 +392,7 @@ impl<'help> ArgGroup<'help> { /// assert_eq!(err.kind, ErrorKind::ArgumentConflict); /// ``` /// [argument exclusion rules]: crate::Arg::conflicts_with() + #[must_use] pub fn conflicts_with(mut self, id: T) -> Self { self.conflicts.push(id.into()); self @@ -425,6 +433,7 @@ impl<'help> ArgGroup<'help> { /// ``` /// /// [argument exclusion rules]: crate::Arg::conflicts_with_all() + #[must_use] pub fn conflicts_with_all(mut self, ns: &[&'help str]) -> Self { for n in ns { self = self.conflicts_with(n); diff --git a/src/lib.rs b/src/lib.rs index 02b4d6829e3..b9b4de27f21 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,8 @@ missing_copy_implementations, trivial_casts, unused_allocation, - trivial_numeric_casts + trivial_numeric_casts, + clippy::single_char_pattern )] #![forbid(unsafe_code)] // HACK https://github.com/rust-lang/rust-clippy/issues/7290 diff --git a/src/output/fmt.rs b/src/output/fmt.rs index e4317f799d1..a416935bb8a 100644 --- a/src/output/fmt.rs +++ b/src/output/fmt.rs @@ -8,6 +8,7 @@ use std::{ #[derive(Clone, Debug)] pub(crate) struct Colorizer { use_stderr: bool, + #[allow(unused)] color_when: ColorChoice, pieces: Vec<(String, Style)>, } diff --git a/src/output/help.rs b/src/output/help.rs index ed6bf218eb2..7544b0c18df 100644 --- a/src/output/help.rs +++ b/src/output/help.rs @@ -868,7 +868,7 @@ impl<'help, 'app, 'parser, 'writer> Help<'help, 'app, 'parser, 'writer> { let bin_name = if let Some(bn) = self.parser.app.bin_name.as_ref() { if bn.contains(' ') { // In case we're dealing with subcommands i.e. git mv is translated to git-mv - bn.replace(" ", "-") + bn.replace(' ', "-") } else { text_wrapper(&self.parser.app.name.replace("{n}", "\n"), self.term_w) } diff --git a/src/parse/errors.rs b/src/parse/errors.rs index 0e902337d09..0e889ad774f 100644 --- a/src/parse/errors.rs +++ b/src/parse/errors.rs @@ -456,6 +456,7 @@ impl Error { } /// Format the existing message with the App's context + #[must_use] pub fn format(mut self, app: &mut App) -> Self { app._build(); let usage = app.render_usage(); diff --git a/tests/builder/double_require.rs b/tests/builder/double_require.rs index 166c0a7fe30..71a99947f4a 100644 --- a/tests/builder/double_require.rs +++ b/tests/builder/double_require.rs @@ -68,7 +68,7 @@ fn help_text() { assert!(res.is_err()); let err = res.unwrap_err(); assert_eq!(err.kind, ErrorKind::DisplayHelp); - println!("{}", err.to_string()); + println!("{}", err); assert_eq!(err.to_string(), HELP); } diff --git a/tests/builder/utils.rs b/tests/builder/utils.rs index 56017c1a0e0..094531362e6 100644 --- a/tests/builder/utils.rs +++ b/tests/builder/utils.rs @@ -14,8 +14,8 @@ where { let re = Regex::new("\x1b[^m]*m").unwrap(); // Strip out any mismatching \r character on windows that might sneak in on either side - let ls = l.as_ref().replace("\r", ""); - let rs = r.as_ref().replace("\r", ""); + let ls = l.as_ref().replace('\r', ""); + let rs = r.as_ref().replace('\r', ""); let left_ = re.replace_all(&*ls, ""); let right = re.replace_all(&*rs, ""); let b = left_ == right;