From fa8540cb159730f9bc6df57d2ed614df7de3a1e9 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Thu, 26 Dec 2019 15:08:10 -0600 Subject: [PATCH] refactor/polish ~ fix `cargo clippy` complaints (DRY struct def) --- src/du/du.rs | 2 +- src/expr/syntax_tree.rs | 4 +-- src/install/install.rs | 4 +-- src/join/join.rs | 4 +-- src/ls/ls.rs | 2 +- src/numfmt/numfmt.rs | 6 ++-- src/od/inputdecoder.rs | 4 +-- src/od/inputoffset.rs | 6 ++-- src/od/od.rs | 18 +++++------ src/od/output_info.rs | 10 +++---- src/od/parse_formats.rs | 4 +-- src/od/parse_inputs.rs | 2 +- src/od/partialreader.rs | 6 ++-- src/od/peekreader.rs | 2 +- src/pinky/pinky.rs | 14 ++++----- .../num_format/formatters/base_conv/mod.rs | 2 +- src/printf/tokenize/sub.rs | 10 +++---- src/ptx/ptx.rs | 2 +- src/rm/rm.rs | 2 +- src/shred/shred.rs | 10 +++---- src/sort/sort.rs | 4 +-- src/stat/stat.rs | 14 ++++----- src/tee/tee.rs | 4 +-- src/tr/tr.rs | 6 ++-- src/unexpand/unexpand.rs | 8 ++--- src/who/who.rs | 30 +++++++++---------- 26 files changed, 90 insertions(+), 90 deletions(-) diff --git a/src/du/du.rs b/src/du/du.rs index fad2df371..905dd96ad 100644 --- a/src/du/du.rs +++ b/src/du/du.rs @@ -339,7 +339,7 @@ pub fn uumain(args: Vec) -> i32 { }; let convert_size_fn = { if matches.opt_present("human-readable") || matches.opt_present("si") { - convert_size_human + convert_size_human } else if matches.opt_present("b") { convert_size_b } else if matches.opt_present("k") { diff --git a/src/expr/syntax_tree.rs b/src/expr/syntax_tree.rs index 66b467bf6..39e8efcfb 100644 --- a/src/expr/syntax_tree.rs +++ b/src/expr/syntax_tree.rs @@ -68,9 +68,9 @@ impl ASTNode { fn new_node(token_idx: usize, op_type: &str, operands: OperandsList) -> Box { Box::new(ASTNode::Node { - token_idx: token_idx, + token_idx, op_type: op_type.into(), - operands: operands, + operands, }) } fn new_leaf(token_idx: usize, value: &str) -> Box { diff --git a/src/install/install.rs b/src/install/install.rs index 4d7aeb611..7112811df 100644 --- a/src/install/install.rs +++ b/src/install/install.rs @@ -244,8 +244,8 @@ fn behaviour(matches: &getopts::Matches) -> Result { }; Ok(Behaviour { - main_function: main_function, - specified_mode: specified_mode, + main_function, + specified_mode, suffix: backup_suffix, verbose: matches.opt_present("v"), }) diff --git a/src/join/join.rs b/src/join/join.rs index 9915e5130..a4f5c126e 100755 --- a/src/join/join.rs +++ b/src/join/join.rs @@ -260,9 +260,9 @@ impl<'a> State<'a> { }; State { - key: key, + key, file_name: name, - file_num: file_num, + file_num, print_unpaired: print_unpaired == file_num, lines: f.lines(), seq: Vec::new(), diff --git a/src/ls/ls.rs b/src/ls/ls.rs index 3a91b4a1c..c1cc909a6 100644 --- a/src/ls/ls.rs +++ b/src/ls/ls.rs @@ -697,7 +697,7 @@ fn display_file_name( Cell { contents: name, - width: width, + width, } } diff --git a/src/numfmt/numfmt.rs b/src/numfmt/numfmt.rs index 8b2c09343..87bf53bcb 100644 --- a/src/numfmt/numfmt.rs +++ b/src/numfmt/numfmt.rs @@ -251,9 +251,9 @@ fn parse_options(args: &Matches) -> Result { }?; Ok(NumfmtOptions { - transform: transform, - padding: padding, - header: header, + transform, + padding, + header, }) } diff --git a/src/od/inputdecoder.rs b/src/od/inputdecoder.rs index cd4a0feec..947bf1111 100644 --- a/src/od/inputdecoder.rs +++ b/src/od/inputdecoder.rs @@ -43,12 +43,12 @@ impl<'a, I> InputDecoder<'a, I> { } // fast but uninitialized InputDecoder { - input: input, + input, data: bytes, reserved_peek_length: peek_length, used_normal_length: 0, used_peek_length: 0, - byte_order: byte_order, + byte_order, } } } diff --git a/src/od/inputoffset.rs b/src/od/inputoffset.rs index 7f2fca559..8f3030edf 100644 --- a/src/od/inputoffset.rs +++ b/src/od/inputoffset.rs @@ -21,9 +21,9 @@ impl InputOffset { /// creates a new `InputOffset` using the provided values. pub fn new(radix: Radix, byte_pos: usize, label: Option) -> InputOffset { InputOffset { - radix: radix, - byte_pos: byte_pos, - label: label, + radix, + byte_pos, + label, } } diff --git a/src/od/od.rs b/src/od/od.rs index d10227fa9..1b8c153e2 100644 --- a/src/od/od.rs +++ b/src/od/od.rs @@ -276,15 +276,15 @@ impl OdOptions { }; Ok(OdOptions { - byte_order: byte_order, - skip_bytes: skip_bytes, - read_bytes: read_bytes, - label: label, - input_strings: input_strings, - formats: formats, - line_bytes: line_bytes, - output_duplicates: output_duplicates, - radix: radix, + byte_order, + skip_bytes, + read_bytes, + label, + input_strings, + formats, + line_bytes, + output_duplicates, + radix, }) } } diff --git a/src/od/output_info.rs b/src/od/output_info.rs index eaf46296c..edcccd913 100644 --- a/src/od/output_info.rs +++ b/src/od/output_info.rs @@ -69,11 +69,11 @@ impl OutputInfo { OutputInfo { byte_size_line: line_bytes, - print_width_line: print_width_line, - byte_size_block: byte_size_block, - print_width_block: print_width_block, - spaced_formatters: spaced_formatters, - output_duplicates: output_duplicates, + print_width_line, + byte_size_block, + print_width_block, + spaced_formatters, + output_duplicates, } } diff --git a/src/od/parse_formats.rs b/src/od/parse_formats.rs index 2a03baa7a..d6318d274 100644 --- a/src/od/parse_formats.rs +++ b/src/od/parse_formats.rs @@ -15,8 +15,8 @@ impl ParsedFormatterItemInfo { add_ascii_dump: bool, ) -> ParsedFormatterItemInfo { ParsedFormatterItemInfo { - formatter_item_info: formatter_item_info, - add_ascii_dump: add_ascii_dump, + formatter_item_info, + add_ascii_dump, } } } diff --git a/src/od/parse_inputs.rs b/src/od/parse_inputs.rs index 033a2e4b3..5f8bbf147 100644 --- a/src/od/parse_inputs.rs +++ b/src/od/parse_inputs.rs @@ -177,7 +177,7 @@ mod tests { fn new(inputs: Vec<&'a str>, option_names: Vec<&'a str>) -> MockOptions<'a> { MockOptions { inputs: inputs.iter().map(|s| s.to_string()).collect::>(), - option_names: option_names, + option_names, } } } diff --git a/src/od/partialreader.rs b/src/od/partialreader.rs index 42bca6428..d8e2310d2 100644 --- a/src/od/partialreader.rs +++ b/src/od/partialreader.rs @@ -22,9 +22,9 @@ impl PartialReader { /// to `None` if there should be no limit. pub fn new(inner: R, skip: usize, limit: Option) -> Self { PartialReader { - inner: inner, - skip: skip, - limit: limit, + inner, + skip, + limit, } } } diff --git a/src/od/peekreader.rs b/src/od/peekreader.rs index 47b05d678..10428a77f 100644 --- a/src/od/peekreader.rs +++ b/src/od/peekreader.rs @@ -41,7 +41,7 @@ impl PeekReader { /// Create a new `PeekReader` wrapping `inner` pub fn new(inner: R) -> Self { PeekReader { - inner: inner, + inner, temp_buffer: Vec::new(), } } diff --git a/src/pinky/pinky.rs b/src/pinky/pinky.rs index 97cd00f9a..7b6c0ab5f 100644 --- a/src/pinky/pinky.rs +++ b/src/pinky/pinky.rs @@ -125,13 +125,13 @@ The utmp file will be {}", } let pk = Pinky { - include_idle: include_idle, - include_heading: include_heading, - include_fullname: include_fullname, - include_project: include_project, - include_plan: include_plan, - include_home_and_shell: include_home_and_shell, - include_where: include_where, + include_idle, + include_heading, + include_fullname, + include_project, + include_plan, + include_home_and_shell, + include_where, names: matches.free, }; diff --git a/src/printf/tokenize/num_format/formatters/base_conv/mod.rs b/src/printf/tokenize/num_format/formatters/base_conv/mod.rs index 2aaa5acbd..1c8bba5a3 100644 --- a/src/printf/tokenize/num_format/formatters/base_conv/mod.rs +++ b/src/printf/tokenize/num_format/formatters/base_conv/mod.rs @@ -96,7 +96,7 @@ pub fn arrnum_int_div_step<'a>( } } DivOut { - quotient: quotient, + quotient, remainder: rem_out, } } diff --git a/src/printf/tokenize/sub.rs b/src/printf/tokenize/sub.rs index bab586baa..933da7af1 100644 --- a/src/printf/tokenize/sub.rs +++ b/src/printf/tokenize/sub.rs @@ -80,11 +80,11 @@ impl Sub { } }; Sub { - min_width: min_width, - second_field: second_field, - field_char: field_char, - field_type: field_type, - orig: orig, + min_width, + second_field, + field_char, + field_type, + orig, } } } diff --git a/src/ptx/ptx.rs b/src/ptx/ptx.rs index b79924541..1d5fd0431 100644 --- a/src/ptx/ptx.rs +++ b/src/ptx/ptx.rs @@ -248,7 +248,7 @@ fn create_word_set( word = word.to_lowercase(); } word_set.insert(WordRef { - word: word, + word, filename: file.clone(), global_line_nr: offs + count, local_line_nr: count, diff --git a/src/rm/rm.rs b/src/rm/rm.rs index 1d10e446b..75355ffbf 100644 --- a/src/rm/rm.rs +++ b/src/rm/rm.rs @@ -109,7 +109,7 @@ pub fn uumain(args: Vec) -> i32 { return 1; } else { let options = Options { - force: force, + force, interactive: { if matches.opt_present("i") { InteractiveMode::InteractiveAlways diff --git a/src/shred/shred.rs b/src/shred/shred.rs index e537480b0..189c1c7a3 100644 --- a/src/shred/shred.rs +++ b/src/shred/shred.rs @@ -76,7 +76,7 @@ impl FilenameGenerator { indices.push(0); } FilenameGenerator { - name_len: name_len, + name_len, nameset_indices: RefCell::new(indices), exhausted: Cell::new(false), } @@ -137,12 +137,12 @@ impl<'a> BytesGenerator<'a> { }; BytesGenerator { - total_bytes: total_bytes, + total_bytes, bytes_generated: Cell::new(0u64), block_size: BLOCK_SIZE, - exact: exact, - gen_type: gen_type, - rng: rng, + exact, + gen_type, + rng, } } } diff --git a/src/sort/sort.rs b/src/sort/sort.rs index 54680b8a7..b7bebcbb0 100644 --- a/src/sort/sort.rs +++ b/src/sort/sort.rs @@ -106,14 +106,14 @@ impl<'a> FileMerger<'a> { fn new(settings: &'a Settings) -> FileMerger<'a> { FileMerger { heap: BinaryHeap::new(), - settings: settings, + settings, } } fn push_file(&mut self, mut lines: Lines>>) { match lines.next() { Some(Ok(next_line)) => { let mergeable_file = MergeableFile { - lines: lines, + lines, current_line: next_line, settings: &self.settings, }; diff --git a/src/stat/stat.rs b/src/stat/stat.rs index 2aa8a0d44..caef583e0 100644 --- a/src/stat/stat.rs +++ b/src/stat/stat.rs @@ -396,9 +396,9 @@ impl Stater { i = j; tokens.push(Token::Directive { - width: width, - flag: flag, - precision: precision, + width, + flag, + precision, format: chars[i], }) } @@ -492,12 +492,12 @@ impl Stater { Ok(Stater { follow: matches.opt_present("dereference"), - showfs: showfs, + showfs, from_user: !fmtstr.is_empty(), files: matches.free, - default_tokens: default_tokens, - default_dev_tokens: default_dev_tokens, - mount_list: mount_list, + default_tokens, + default_dev_tokens, + mount_list, }) } diff --git a/src/tee/tee.rs b/src/tee/tee.rs index de77d8555..7421d69e6 100644 --- a/src/tee/tee.rs +++ b/src/tee/tee.rs @@ -119,8 +119,8 @@ fn open(name: String, append: bool) -> Box { } }; Box::new(NamedWriter { - inner: inner, - path: path, + inner, + path, }) as Box } diff --git a/src/tr/tr.rs b/src/tr/tr.rs index 42566141a..069d0fbc4 100644 --- a/src/tr/tr.rs +++ b/src/tr/tr.rs @@ -45,7 +45,7 @@ impl DeleteOperation { fn new(set: ExpandSet, complement: bool) -> DeleteOperation { DeleteOperation { bset: set.map(|c| c as usize).collect(), - complement: complement, + complement, } } } @@ -70,7 +70,7 @@ impl SqueezeOperation { fn new(squeeze_set: ExpandSet, complement: bool) -> SqueezeOperation { SqueezeOperation { squeeze_set: squeeze_set.map(|c| c as usize).collect(), - complement: complement, + complement, } } } @@ -100,7 +100,7 @@ impl DeleteAndSqueezeOperation { DeleteAndSqueezeOperation { delete_set: delete_set.map(|c| c as usize).collect(), squeeze_set: squeeze_set.map(|c| c as usize).collect(), - complement: complement, + complement, } } } diff --git a/src/unexpand/unexpand.rs b/src/unexpand/unexpand.rs index 2cee398dd..8ce009c9f 100644 --- a/src/unexpand/unexpand.rs +++ b/src/unexpand/unexpand.rs @@ -76,10 +76,10 @@ impl Options { }; Options { - files: files, - tabstops: tabstops, - aflag: aflag, - uflag: uflag, + files, + tabstops, + aflag, + uflag, } } } diff --git a/src/who/who.rs b/src/who/who.rs index 68972be1f..18fb862d4 100644 --- a/src/who/who.rs +++ b/src/who/who.rs @@ -204,21 +204,21 @@ pub fn uumain(args: Vec) -> i32 { } let mut who = Who { - do_lookup: do_lookup, - short_list: short_list, - short_output: short_output, - include_idle: include_idle, - include_heading: include_heading, - include_mesg: include_mesg, - include_exit: include_exit, - need_boottime: need_boottime, - need_deadprocs: need_deadprocs, - need_login: need_login, - need_initspawn: need_initspawn, - need_clockchange: need_clockchange, - need_runlevel: need_runlevel, - need_users: need_users, - my_line_only: my_line_only, + do_lookup, + short_list, + short_output, + include_idle, + include_heading, + include_mesg, + include_exit, + need_boottime, + need_deadprocs, + need_login, + need_initspawn, + need_clockchange, + need_runlevel, + need_users, + my_line_only, has_records: false, args: matches.free, };