From 905d3b97775e1208645919beeda9e23d4b9c3231 Mon Sep 17 00:00:00 2001 From: Salim Afiune Date: Tue, 4 Oct 2016 09:54:45 -0400 Subject: [PATCH] Fix linting errors from rustc 1.14.0 The new version of rustc 1.14.0-nightly (144af3e97 2016-10-02) has new linting warnings/errors. This commit fixes them. Signed-off-by: Salim Afiune --- src/app/help.rs | 22 +++++++++++----------- src/app/mod.rs | 2 +- src/app/parser.rs | 10 +++++----- src/suggestions.rs | 2 +- tests/arg_aliases.rs | 18 +++++------------- 5 files changed, 23 insertions(+), 31 deletions(-) diff --git a/src/app/help.rs b/src/app/help.rs index dc07944af7d..1bd23f45b66 100644 --- a/src/app/help.rs +++ b/src/app/help.rs @@ -212,8 +212,8 @@ impl<'a> Help<'a> { } } let mut first = true; - for (_, btm) in ord_m.into_iter() { - for (_, arg) in btm.into_iter() { + for (_, btm) in ord_m { + for arg in btm.values() { if !first { try!(self.writer.write(b"\n")); } else { @@ -380,11 +380,11 @@ impl<'a> Help<'a> { help.push_str(h); &*help }; - if help.contains("\n") { - if let Some(part) = help.split("\n").next() { + if help.contains('\n') { + if let Some(part) = help.split('\n').next() { try!(write!(self.writer, "{}", part)); } - for part in help.split("\n").skip(1) { + for part in help.split('\n').skip(1) { try!(write!(self.writer, "\n{}", part)); } } else { @@ -464,11 +464,11 @@ impl<'a> Help<'a> { help.push_str(&*spec_vals); &*help }; - if help.contains("\n") { - if let Some(part) = help.split("\n").next() { + if help.contains('\n') { + if let Some(part) = help.split('\n').next() { try!(write!(self.writer, "{}", part)); } - for part in help.split("\n").skip(1) { + for part in help.split('\n').skip(1) { try!(write!(self.writer, "\n")); if nlh || force_next_line { try!(write!(self.writer, "{}{}{}", TAB, TAB, TAB)); @@ -616,14 +616,14 @@ impl<'a> Help<'a> { } let mut first = true; - for (_, btm) in ord_m.into_iter() { - for (_, sc) in btm.into_iter() { + for (_, btm) in ord_m { + for sc in btm.values() { if !first { try!(self.writer.write(b"\n")); } else { first = false; } - try!(self.write_arg(&sc, longest)); + try!(self.write_arg(sc, longest)); } } Ok(()) diff --git a/src/app/mod.rs b/src/app/mod.rs index 86d73a0fb92..d95261143be 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -928,7 +928,7 @@ impl<'a, 'b> App<'a, 'b> { pub fn subcommands(mut self, subcmds: I) -> Self where I: IntoIterator> { - for subcmd in subcmds.into_iter() { + for subcmd in subcmds { self.p.add_subcommand(subcmd); } self diff --git a/src/app/parser.rs b/src/app/parser.rs index 099bc30a699..4a17e2bb513 100644 --- a/src/app/parser.rs +++ b/src/app/parser.rs @@ -355,13 +355,13 @@ impl<'a, 'b> Parser<'a, 'b> grps.dedup(); let mut args_in_groups = vec![]; for g in &grps { - for a in self.arg_names_in_group(g).into_iter() { + for a in self.arg_names_in_group(g) { args_in_groups.push(a); } } let mut pmap = BTreeMap::new(); - for p in c_pos.into_iter() { + for p in c_pos { if matcher.is_some() && matcher.as_ref().unwrap().contains(p) { continue; } @@ -382,7 +382,7 @@ impl<'a, 'b> Parser<'a, 'b> } macro_rules! write_arg { ($i:expr, $m:ident, $v:ident, $r:ident, $aig:ident) => { - for f in $v.into_iter() { + for f in $v { if $m.is_some() && $m.as_ref().unwrap().contains(f) || $aig.contains(&f) { continue; } @@ -393,13 +393,13 @@ impl<'a, 'b> Parser<'a, 'b> write_arg!(self.flags.iter(), matcher, c_flags, ret_val, args_in_groups); write_arg!(self.opts.iter(), matcher, c_opt, ret_val, args_in_groups); let mut g_vec = vec![]; - for g in grps.into_iter() { + for g in grps { let g_string = self.args_in_group(g) .join("|"); g_vec.push(format!("<{}>", &g_string[..g_string.len()])); } g_vec.dedup(); - for g in g_vec.into_iter() { + for g in g_vec { ret_val.push_back(g); } diff --git a/src/suggestions.rs b/src/suggestions.rs index 9633de7bc36..d11c6646391 100644 --- a/src/suggestions.rs +++ b/src/suggestions.rs @@ -17,7 +17,7 @@ pub fn did_you_mean<'a, T, I>(v: &str, possible_values: I) -> Option<&'a str> { let mut candidate: Option<(f64, &str)> = None; - for pv in possible_values.into_iter() { + for pv in possible_values { let confidence = strsim::jaro_winkler(v, pv.as_ref()); if confidence > 0.8 && (candidate.is_none() || (candidate.as_ref().unwrap().0 < confidence)) { diff --git a/tests/arg_aliases.rs b/tests/arg_aliases.rs index 68620a60de5..9c1c419ea79 100644 --- a/tests/arg_aliases.rs +++ b/tests/arg_aliases.rs @@ -12,12 +12,10 @@ USAGE: test [FLAGS] [OPTIONS] FLAGS: - -f, --flag - flag with aliases [aliases: v_flg, flag2, flg3] + -f, --flag [aliases: v_flg, flag2, flg3] OPTIONS: - -o, --opt - help for option with alias [aliases: visible]"; + -o, --opt [aliases: visible]"; static SC_INVISIBLE_ALIAS_HELP: &'static str = "test Some help @@ -26,10 +24,10 @@ USAGE: test [FLAGS] [OPTIONS] FLAGS: - -f, --flag flag with aliases + -f, --flag OPTIONS: - -o, --opt help for option with alias"; + -o, --opt "; #[test] fn single_alias_of_option() { @@ -169,13 +167,9 @@ fn invisible_arg_aliases_help_output() { .arg(Arg::with_name("opt") .long("opt") .short("o") - .help("help for option with alias") .takes_value(true) .aliases(&["invisible", "als1", "more"])) - .arg(Arg::with_name("flg") - .long("flag") - .short("f") - .help("flag with aliases") + .arg(Arg::from_usage("-f, --flag") .aliases(&["invisible", "flg1", "anyway"]))); test::check_subcommand_help(app, "test", SC_INVISIBLE_ALIAS_HELP); } @@ -189,14 +183,12 @@ fn visible_arg_aliases_help_output() { .arg(Arg::with_name("opt") .long("opt") .short("o") - .help("help for option with alias") .takes_value(true) .alias("invisible") .visible_alias("visible")) .arg(Arg::with_name("flg") .long("flag") .short("f") - .help("flag with aliases") .visible_aliases(&["v_flg", "flag2", "flg3"]))); test::check_subcommand_help(app, "test", SC_VISIBLE_ALIAS_HELP); }