From 4034a322a2bf2df7f885121e2c7a259d61e588ad Mon Sep 17 00:00:00 2001 From: Vinzent Steinberg Date: Mon, 3 Sep 2018 19:02:51 +0200 Subject: [PATCH 1/3] Fix a few clippy warnings --- src/basename/basename.rs | 2 +- src/cat/cat.rs | 47 +++++++++++----------------- src/chgrp/chgrp.rs | 14 ++++----- src/chmod/chmod.rs | 20 ++++++------ src/chown/chown.rs | 18 +++++------ src/chroot/chroot.rs | 2 +- src/cksum/cksum.rs | 6 ++-- src/comm/comm.rs | 6 ++-- src/cp/cp.rs | 4 +-- src/cut/buffer.rs | 9 +++--- src/cut/cut.rs | 52 +++++++++++++------------------ src/cut/ranges.rs | 12 +++---- src/cut/searcher.rs | 4 +-- src/date/date.rs | 64 ++++++++++++++++++-------------------- src/dircolors/colors.rs | 2 +- src/dircolors/dircolors.rs | 22 ++++++------- src/du/du.rs | 42 ++++++++++++------------- src/env/env.rs | 4 +-- src/expand/expand.rs | 10 +++--- src/expr/expr.rs | 12 +++---- src/expr/syntax_tree.rs | 45 +++++++++++++++------------ src/expr/tokens.rs | 14 ++++----- src/uucore/coreopts.rs | 2 +- src/uucore/encoding.rs | 4 +-- src/uucore/fs.rs | 2 +- src/yes/yes.rs | 2 +- 26 files changed, 201 insertions(+), 220 deletions(-) diff --git a/src/basename/basename.rs b/src/basename/basename.rs index 719a6addf..fa8e03e50 100644 --- a/src/basename/basename.rs +++ b/src/basename/basename.rs @@ -44,7 +44,7 @@ pub fn uumain(args: Vec) -> i32 { .parse(args); // too few arguments - if matches.free.len() < 1 { + if matches.free.is_empty() { crash!( 1, "{0}: {1}\nTry '{0} --help' for more information.", diff --git a/src/cat/cat.rs b/src/cat/cat.rs index 9aef7114e..38b5753e1 100644 --- a/src/cat/cat.rs +++ b/src/cat/cat.rs @@ -174,32 +174,23 @@ pub fn uumain(args: Vec) -> i32 { let success = if can_write_fast { write_fast(files).is_ok() } else { - let tab = match show_tabs { - true => "^I", - false => "\t", - }.to_owned(); + let tab = if show_tabs { "^I" } else { "\t" }.to_owned(); - let end_of_line = match show_ends { - true => "$\n", - false => "\n", - }.to_owned(); + let end_of_line = if show_ends { "$\n" } else { "\n" }.to_owned(); let options = OutputOptions { - end_of_line: end_of_line, + end_of_line, number: number_mode, - show_nonprint: show_nonprint, - show_tabs: show_tabs, - squeeze_blank: squeeze_blank, - tab: tab, + show_nonprint, + show_tabs, + squeeze_blank, + tab, }; write_lines(files, &options).is_ok() }; - match success { - true => 0, - false => 1, - } + if success { 0 } else { 1 } } /// Classifies the `InputType` of file at `path` if possible @@ -363,7 +354,7 @@ fn write_file_lines(file: &str, options: &OutputOptions, state: &mut OutputState let mut pos = 0; while pos < n { // skip empty line_number enumerating them if needed - if in_buf[pos] == '\n' as u8 { + if in_buf[pos] == b'\n' { if !state.at_line_start || !options.squeeze_blank || !one_blank_kept { one_blank_kept = true; if state.at_line_start && options.number == NumberingMode::NumberAll { @@ -415,7 +406,7 @@ fn write_file_lines(file: &str, options: &OutputOptions, state: &mut OutputState // Write all symbols till end of line or end of buffer is reached // Return the (number of written symbols + 1) or 0 if the end of buffer is reached fn write_to_end(in_buf: &[u8], writer: &mut W) -> usize { - match in_buf.iter().position(|c| *c == '\n' as u8) { + match in_buf.iter().position(|c| *c == b'\n') { Some(p) => { writer.write_all(&in_buf[..p]).unwrap(); p + 1 @@ -431,14 +422,14 @@ fn write_tab_to_end(mut in_buf: &[u8], writer: &mut W) -> usize { loop { match in_buf .iter() - .position(|c| *c == '\n' as u8 || *c == '\t' as u8) + .position(|c| *c == b'\n' || *c == b'\t') { Some(p) => { writer.write_all(&in_buf[..p]).unwrap(); - if in_buf[p] == '\n' as u8 { + if in_buf[p] == b'\n' { return p + 1; } else { - writer.write_all("^I".as_bytes()).unwrap(); + writer.write_all(b"^I").unwrap(); in_buf = &in_buf[p + 1..]; } } @@ -454,17 +445,17 @@ fn write_nonprint_to_end(in_buf: &[u8], writer: &mut W, tab: &[u8]) -> let mut count = 0; for byte in in_buf.iter().map(|c| *c) { - if byte == '\n' as u8 { + if byte == b'\n' { break; } match byte { 9 => writer.write_all(tab), - 0...8 | 10...31 => writer.write_all(&['^' as u8, byte + 64]), + 0...8 | 10...31 => writer.write_all(&[b'^', byte + 64]), 32...126 => writer.write_all(&[byte]), - 127 => writer.write_all(&['^' as u8, byte - 64]), - 128...159 => writer.write_all(&['M' as u8, '-' as u8, '^' as u8, byte - 64]), - 160...254 => writer.write_all(&['M' as u8, '-' as u8, byte - 128]), - _ => writer.write_all(&['M' as u8, '-' as u8, '^' as u8, 63]), + 127 => writer.write_all(&[b'^', byte - 64]), + 128...159 => writer.write_all(&[b'M', b'-', b'^', byte - 64]), + 160...254 => writer.write_all(&[b'M', b'-', byte - 128]), + _ => writer.write_all(&[b'M', b'-', b'^', 63]), }.unwrap(); count += 1; } diff --git a/src/chgrp/chgrp.rs b/src/chgrp/chgrp.rs index a312c45f2..a5e0aa52b 100644 --- a/src/chgrp/chgrp.rs +++ b/src/chgrp/chgrp.rs @@ -117,7 +117,7 @@ pub fn uumain(args: Vec) -> i32 { Verbosity::Normal }; - if matches.free.len() < 1 { + if matches.free.is_empty() { disp_err!("missing operand"); return 1; } else if matches.free.len() < 2 && !matches.opt_present("reference") { @@ -153,13 +153,13 @@ pub fn uumain(args: Vec) -> i32 { } let executor = Chgrper { - bit_flag: bit_flag, - dest_gid: dest_gid, - verbosity: verbosity, - recursive: recursive, + bit_flag, + dest_gid, + verbosity, + recursive, dereference: derefer != 0, - preserve_root: preserve_root, - files: files, + preserve_root, + files, }; executor.exec() } diff --git a/src/chmod/chmod.rs b/src/chmod/chmod.rs index bfb6e2a4d..6cd1f6373 100644 --- a/src/chmod/chmod.rs +++ b/src/chmod/chmod.rs @@ -24,10 +24,10 @@ use walker::Walker; use uucore::mode; use uucore::fs::display_permissions_unix; -const NAME: &'static str = "chmod"; -static SUMMARY: &'static str = "Change the mode of each FILE to MODE. +const NAME: &str = "chmod"; +static SUMMARY: &str = "Change the mode of each FILE to MODE. With --reference, change the mode of each FILE to that of RFILE."; -static LONG_HELP: &'static str = " +static LONG_HELP: &str = " Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'. "; @@ -81,13 +81,13 @@ pub fn uumain(mut args: Vec) -> i32 { None }; let chmoder = Chmoder { - changes: changes, - quiet: quiet, - verbose: verbose, - preserve_root: preserve_root, - recursive: recursive, - fmode: fmode, - cmode: cmode, + changes, + quiet, + verbose, + preserve_root, + recursive, + fmode, + cmode, }; match chmoder.chmod(matches.free) { Ok(()) => {} diff --git a/src/chown/chown.rs b/src/chown/chown.rs index d1787b48e..5a913ecfa 100644 --- a/src/chown/chown.rs +++ b/src/chown/chown.rs @@ -136,7 +136,7 @@ pub fn uumain(args: Vec) -> i32 { IfFrom::All }; - if matches.free.len() < 1 { + if matches.free.is_empty() { disp_err!("missing operand"); return 1; } else if matches.free.len() < 2 && !matches.opt_present("reference") { @@ -172,15 +172,15 @@ pub fn uumain(args: Vec) -> i32 { let mut files = matches.free; files.remove(0); let executor = Chowner { - bit_flag: bit_flag, - dest_uid: dest_uid, - dest_gid: dest_gid, - verbosity: verbosity, - recursive: recursive, + bit_flag, + dest_uid, + dest_gid, + verbosity, + recursive, dereference: derefer != 0, - filter: filter, - preserve_root: preserve_root, - files: files, + filter, + preserve_root, + files, }; executor.exec() } diff --git a/src/chroot/chroot.rs b/src/chroot/chroot.rs index ab4072e86..ab0b9a7fd 100644 --- a/src/chroot/chroot.rs +++ b/src/chroot/chroot.rs @@ -140,7 +140,7 @@ fn enter_chroot(root: &Path) { let root_str = root.display(); std::env::set_current_dir(root).unwrap(); let err = unsafe { - chroot(CString::new(".".as_bytes()) + chroot(CString::new(".") .unwrap() .as_bytes_with_nul() .as_ptr() as *const libc::c_char) diff --git a/src/cksum/cksum.rs b/src/cksum/cksum.rs index cfb4ca955..44eb84af2 100644 --- a/src/cksum/cksum.rs +++ b/src/cksum/cksum.rs @@ -20,9 +20,9 @@ use std::path::Path; include!(concat!(env!("OUT_DIR"), "/crc_table.rs")); -static SYNTAX: &'static str = "[OPTIONS] [FILE]..."; -static SUMMARY: &'static str = "Print CRC and size for each file"; -static LONG_HELP: &'static str = ""; +static SYNTAX: &str = "[OPTIONS] [FILE]..."; +static SUMMARY: &str = "Print CRC and size for each file"; +static LONG_HELP: &str = ""; #[inline] fn crc_update(crc: u32, input: u8) -> u32 { diff --git a/src/comm/comm.rs b/src/comm/comm.rs index 139c3d79a..b614f898b 100644 --- a/src/comm/comm.rs +++ b/src/comm/comm.rs @@ -19,9 +19,9 @@ use std::fs::File; use std::io::{self, stdin, BufRead, BufReader, Stdin}; use std::path::Path; -static SYNTAX: &'static str = "[OPTIONS] FILE1 FILE2"; -static SUMMARY: &'static str = "Compare sorted files line by line"; -static LONG_HELP: &'static str = ""; +static SYNTAX: &str = "[OPTIONS] FILE1 FILE2"; +static SUMMARY: &str = "Compare sorted files line by line"; +static LONG_HELP: &str = ""; fn mkdelim(col: usize, opts: &getopts::Matches) -> String { let mut s = String::new(); diff --git a/src/cp/cp.rs b/src/cp/cp.rs index d8147f6ba..de05619c4 100644 --- a/src/cp/cp.rs +++ b/src/cp/cp.rs @@ -676,14 +676,14 @@ impl TargetType { fn parse_path_args(path_args: &[String], options: &Options) -> CopyResult<(Vec, Target)> { let mut paths = path_args.iter().map(PathBuf::from).collect::>(); - if paths.len() < 1 { + if paths.is_empty() { // No files specified return Err("missing file operand".into()); } // Return an error if the user requested to copy more than one // file source to a file target - if options.no_target_dir && !options.target_dir.is_some() && paths.len() > 2 { + if options.no_target_dir && options.target_dir.is_none() && paths.len() > 2 { return Err(format!("extra operand {:?}", paths[2]).into()); } diff --git a/src/cut/buffer.rs b/src/cut/buffer.rs index 77955171a..11f48bccb 100644 --- a/src/cut/buffer.rs +++ b/src/cut/buffer.rs @@ -43,7 +43,7 @@ impl ByteReader { pub fn new(read: R, newline_char: u8) -> ByteReader { ByteReader { inner: BufReader::with_capacity(4096, read), - newline_char: newline_char, + newline_char, } } } @@ -75,7 +75,7 @@ impl ByteReader { // need filled_buf to go out of scope let filled_buf = match self.fill_buf() { Ok(b) => { - if b.len() == 0 { + if b.is_empty() { return bytes_consumed; } else { b @@ -137,9 +137,8 @@ impl self::Bytes::Select for ByteReader { }, }; - match out { - Some(out) => crash_if_err!(1, out.write_all(&buffer[0..consume_val])), - None => (), + if let Some(out) = out { + crash_if_err!(1, out.write_all(&buffer[0..consume_val])); } (res, consume_val) }; diff --git a/src/cut/cut.rs b/src/cut/cut.rs index d1221656d..c6efea47e 100644 --- a/src/cut/cut.rs +++ b/src/cut/cut.rs @@ -23,11 +23,11 @@ mod buffer; mod ranges; mod searcher; -static SYNTAX: &'static str = +static SYNTAX: &str = "[-d] [-s] [-z] [--output-delimiter] ((-f|-b|-c) {{sequence}}) {{sourcefile}}+"; -static SUMMARY: &'static str = +static SUMMARY: &str = "Prints specified byte or field columns from each line of stdin or the input files"; -static LONG_HELP: &'static str = " +static LONG_HELP: &str = " Each call must specify a mode (what to use for columns), a sequence (which columns to print), and provide a data source @@ -169,14 +169,11 @@ fn cut_bytes(reader: R, ranges: &[Range], opts: &Options) -> i32 { } } - match opts.out_delim { - Some(ref delim) => { - if print_delim { - crash_if_err!(1, out.write_all(delim.as_bytes())); - } - print_delim = true; + if let Some(ref delim) = opts.out_delim { + if print_delim { + crash_if_err!(1, out.write_all(delim.as_bytes())); } - None => (), + print_delim = true; } // write out from low to high @@ -293,18 +290,15 @@ fn cut_fields_delimiter( fn cut_fields(reader: R, ranges: &[Range], opts: &FieldOptions) -> i32 { let newline_char = if opts.zero_terminated { b'\0' } else { b'\n' }; - match opts.out_delimeter { - Some(ref o_delim) => { - return cut_fields_delimiter( - reader, - ranges, - &opts.delimiter, - opts.only_delimited, - newline_char, - o_delim, - ) - } - None => (), + if let Some(ref o_delim) = opts.out_delimeter { + return cut_fields_delimiter( + reader, + ranges, + &opts.delimiter, + opts.only_delimited, + newline_char, + o_delim, + ); } let mut buf_in = BufReader::new(reader); @@ -348,10 +342,8 @@ fn cut_fields(reader: R, ranges: &[Range], opts: &FieldOptions) -> i32 }; } - if print_delim { - if low_idx >= opts.delimiter.as_bytes().len() { - low_idx -= opts.delimiter.as_bytes().len(); - } + if print_delim && low_idx >= opts.delimiter.as_bytes().len() { + low_idx -= opts.delimiter.as_bytes().len(); } match delim_search.nth(high - low) { @@ -509,8 +501,8 @@ pub fn uumain(args: Vec) -> i32 { FieldOptions { delimiter: delim, out_delimeter: out_delim, - only_delimited: only_delimited, - zero_terminated: zero_terminated, + only_delimited, + zero_terminated, }, )) } @@ -520,8 +512,8 @@ pub fn uumain(args: Vec) -> i32 { FieldOptions { delimiter: "\t".to_owned(), out_delimeter: out_delim, - only_delimited: only_delimited, - zero_terminated: zero_terminated, + only_delimited, + zero_terminated, }, )), } diff --git a/src/cut/ranges.rs b/src/cut/ranges.rs index ad8735ea9..44edcb943 100644 --- a/src/cut/ranges.rs +++ b/src/cut/ranges.rs @@ -39,11 +39,11 @@ impl FromStr for Range { Err(inval) } } - (Some(n), Some(m)) if m.len() == 0 => { + (Some(n), Some(m)) if m.is_empty() => { if let Ok(low) = n.parse::() { if low > 0 { Ok(Range { - low: low, + low, high: MAX - 1, }) } else { @@ -56,7 +56,7 @@ impl FromStr for Range { (Some(n), Some(m)) if n.len() == 0 => { if let Ok(high) = m.parse::() { if high > 0 { - Ok(Range { low: 1, high: high }) + Ok(Range { low: 1, high }) } else { Err(field) } @@ -68,8 +68,8 @@ impl FromStr for Range { (Ok(low), Ok(high)) => { if low > 0 && low <= high { Ok(Range { - low: low, - high: high, + low, + high, }) } else if low == 0 { Err(field) @@ -118,7 +118,7 @@ pub fn complement(ranges: &[Range]) -> Vec { let mut complements = Vec::with_capacity(ranges.len() + 1); - if ranges.len() > 0 && ranges[0].low > 1 { + if !ranges.is_empty() && ranges[0].low > 1 { complements.push(Range { low: 1, high: ranges[0].low - 1, diff --git a/src/cut/searcher.rs b/src/cut/searcher.rs index e5d761551..2394ca539 100644 --- a/src/cut/searcher.rs +++ b/src/cut/searcher.rs @@ -17,8 +17,8 @@ pub struct Searcher<'a> { impl<'a> Searcher<'a> { pub fn new(haystack: &'a [u8], needle: &'a [u8]) -> Searcher<'a> { Searcher { - haystack: haystack, - needle: needle, + haystack, + needle, position: 0, } } diff --git a/src/date/date.rs b/src/date/date.rs index 9e6bad796..db81f2fd6 100644 --- a/src/date/date.rs +++ b/src/date/date.rs @@ -21,24 +21,24 @@ use std::io::{BufRead, BufReader}; use std::path::PathBuf; // Options -const DATE: &'static str = "date"; -const HOURS: &'static str = "hours"; -const MINUTES: &'static str = "minutes"; -const SECONDS: &'static str = "seconds"; -const NS: &'static str = "ns"; +const DATE: &str = "date"; +const HOURS: &str = "hours"; +const MINUTES: &str = "minutes"; +const SECONDS: &str = "seconds"; +const NS: &str = "ns"; // Help strings -static ISO_8601_HELP_STRING: &'static str = "output date/time in ISO 8601 format. +static ISO_8601_HELP_STRING: &str = "output date/time in ISO 8601 format. FMT='date' for date only (the default), 'hours', 'minutes', 'seconds', or 'ns' for date and time to the indicated precision. Example: 2006-08-14T02:34:56-06:00"; -static RFC_2822_HELP_STRING: &'static str = "output date and time in RFC 2822 format. +static RFC_2822_HELP_STRING: &str = "output date and time in RFC 2822 format. Example: Mon, 14 Aug 2006 02:34:56 -0600"; -static RFC_3339_HELP_STRING: &'static str = "output date/time in RFC 3339 format. +static RFC_3339_HELP_STRING: &str = "output date/time in RFC 3339 format. FMT='date', 'seconds', or 'ns' for date and time to the indicated precision. Example: 2006-08-14 02:34:56-06:00"; @@ -119,15 +119,12 @@ pub fn uumain(args: Vec) -> i32 { let file: File; // Get the current time, either in the local time zone or UTC. - let now: DateTime = match settings.utc { - true => { - let now = Utc::now(); - now.with_timezone(&now.offset().fix()) - } - false => { - let now = Local::now(); - now.with_timezone(now.offset()) - } + let now: DateTime = if settings.utc { + let now = Utc::now(); + now.with_timezone(&now.offset().fix()) + } else { + let now = Local::now(); + now.with_timezone(now.offset()) }; /// Parse a `String` into a `DateTime`. @@ -198,10 +195,11 @@ fn parse_cli(args: Vec) -> Settings { possible_value[date seconds ns] RFC_3339_HELP_STRING) (@arg custom_format: +takes_value { - |s| match s.starts_with("+") { - true => Ok(()), - false => Err(String::from("Date formats must start with a '+' character")) - } + |s| if s.starts_with('+') { + Ok(()) + } else { + Err(String::from("Date formats must start with a '+' character")) + } })) (@arg debug: --debug @@ -245,8 +243,8 @@ fn parse_cli(args: Vec) -> Settings { Settings { utc: matches.is_present("utc"), - format: format, - date_source: date_source, + format, + date_source, // TODO: Handle this option: set_to: None, } @@ -255,18 +253,18 @@ fn parse_cli(args: Vec) -> Settings { /// Return the appropriate format string for the given settings. fn make_format_string(settings: &Settings) -> &str { match settings.format { - Format::Iso8601(ref fmt) => match fmt { - &Iso8601Format::Date => "%F", - &Iso8601Format::Hours => "%FT%H%:z", - &Iso8601Format::Minutes => "%FT%H:%M%:z", - &Iso8601Format::Seconds => "%FT%T%:z", - &Iso8601Format::Ns => "%FT%T,%f%:z", + Format::Iso8601(ref fmt) => match *fmt { + Iso8601Format::Date => "%F", + Iso8601Format::Hours => "%FT%H%:z", + Iso8601Format::Minutes => "%FT%H:%M%:z", + Iso8601Format::Seconds => "%FT%T%:z", + Iso8601Format::Ns => "%FT%T,%f%:z", }, Format::Rfc2822 => "%a, %d %h %Y %T %z", - Format::Rfc3339(ref fmt) => match fmt { - &Rfc3339Format::Date => "%F", - &Rfc3339Format::Seconds => "%F %T%:z", - &Rfc3339Format::Ns => "%F %T.%f%:z", + Format::Rfc3339(ref fmt) => match *fmt { + Rfc3339Format::Date => "%F", + Rfc3339Format::Seconds => "%F %T%:z", + Rfc3339Format::Ns => "%F %T.%f%:z", }, Format::Custom(ref fmt) => fmt, Format::Default => "%c", diff --git a/src/dircolors/colors.rs b/src/dircolors/colors.rs index 8338dd6f3..c19920508 100644 --- a/src/dircolors/colors.rs +++ b/src/dircolors/colors.rs @@ -1,4 +1,4 @@ -pub const INTERNAL_DB: &'static str = +pub const INTERNAL_DB: &str = r#"# Configuration file for dircolors, a utility to help you set the # LS_COLORS environment variable used by GNU ls with the --color option. # Copyright (C) 1996-2016 Free Software Foundation, Inc. diff --git a/src/dircolors/dircolors.rs b/src/dircolors/dircolors.rs index 6bdc6bda3..864438500 100644 --- a/src/dircolors/dircolors.rs +++ b/src/dircolors/dircolors.rs @@ -18,9 +18,9 @@ use std::io::{BufRead, BufReader}; use std::borrow::Borrow; use std::env; -static SYNTAX: &'static str = "[OPTION]... [FILE]"; -static SUMMARY: &'static str = "Output commands to set the LS_COLORS environment variable."; -static LONG_HELP: &'static str = " +static SYNTAX: &str = "[OPTION]... [FILE]"; +static SUMMARY: &str = "Output commands to set the LS_COLORS environment variable."; +static LONG_HELP: &str = " If FILE is specified, read it to determine which colors to use for which file types and extensions. Otherwise, a precompiled database is used. For details on the format of these files, run 'dircolors --print-database' @@ -252,7 +252,7 @@ where table.insert("multihardlink", "mh"); table.insert("clrtoeol", "cl"); - let term = env::var("TERM").unwrap_or("none".to_owned()); + let term = env::var("TERM").unwrap_or_else(|_| "none".to_owned()); let term = term.as_str(); let mut state = ParseState::Global; @@ -286,18 +286,16 @@ where state = ParseState::Continue; } if state != ParseState::Pass { - if key.starts_with(".") { + if key.starts_with('.') { result.push_str(format!("*{}={}:", key, val).as_str()); - } else if key.starts_with("*") { + } else if key.starts_with('*') { result.push_str(format!("{}={}:", key, val).as_str()); } else if lower == "options" || lower == "color" || lower == "eightbit" { - // Slackware only. Ignore + // Slackware only. Ignore + } else if let Some(s) = table.get(lower.as_str()) { + result.push_str(format!("{}={}:", s, val).as_str()); } else { - if let Some(s) = table.get(lower.as_str()) { - result.push_str(format!("{}={}:", s, val).as_str()); - } else { - return Err(format!("{}:{}: unrecognized keyword {}", fp, num, key)); - } + return Err(format!("{}:{}: unrecognized keyword {}", fp, num, key)); } } } diff --git a/src/du/du.rs b/src/du/du.rs index ad2b5df25..269d726e1 100644 --- a/src/du/du.rs +++ b/src/du/du.rs @@ -25,9 +25,9 @@ use std::os::unix::fs::MetadataExt; use std::path::PathBuf; use time::Timespec; -const NAME: &'static str = "du"; -const SUMMARY: &'static str = "estimate file space usage"; -const LONG_HELP: &'static str = " +const NAME: &str = "du"; +const SUMMARY: &str = "estimate file space usage"; +const LONG_HELP: &str = " Display values are in units of the first available SIZE from --block-size, and the DU_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environ‐ ment variables. Otherwise, units default to 1024 bytes (or 512 if @@ -65,7 +65,7 @@ impl Stat { fn new(path: PathBuf) -> Result { let metadata = fs::symlink_metadata(&path)?; Ok(Stat { - path: path, + path, is_dir: metadata.is_dir(), size: metadata.len(), blocks: metadata.blocks() as u64, @@ -110,9 +110,9 @@ fn unit_string_to_number(s: &str) -> Option { } fn translate_to_pure_number(s: &Option) -> Option { - match s { - &Some(ref s) => unit_string_to_number(s), - &None => None, + match *s { + Some(ref s) => unit_string_to_number(s), + None => None, } } @@ -165,7 +165,7 @@ fn du( } }; - for f in read.into_iter() { + for f in read { match f { Ok(entry) => { match Stat::new(entry.path()) { @@ -319,7 +319,7 @@ pub fn uumain(args: Vec) -> i32 { let options = Options { all: matches.opt_present("all"), program_name: NAME.to_owned(), - max_depth: max_depth, + max_depth, total: matches.opt_present("total"), separate_dirs: matches.opt_present("S"), }; @@ -377,13 +377,13 @@ Try '{} --help' for more information.", let line_separator = if matches.opt_present("0") { "\0" } else { "\n" }; let mut grand_total = 0; - for path_str in strs.into_iter() { + for path_str in strs { let path = PathBuf::from(&path_str); match Stat::new(path) { Ok(stat) => { let mut inodes: HashSet = HashSet::new(); - let iter = du(stat, &options, 0, &mut inodes).into_iter(); + let iter = du(stat, &options, 0, &mut inodes); let (_, len) = iter.size_hint(); let len = len.unwrap(); for (index, stat) in iter.enumerate() { @@ -417,11 +417,11 @@ Try '{} --help' for more information.", } None => stat.modified, }; - ((time / 1000) as i64, (time % 1000 * 1000000) as i32) + ((time / 1000) as i64, (time % 1000 * 1_000_000) as i32) }; time::at(Timespec::new(secs, nsecs)) }; - if !summarize || (summarize && index == len - 1) { + if !summarize || index == len - 1 { let time_str = tm.strftime(time_format_str).unwrap(); print!( "{}\t{}\t{}{}", @@ -431,15 +431,13 @@ Try '{} --help' for more information.", line_separator ); } - } else { - if !summarize || (summarize && index == len - 1) { - print!( - "{}\t{}{}", - convert_size(size), - stat.path.display(), - line_separator - ); - } + } else if !summarize || index == len - 1 { + print!( + "{}\t{}{}", + convert_size(size), + stat.path.display(), + line_separator + ); } if options.total && index == (len - 1) { // The last element will be the total size of the the path under diff --git a/src/env/env.rs b/src/env/env.rs index 8b7af61bf..a456c4190 100644 --- a/src/env/env.rs +++ b/src/env/env.rs @@ -147,7 +147,7 @@ pub fn uumain(args: Vec) -> i32 { } } else { // is it a NAME=VALUE like opt ? - let mut sp = opt.splitn(2, "="); + let mut sp = opt.splitn(2, '='); let name = sp.next(); let value = sp.next(); @@ -187,7 +187,7 @@ pub fn uumain(args: Vec) -> i32 { env::set_var(name, val); } - if opts.program.len() >= 1 { + if !opts.program.is_empty() { let prog = opts.program[0].clone(); let args = &opts.program[1..]; match Command::new(prog).args(args).status() { diff --git a/src/expand/expand.rs b/src/expand/expand.rs index 3821f4870..905677f65 100644 --- a/src/expand/expand.rs +++ b/src/expand/expand.rs @@ -92,11 +92,11 @@ impl Options { }; Options { - files: files, - tabstops: tabstops, - tspaces: tspaces, - iflag: iflag, - uflag: uflag, + files, + tabstops, + tspaces, + iflag, + uflag, } } } diff --git a/src/expr/expr.rs b/src/expr/expr.rs index c1fdceb22..f0e124d42 100644 --- a/src/expr/expr.rs +++ b/src/expr/expr.rs @@ -16,8 +16,8 @@ extern crate uucore; mod tokens; mod syntax_tree; -static NAME: &'static str = "expr"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "expr"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { // For expr utility we do not want getopts. @@ -35,13 +35,13 @@ pub fn uumain(args: Vec) -> i32 { } } -fn process_expr(token_strings: &Vec) -> Result { +fn process_expr(token_strings: &[String]) -> Result { let maybe_tokens = tokens::strings_to_tokens(&token_strings); let maybe_ast = syntax_tree::tokens_to_ast(maybe_tokens); evaluate_ast(maybe_ast) } -fn print_expr_ok(expr_result: &String) -> i32 { +fn print_expr_ok(expr_result: &str) -> i32 { println!("{}", expr_result); if expr_result == "0" || expr_result == "" { 1 @@ -50,7 +50,7 @@ fn print_expr_ok(expr_result: &String) -> i32 { } } -fn print_expr_error(expr_error: &String) -> ! { +fn print_expr_error(expr_error: &str) -> ! { crash!(2, "{}", expr_error) } @@ -62,7 +62,7 @@ fn evaluate_ast(maybe_ast: Result, String>) -> Result< } } -fn maybe_handle_help_or_version(args: &Vec) -> bool { +fn maybe_handle_help_or_version(args: &[String]) -> bool { if args.len() == 2 { if args[1] == "--help" { print_help(); diff --git a/src/expr/syntax_tree.rs b/src/expr/syntax_tree.rs index ac11fbcc3..66b467bf6 100644 --- a/src/expr/syntax_tree.rs +++ b/src/expr/syntax_tree.rs @@ -66,17 +66,17 @@ impl ASTNode { } } - fn new_node(token_idx: usize, op_type: &String, operands: OperandsList) -> Box { + fn new_node(token_idx: usize, op_type: &str, operands: OperandsList) -> Box { Box::new(ASTNode::Node { token_idx: token_idx, - op_type: op_type.clone(), + op_type: op_type.into(), operands: operands, }) } - fn new_leaf(token_idx: usize, value: &String) -> Box { + fn new_leaf(token_idx: usize, value: &str) -> Box { Box::new(ASTNode::Leaf { - token_idx: token_idx, - value: value.clone(), + token_idx, + value: value.into(), }) } pub fn evaluate(&self) -> Result { @@ -252,7 +252,7 @@ fn ast_from_rpn(rpn: &mut TokenStack) -> Result, String> { } fn maybe_ast_node( token_idx: usize, - op_type: &String, + op_type: &str, arity: usize, rpn: &mut TokenStack, ) -> Result, String> { @@ -351,7 +351,10 @@ fn push_op_to_stack( match op_stack.last() { None => return Ok(op_stack.push((token_idx, token.clone()))), - Some(&(_, Token::ParOpen)) => return Ok(op_stack.push((token_idx, token.clone()))), + Some(&(_, Token::ParOpen)) => { + op_stack.push((token_idx, token.clone())); + return Ok(()); + } Some(&( _, @@ -362,11 +365,13 @@ fn push_op_to_stack( )) => if la && prev_prec >= prec || !la && prev_prec > prec { out_stack.push(op_stack.pop().unwrap()) } else { - return Ok(op_stack.push((token_idx, token.clone()))); + op_stack.push((token_idx, token.clone())); + return Ok(()); }, Some(&(_, Token::PrefixOp { .. })) => { - return Ok(op_stack.push((token_idx, token.clone()))) + op_stack.push((token_idx, token.clone())); + return Ok(()); } Some(_) => panic!("Non-operator on op_stack"), @@ -397,13 +402,13 @@ fn checked_binop Option, T>(cb: F, op: &str) -> Result } } -fn infix_operator_two_ints(f: F, values: &Vec) -> Result +fn infix_operator_two_ints(f: F, values: &[String]) -> Result where F: Fn(i64, i64) -> Result, { assert!(values.len() == 2); - if let Some(left) = values[0].parse::().ok() { - if let Some(right) = values[1].parse::().ok() { + if let Ok(left) = values[0].parse::() { + if let Ok(right) = values[1].parse::() { return match f(left, right) { Ok(result) => Ok(result.to_string()), Err(reason) => Err(reason), @@ -416,7 +421,7 @@ where fn infix_operator_two_ints_or_two_strings( fi: FI, fs: FS, - values: &Vec, + values: &[String], ) -> Result where FI: Fn(i64, i64) -> Result, @@ -435,7 +440,7 @@ where } } -fn infix_operator_or(values: &Vec) -> Result { +fn infix_operator_or(values: &[String]) -> Result { assert!(values.len() == 2); if value_as_bool(&values[0]) { Ok(values[0].clone()) @@ -444,7 +449,7 @@ fn infix_operator_or(values: &Vec) -> Result { } } -fn infix_operator_and(values: &Vec) -> Result { +fn infix_operator_and(values: &[String]) -> Result { if value_as_bool(&values[0]) && value_as_bool(&values[1]) { Ok(values[0].clone()) } else { @@ -452,7 +457,7 @@ fn infix_operator_and(values: &Vec) -> Result { } } -fn operator_match(values: &Vec) -> Result { +fn operator_match(values: &[String]) -> Result { assert!(values.len() == 2); let re = match Regex::with_options(&values[1], RegexOptions::REGEX_OPTION_NONE, Syntax::grep()) { @@ -472,12 +477,12 @@ fn operator_match(values: &Vec) -> Result { } } -fn prefix_operator_length(values: &Vec) -> Result { +fn prefix_operator_length(values: &[String]) -> Result { assert!(values.len() == 1); Ok(values[0].len().to_string()) } -fn prefix_operator_index(values: &Vec) -> Result { +fn prefix_operator_index(values: &[String]) -> Result { assert!(values.len() == 2); let haystack = &values[0]; let needles = &values[1]; @@ -495,7 +500,7 @@ fn prefix_operator_index(values: &Vec) -> Result { Ok("0".to_string()) } -fn prefix_operator_substr(values: &Vec) -> Result { +fn prefix_operator_substr(values: &[String]) -> Result { assert!(values.len() == 3); let subj = &values[0]; let mut idx = match values[1].parse::() { @@ -541,7 +546,7 @@ fn bool_as_string(b: bool) -> String { } } fn value_as_bool(s: &str) -> bool { - if s.len() == 0 { + if s.is_empty() { return false; } match s.parse::() { diff --git a/src/expr/tokens.rs b/src/expr/tokens.rs index 23bf985df..5684b0bed 100644 --- a/src/expr/tokens.rs +++ b/src/expr/tokens.rs @@ -39,15 +39,15 @@ pub enum Token { }, } impl Token { - fn new_infix_op(v: &String, left_assoc: bool, precedence: u8) -> Self { + fn new_infix_op(v: &str, left_assoc: bool, precedence: u8) -> Self { Token::InfixOp { - left_assoc: left_assoc, - precedence: precedence, - value: v.clone(), + left_assoc, + precedence, + value: v.into(), } } - fn new_value(v: &String) -> Self { - Token::Value { value: v.clone() } + fn new_value(v: &str) -> Self { + Token::Value { value: v.into() } } fn is_infix_plus(&self) -> bool { @@ -148,7 +148,7 @@ fn push_token_if_not_escaped( acc: &mut Vec<(usize, Token)>, tok_idx: usize, token: Token, - s: &String, + s: &str, ) { // Smells heuristics... :( let prev_is_plus = match acc.last() { diff --git a/src/uucore/coreopts.rs b/src/uucore/coreopts.rs index 58518540f..c245cf500 100644 --- a/src/uucore/coreopts.rs +++ b/src/uucore/coreopts.rs @@ -18,7 +18,7 @@ impl<'a> CoreOptions<'a> { pub fn new(help_text: HelpText<'a>) -> Self { let mut ret = CoreOptions { options: getopts::Options::new(), - help_text: help_text, + help_text, }; ret.options .optflag("", "help", "print usage information") diff --git a/src/uucore/encoding.rs b/src/uucore/encoding.rs index 0bc8d5be8..ca0e2eeb7 100644 --- a/src/uucore/encoding.rs +++ b/src/uucore/encoding.rs @@ -66,8 +66,8 @@ impl Data { Data { line_wrap: 76, ignore_garbage: false, - input: input, - format: format, + input, + format, alphabet: match format { Base32 => b"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=", Base64 => b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789=+/", diff --git a/src/uucore/fs.rs b/src/uucore/fs.rs index 78ccfbef3..39a7c4757 100644 --- a/src/uucore/fs.rs +++ b/src/uucore/fs.rs @@ -31,7 +31,7 @@ macro_rules! has { ) } -pub fn resolve_relative_path<'a>(path: &'a Path) -> Cow<'a, Path> { +pub fn resolve_relative_path(path: &Path) -> Cow { if path.components().all(|e| e != Component::ParentDir) { return path.into(); } diff --git a/src/yes/yes.rs b/src/yes/yes.rs index cca6ec912..a153222ba 100644 --- a/src/yes/yes.rs +++ b/src/yes/yes.rs @@ -21,7 +21,7 @@ use std::borrow::Cow; use std::io::{self, Write}; // force a re-build whenever Cargo.toml changes -const _CARGO_TOML: &'static str = include_str!("Cargo.toml"); +const _CARGO_TOML: &str = include_str!("Cargo.toml"); // it's possible that using a smaller or larger buffer might provide better performance on some // systems, but honestly this is good enough From e46e3594d20f2358a7421b8df11b851a47726b03 Mon Sep 17 00:00:00 2001 From: Vinzent Steinberg Date: Tue, 4 Sep 2018 14:33:36 +0200 Subject: [PATCH 2/3] Fix more clippy warnings and remove redundant 'static --- src/arch/arch.rs | 6 +-- src/base32/base32.rs | 6 +-- src/base64/base64.rs | 6 +-- src/basename/basename.rs | 8 ++-- src/cat/cat.rs | 6 +-- src/chgrp/chgrp.rs | 4 +- src/chown/chown.rs | 4 +- src/chroot/chroot.rs | 8 ++-- src/cksum/build.rs | 2 +- src/dirname/dirname.rs | 8 ++-- src/env/env.rs | 8 ++-- src/expand/expand.rs | 6 +-- src/factor/factor.rs | 8 ++-- src/fmt/fmt.rs | 89 +++++++++++++++++----------------------- src/fmt/linebreak.rs | 22 +++++----- src/fmt/parasplit.rs | 42 +++++++++---------- src/fold/fold.rs | 12 +++--- src/groups/groups.rs | 26 ++++++------ src/hashsum/hashsum.rs | 24 +++++------ src/head/head.rs | 19 ++++----- src/hostid/hostid.rs | 8 ++-- src/hostname/hostname.rs | 6 +-- src/install/install.rs | 6 +-- src/join/join.rs | 4 +- src/kill/kill.rs | 6 +-- src/link/link.rs | 6 +-- src/ln/ln.rs | 6 +-- src/logname/logname.rs | 6 +-- src/ls/ls.rs | 8 ++-- src/mkdir/mkdir.rs | 4 +- src/mkfifo/mkfifo.rs | 4 +- src/mknod/mknod.rs | 4 +- src/mktemp/mktemp.rs | 6 +-- src/more/more.rs | 4 +- src/mv/mv.rs | 4 +- src/nice/nice.rs | 4 +- src/nl/nl.rs | 6 +-- src/nohup/nohup.rs | 4 +- src/nproc/nproc.rs | 4 +- src/numfmt/numfmt.rs | 4 +- src/od/od.rs | 4 +- src/od/prn_char.rs | 2 +- src/paste/paste.rs | 4 +- src/pathchk/pathchk.rs | 8 ++-- src/pinky/pinky.rs | 4 +- src/printenv/printenv.rs | 4 +- src/printf/cli.rs | 4 +- src/printf/printf.rs | 10 ++--- src/ptx/ptx.rs | 4 +- src/pwd/pwd.rs | 4 +- src/readlink/readlink.rs | 4 +- src/realpath/realpath.rs | 4 +- src/relpath/relpath.rs | 4 +- src/rm/rm.rs | 4 +- src/rmdir/rmdir.rs | 4 +- src/seq/seq.rs | 4 +- src/shred/shred.rs | 6 +-- src/shuf/shuf.rs | 4 +- src/sleep/sleep.rs | 4 +- src/sort/sort.rs | 8 ++-- src/split/split.rs | 4 +- src/stdbuf/build.rs | 4 +- src/stdbuf/stdbuf.rs | 6 +-- src/sum/sum.rs | 4 +- src/sync/sync.rs | 4 +- src/tac/tac.rs | 4 +- src/tail/tail.rs | 4 +- src/tee/tee.rs | 4 +- src/test/test.rs | 2 +- src/timeout/timeout.rs | 6 +-- src/touch/touch.rs | 4 +- src/tr/tr.rs | 4 +- src/truncate/truncate.rs | 4 +- src/tsort/tsort.rs | 4 +- src/tty/tty.rs | 4 +- src/uname/uname.rs | 32 +++++++-------- src/unexpand/unexpand.rs | 6 +-- src/uniq/uniq.rs | 4 +- src/unlink/unlink.rs | 4 +- src/uptime/uptime.rs | 4 +- src/users/users.rs | 4 +- src/uucore/utmpx.rs | 6 +-- src/uutils/uutils.rs | 4 +- src/wc/wc.rs | 4 +- src/who/who.rs | 6 +-- src/whoami/whoami.rs | 2 +- 86 files changed, 316 insertions(+), 334 deletions(-) diff --git a/src/arch/arch.rs b/src/arch/arch.rs index 17a6e9f53..d27b5d216 100644 --- a/src/arch/arch.rs +++ b/src/arch/arch.rs @@ -15,9 +15,9 @@ extern crate uucore; use platform_info::*; -static SYNTAX: &'static str = ""; -static SUMMARY: &'static str = "Determine architecture name for current machine."; -static LONG_HELP: &'static str = ""; +static SYNTAX: &str = ""; +static SUMMARY: &str = "Determine architecture name for current machine."; +static LONG_HELP: &str = ""; pub fn uumain(args: Vec) -> i32 { new_coreopts!(SYNTAX, SUMMARY, LONG_HELP).parse(args); diff --git a/src/base32/base32.rs b/src/base32/base32.rs index c0dc5e613..e87d982c5 100644 --- a/src/base32/base32.rs +++ b/src/base32/base32.rs @@ -16,10 +16,10 @@ use std::fs::File; use std::io::{stdin, BufReader, Read}; use std::path::Path; -static SYNTAX: &'static str = "[OPTION]... [FILE]"; -static SUMMARY: &'static str = +static SYNTAX: &str = "[OPTION]... [FILE]"; +static SUMMARY: &str = "Base32 encode or decode FILE, or standard input, to standard output."; -static LONG_HELP: &'static str = " +static LONG_HELP: &str = " With no FILE, or when FILE is -, read standard input. The data are encoded as described for the base32 alphabet in RFC diff --git a/src/base64/base64.rs b/src/base64/base64.rs index ac7e350b8..68c517e22 100644 --- a/src/base64/base64.rs +++ b/src/base64/base64.rs @@ -17,10 +17,10 @@ use std::fs::File; use std::io::{stdin, BufReader, Read}; use std::path::Path; -static SYNTAX: &'static str = "[OPTION]... [FILE]"; -static SUMMARY: &'static str = +static SYNTAX: &str = "[OPTION]... [FILE]"; +static SUMMARY: &str = "Base64 encode or decode FILE, or standard input, to standard output."; -static LONG_HELP: &'static str = " +static LONG_HELP: &str = " With no FILE, or when FILE is -, read standard input. The data are encoded as described for the base64 alphabet in RFC diff --git a/src/basename/basename.rs b/src/basename/basename.rs index fa8e03e50..9711efea3 100644 --- a/src/basename/basename.rs +++ b/src/basename/basename.rs @@ -14,11 +14,11 @@ extern crate uucore; use std::path::{is_separator, PathBuf}; -static NAME: &'static str = "basename"; -static SYNTAX: &'static str = "NAME [SUFFIX]"; -static SUMMARY: &'static str = "Print NAME with any leading directory components removed +static NAME: &str = "basename"; +static SYNTAX: &str = "NAME [SUFFIX]"; +static SUMMARY: &str = "Print NAME with any leading directory components removed If specified, also remove a trailing SUFFIX"; -static LONG_HELP: &'static str = ""; +static LONG_HELP: &str = ""; pub fn uumain(args: Vec) -> i32 { // diff --git a/src/cat/cat.rs b/src/cat/cat.rs index 38b5753e1..5885a7c0f 100644 --- a/src/cat/cat.rs +++ b/src/cat/cat.rs @@ -31,10 +31,10 @@ use std::os::unix::fs::FileTypeExt; #[cfg(unix)] use unix_socket::UnixStream; -static SYNTAX: &'static str = "[OPTION]... [FILE]..."; -static SUMMARY: &'static str = "Concatenate FILE(s), or standard input, to standard output +static SYNTAX: &str = "[OPTION]... [FILE]..."; +static SUMMARY: &str = "Concatenate FILE(s), or standard input, to standard output With no FILE, or when FILE is -, read standard input."; -static LONG_HELP: &'static str = ""; +static LONG_HELP: &str = ""; #[derive(PartialEq)] enum NumberingMode { diff --git a/src/chgrp/chgrp.rs b/src/chgrp/chgrp.rs index a5e0aa52b..ed50432d3 100644 --- a/src/chgrp/chgrp.rs +++ b/src/chgrp/chgrp.rs @@ -29,9 +29,9 @@ use std::path::Path; use std::ffi::CString; use std::os::unix::ffi::OsStrExt; -static SYNTAX: &'static str = +static SYNTAX: &str = "chgrp [OPTION]... GROUP FILE...\n or : chgrp [OPTION]... --reference=RFILE FILE..."; -static SUMMARY: &'static str = "Change the group of each FILE to GROUP."; +static SUMMARY: &str = "Change the group of each FILE to GROUP."; const FTS_COMFOLLOW: u8 = 1; const FTS_PHYSICAL: u8 = 1 << 1; diff --git a/src/chown/chown.rs b/src/chown/chown.rs index 5a913ecfa..d594ffa61 100644 --- a/src/chown/chown.rs +++ b/src/chown/chown.rs @@ -30,9 +30,9 @@ use std::convert::AsRef; use std::ffi::CString; use std::os::unix::ffi::OsStrExt; -static SYNTAX: &'static str = +static SYNTAX: &str = "[OPTION]... [OWNER][:[GROUP]] FILE...\n chown [OPTION]... --reference=RFILE FILE..."; -static SUMMARY: &'static str = "change file owner and group"; +static SUMMARY: &str = "change file owner and group"; const FTS_COMFOLLOW: u8 = 1; const FTS_PHYSICAL: u8 = 1 << 1; diff --git a/src/chroot/chroot.rs b/src/chroot/chroot.rs index ab0b9a7fd..a7973e8fe 100644 --- a/src/chroot/chroot.rs +++ b/src/chroot/chroot.rs @@ -23,10 +23,10 @@ use std::iter::FromIterator; use std::path::Path; use std::process::Command; -static NAME: &'static str = "chroot"; -static SYNTAX: &'static str = "[OPTION]... NEWROOT [COMMAND [ARG]...]"; -static SUMMARY: &'static str = "Run COMMAND with root directory set to NEWROOT."; -static LONG_HELP: &'static str = " +static NAME: &str = "chroot"; +static SYNTAX: &str = "[OPTION]... NEWROOT [COMMAND [ARG]...]"; +static SUMMARY: &str = "Run COMMAND with root directory set to NEWROOT."; +static LONG_HELP: &str = " If COMMAND is not specified, it defaults to '$(SHELL) -i'. If $(SHELL) is not set, /bin/sh is used. "; diff --git a/src/cksum/build.rs b/src/cksum/build.rs index 98736424d..37c48db5c 100644 --- a/src/cksum/build.rs +++ b/src/cksum/build.rs @@ -13,7 +13,7 @@ use std::fs::File; use std::io::Write; use std::path::Path; -static CRC_TABLE_LEN: usize = 256; +const CRC_TABLE_LEN: usize = 256; #[path = "../../mkmain.rs"] mod mkmain; diff --git a/src/dirname/dirname.rs b/src/dirname/dirname.rs index e9b773ad0..d56c9e464 100644 --- a/src/dirname/dirname.rs +++ b/src/dirname/dirname.rs @@ -14,10 +14,10 @@ extern crate uucore; use std::path::Path; -static NAME: &'static str = "dirname"; -static SYNTAX: &'static str = "[OPTION] NAME..."; -static SUMMARY: &'static str = "strip last component from file name"; -static LONG_HELP: &'static str = " +static NAME: &str = "dirname"; +static SYNTAX: &str = "[OPTION] NAME..."; +static SUMMARY: &str = "strip last component from file name"; +static LONG_HELP: &str = " Output each NAME with its last non-slash component and trailing slashes removed; if NAME contains no /'s, output '.' (meaning the current directory). diff --git a/src/env/env.rs b/src/env/env.rs index a456c4190..0203e3ba8 100644 --- a/src/env/env.rs +++ b/src/env/env.rs @@ -17,10 +17,10 @@ use std::env; use std::io::{stdout, Write}; use std::process::Command; -static NAME: &'static str = "env"; -static SYNTAX: &'static str = "[OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]"; -static SUMMARY: &'static str = "Set each NAME to VALUE in the environment and run COMMAND"; -static LONG_HELP: &'static str = " +static NAME: &str = "env"; +static SYNTAX: &str = "[OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]"; +static SUMMARY: &str = "Set each NAME to VALUE in the environment and run COMMAND"; +static LONG_HELP: &str = " A mere - implies -i. If no COMMAND, print the resulting environment "; diff --git a/src/expand/expand.rs b/src/expand/expand.rs index 905677f65..6b358e90c 100644 --- a/src/expand/expand.rs +++ b/src/expand/expand.rs @@ -23,10 +23,10 @@ use std::iter::repeat; use std::str::from_utf8; use unicode_width::UnicodeWidthChar; -static SYNTAX: &'static str = "[OPTION]... [FILE]..."; -static SUMMARY: &'static str = "Convert tabs in each FILE to spaces, writing to standard output. +static SYNTAX: &str = "[OPTION]... [FILE]..."; +static SUMMARY: &str = "Convert tabs in each FILE to spaces, writing to standard output. With no FILE, or when FILE is -, read standard input."; -static LONG_HELP: &'static str = ""; +static LONG_HELP: &str = ""; static DEFAULT_TABSTOP: usize = 8; diff --git a/src/factor/factor.rs b/src/factor/factor.rs index 72224377d..e505e077d 100644 --- a/src/factor/factor.rs +++ b/src/factor/factor.rs @@ -29,10 +29,10 @@ mod numeric; include!(concat!(env!("OUT_DIR"), "/prime_table.rs")); -static SYNTAX: &'static str = "[OPTION] [NUMBER]..."; -static SUMMARY: &'static str = "Print the prime factors of the given number(s). +static SYNTAX: &str = "[OPTION] [NUMBER]..."; +static SUMMARY: &str = "Print the prime factors of the given number(s). If none are specified, read from standard input."; -static LONG_HELP: &'static str = ""; +static LONG_HELP: &str = ""; fn rho_pollard_pseudorandom_function(x: u64, a: u64, b: u64, num: u64) -> u64 { if num < 1 << 63 { @@ -148,7 +148,7 @@ fn print_factors(num: u64) { for fac in &factors { print!(" {}", fac); } - println!(""); + println!(); } fn print_factors_str(num_str: &str) { diff --git a/src/fmt/fmt.rs b/src/fmt/fmt.rs index 45e1e885f..816e47ede 100644 --- a/src/fmt/fmt.rs +++ b/src/fmt/fmt.rs @@ -34,9 +34,9 @@ mod linebreak; mod parasplit; // program's NAME and VERSION are used for -V and -h -static SYNTAX: &'static str = "[OPTION]... [FILE]..."; -static SUMMARY: &'static str = "Reformat paragraphs from input files (or stdin) to stdout."; -static LONG_HELP: &'static str = ""; +static SYNTAX: &str = "[OPTION]... [FILE]..."; +static SUMMARY: &str = "Reformat paragraphs from input files (or stdin) to stdout."; +static LONG_HELP: &str = ""; pub type FileOrStdReader = BufReader>; pub struct FmtOptions { @@ -120,62 +120,47 @@ pub fn uumain(args: Vec) -> i32 { fmt_opts.xanti_prefix = true; } - match matches.opt_str("p") { - Some(s) => { - fmt_opts.prefix = s; - fmt_opts.use_prefix = true; - } - None => (), + if let Some(s) = matches.opt_str("p") { + fmt_opts.prefix = s; + fmt_opts.use_prefix = true; }; - match matches.opt_str("P") { - Some(s) => { - fmt_opts.anti_prefix = s; - fmt_opts.use_anti_prefix = true; - } - None => (), + if let Some(s) = matches.opt_str("P") { + fmt_opts.anti_prefix = s; + fmt_opts.use_anti_prefix = true; }; - match matches.opt_str("w") { - Some(s) => { - fmt_opts.width = match s.parse::() { - Ok(t) => t, - Err(e) => { - crash!(1, "Invalid WIDTH specification: `{}': {}", s, e); - } - }; - fmt_opts.goal = cmp::min(fmt_opts.width * 94 / 100, fmt_opts.width - 3); - } - None => (), - }; - - match matches.opt_str("g") { - Some(s) => { - fmt_opts.goal = match s.parse::() { - Ok(t) => t, - Err(e) => { - crash!(1, "Invalid GOAL specification: `{}': {}", s, e); - } - }; - if !matches.opt_present("w") { - fmt_opts.width = cmp::max(fmt_opts.goal * 100 / 94, fmt_opts.goal + 3); - } else if fmt_opts.goal > fmt_opts.width { - crash!(1, "GOAL cannot be greater than WIDTH."); + if let Some(s) = matches.opt_str("w") { + fmt_opts.width = match s.parse::() { + Ok(t) => t, + Err(e) => { + crash!(1, "Invalid WIDTH specification: `{}': {}", s, e); } - } - None => (), + }; + fmt_opts.goal = cmp::min(fmt_opts.width * 94 / 100, fmt_opts.width - 3); }; - match matches.opt_str("T") { - Some(s) => { - fmt_opts.tabwidth = match s.parse::() { - Ok(t) => t, - Err(e) => { - crash!(1, "Invalid TABWIDTH specification: `{}': {}", s, e); - } - }; + if let Some(s) = matches.opt_str("g") { + fmt_opts.goal = match s.parse::() { + Ok(t) => t, + Err(e) => { + crash!(1, "Invalid GOAL specification: `{}': {}", s, e); + } + }; + if !matches.opt_present("w") { + fmt_opts.width = cmp::max(fmt_opts.goal * 100 / 94, fmt_opts.goal + 3); + } else if fmt_opts.goal > fmt_opts.width { + crash!(1, "GOAL cannot be greater than WIDTH."); } - None => (), + }; + + if let Some(s) = matches.opt_str("T") { + fmt_opts.tabwidth = match s.parse::() { + Ok(t) => t, + Err(e) => { + crash!(1, "Invalid TABWIDTH specification: `{}': {}", s, e); + } + }; }; if fmt_opts.tabwidth < 1 { @@ -208,7 +193,7 @@ pub fn uumain(args: Vec) -> i32 { match para_result { Err(s) => { silent_unwrap!(ostream.write_all(s.as_bytes())); - silent_unwrap!(ostream.write_all("\n".as_bytes())); + silent_unwrap!(ostream.write_all(b"\n")); } Ok(para) => break_lines(¶, &fmt_opts, &mut ostream), } diff --git a/src/fmt/linebreak.rs b/src/fmt/linebreak.rs index 1c47c5c64..2bf7b0ef9 100644 --- a/src/fmt/linebreak.rs +++ b/src/fmt/linebreak.rs @@ -53,7 +53,7 @@ pub fn break_lines(para: &Paragraph, opts: &FmtOptions, ostream: &mut BufWriter< let (w, w_len) = match p_words_words.next() { Some(winfo) => (winfo.word, winfo.word_nchars), None => { - silent_unwrap!(ostream.write_all("\n".as_bytes())); + silent_unwrap!(ostream.write_all(b"\n")); return; } }; @@ -77,12 +77,12 @@ pub fn break_lines(para: &Paragraph, opts: &FmtOptions, ostream: &mut BufWriter< let uniform = para.mail_header || opts.uniform; let mut break_args = BreakArgs { - opts: opts, + opts, init_len: p_init_len, indent_str: &p_indent[..], indent_len: p_indent_len, - uniform: uniform, - ostream: ostream, + uniform, + ostream, }; if opts.quick || para.mail_header { @@ -98,7 +98,7 @@ fn break_simple<'a, T: Iterator>>(iter: T, args: &mut Br iter.fold((args.init_len, false), |l, winfo| { accum_words_simple(args, l, winfo) }); - silent_unwrap!(args.ostream.write_all("\n".as_bytes())); + silent_unwrap!(args.ostream.write_all(b"\n")); } fn accum_words_simple<'a>( @@ -199,7 +199,7 @@ fn break_knuth_plass<'a, T: Clone + Iterator>>( fresh = false; write_with_spaces(word, slen, args.ostream); } - silent_unwrap!(args.ostream.write_all("\n".as_bytes())); + silent_unwrap!(args.ostream.write_all(b"\n")); } struct LineBreak<'a> { @@ -381,7 +381,7 @@ fn build_best_path<'a>(paths: &[LineBreak<'a>], active: &[usize]) -> Vec<(&'a Wo } // "infinite" badness is more like (1+BAD_INFTY)^2 because of how demerits are computed -const BAD_INFTY: i64 = 10000000; +const BAD_INFTY: i64 = 10_000_000; const BAD_INFTY_SQ: i64 = BAD_INFTY * BAD_INFTY; // badness = BAD_MULT * abs(r) ^ 3 const BAD_MULT: f32 = 100.0; @@ -451,7 +451,7 @@ fn restart_active_breaks<'a>( LineBreak { prev: act_idx, linebreak: Some(w), - break_before: break_before, + break_before, demerits: 0, // this is the only active break, so we can reset the demerit count prev_rat: if break_before { 1.0 } else { -1.0 }, length: line_length, @@ -492,16 +492,16 @@ fn slice_if_fresh( // Write a newline and add the indent. fn write_newline(indent: &str, ostream: &mut BufWriter) { - silent_unwrap!(ostream.write_all("\n".as_bytes())); + silent_unwrap!(ostream.write_all(b"\n")); silent_unwrap!(ostream.write_all(indent.as_bytes())); } // Write the word, along with slen spaces. fn write_with_spaces(word: &str, slen: usize, ostream: &mut BufWriter) { if slen == 2 { - silent_unwrap!(ostream.write_all(" ".as_bytes())); + silent_unwrap!(ostream.write_all(b" ")); } else if slen == 1 { - silent_unwrap!(ostream.write_all(" ".as_bytes())); + silent_unwrap!(ostream.write_all(b" ")); } silent_unwrap!(ostream.write_all(word.as_bytes())); } diff --git a/src/fmt/parasplit.rs b/src/fmt/parasplit.rs index 208b3bf04..42ceccf81 100644 --- a/src/fmt/parasplit.rs +++ b/src/fmt/parasplit.rs @@ -73,8 +73,8 @@ pub struct FileLines<'a> { impl<'a> FileLines<'a> { fn new<'b>(opts: &'b FmtOptions, lines: Lines<&'b mut FileOrStdReader>) -> FileLines<'b> { FileLines { - opts: opts, - lines: lines, + opts, + lines, } } @@ -197,10 +197,10 @@ impl<'a> Iterator for FileLines<'a> { Some(Line::FormatLine(FileLine { line: n, - indent_end: indent_end, + indent_end, pfxind_end: poffset, - indent_len: indent_len, - prefix_len: prefix_len, + indent_len, + prefix_len, })) } } @@ -234,9 +234,9 @@ impl<'a> ParagraphStream<'a> { let lines = FileLines::new(opts, reader.lines()).peekable(); // at the beginning of the file, we might find mail headers ParagraphStream { - lines: lines, + lines, next_mail: true, - opts: opts, + opts, } } @@ -405,12 +405,12 @@ impl<'a> Iterator for ParagraphStream<'a> { Some(Ok(Paragraph { lines: p_lines, - init_str: init_str, - init_len: init_len, - init_end: init_end, - indent_str: indent_str, - indent_len: indent_len, - indent_end: indent_end, + init_str, + init_len, + init_end, + indent_str, + indent_len, + indent_end, mail_header: in_mail, })) } @@ -425,8 +425,8 @@ pub struct ParaWords<'a> { impl<'a> ParaWords<'a> { pub fn new<'b>(opts: &'b FmtOptions, para: &'b Paragraph) -> ParaWords<'b> { let mut pw = ParaWords { - opts: opts, - para: para, + opts, + para, words: Vec::new(), }; pw.create_words(); @@ -522,7 +522,7 @@ impl<'a> WordSplit<'a> { // wordsplits *must* start at a non-whitespace character let trim_string = string.trim_left(); WordSplit { - opts: opts, + opts, string: trim_string, length: string.len(), position: 0, @@ -610,14 +610,14 @@ impl<'a> Iterator for WordSplit<'a> { }; Some(WordInfo { - word: word, + word, word_start: word_start_relative, - word_nchars: word_nchars, - before_tab: before_tab, - after_tab: after_tab, + word_nchars, + before_tab, + after_tab, sentence_start: is_start_of_sentence, ends_punct: self.prev_punct, - new_line: new_line, + new_line, }) } } diff --git a/src/fold/fold.rs b/src/fold/fold.rs index d2d33fecc..8e083df32 100644 --- a/src/fold/fold.rs +++ b/src/fold/fold.rs @@ -16,10 +16,10 @@ use std::fs::File; use std::io::{stdin, BufRead, BufReader, Read}; use std::path::Path; -static SYNTAX: &'static str = "[OPTION]... [FILE]..."; -static SUMMARY: &'static str = "Writes each file (or standard input if no files are given) +static SYNTAX: &str = "[OPTION]... [FILE]..."; +static SUMMARY: &str = "Writes each file (or standard input if no files are given) to standard output whilst breaking long lines"; -static LONG_HELP: &'static str = ""; +static LONG_HELP: &str = ""; pub fn uumain(args: Vec) -> i32 { let (args, obs_width) = handle_obsolete(&args[..]); @@ -70,7 +70,7 @@ pub fn uumain(args: Vec) -> i32 { fn handle_obsolete(args: &[String]) -> (Vec, Option) { for (i, arg) in args.iter().enumerate() { let slice = &arg; - if slice.chars().next().unwrap() == '-' && slice.len() > 1 + if slice.starts_with('-') && slice.len() > 1 && slice.chars().nth(1).unwrap().is_digit(10) { let mut v = args.to_vec(); @@ -123,10 +123,10 @@ fn fold_file(mut file: BufReader, bytes: bool, spaces: bool, width: } } else { let mut len = line.chars().count(); - let newline = line.ends_with("\n"); + let newline = line.ends_with('\n'); if newline { if len == 1 { - println!(""); + println!(); continue; } len -= 1; diff --git a/src/groups/groups.rs b/src/groups/groups.rs index a667b1a9c..406429eea 100644 --- a/src/groups/groups.rs +++ b/src/groups/groups.rs @@ -14,8 +14,8 @@ extern crate uucore; use uucore::entries::{get_groups, Locate, Passwd, gid2grp}; -static SYNTAX: &'static str = "[user]"; -static SUMMARY: &'static str = "display current group names"; +static SYNTAX: &str = "[user]"; +static SUMMARY: &str = "display current group names"; pub fn uumain(args: Vec) -> i32 { let matches = new_coreopts!(SYNTAX, SUMMARY, "").parse(args); @@ -30,19 +30,17 @@ pub fn uumain(args: Vec) -> i32 { .collect::>() .join(" ") ); + } else if let Ok(p) = Passwd::locate(matches.free[0].as_str()) { + println!( + "{}", + p.belongs_to() + .iter() + .map(|&g| gid2grp(g).unwrap()) + .collect::>() + .join(" ") + ); } else { - if let Ok(p) = Passwd::locate(matches.free[0].as_str()) { - println!( - "{}", - p.belongs_to() - .iter() - .map(|&g| gid2grp(g).unwrap()) - .collect::>() - .join(" ") - ); - } else { - crash!(1, "unknown user {}", matches.free[0]); - } + crash!(1, "unknown user {}", matches.free[0]); } 0 diff --git a/src/hashsum/hashsum.rs b/src/hashsum/hashsum.rs index e71ed4f4e..e0f5ff428 100644 --- a/src/hashsum/hashsum.rs +++ b/src/hashsum/hashsum.rs @@ -38,8 +38,8 @@ use std::fs::File; use std::io::{self, stdin, BufRead, BufReader, Read}; use std::path::Path; -static NAME: &'static str = "hashsum"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "hashsum"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); fn is_custom_binary(program: &str) -> bool { match program { @@ -493,8 +493,8 @@ fn digest_reader<'a, T: Read>( // Digest file, do not hold too much in memory at any given moment let windows = cfg!(windows); - let mut buffer = Vec::with_capacity(524288); - let mut vec = Vec::with_capacity(524288); + let mut buffer = Vec::with_capacity(524_288); + let mut vec = Vec::with_capacity(524_288); let mut looking_for_newline = false; loop { match reader.read_to_end(&mut buffer) { @@ -504,17 +504,17 @@ fn digest_reader<'a, T: Read>( Ok(nread) => { if windows && !binary { // Windows text mode returns '\n' when reading '\r\n' - for i in 0..nread { + for &b in buffer.iter().take(nread) { if looking_for_newline { - if buffer[i] != ('\n' as u8) { - vec.push('\r' as u8); + if b != b'\n' { + vec.push(b'\r'); } - if buffer[i] != ('\r' as u8) { - vec.push(buffer[i]); + if b != b'\r' { + vec.push(b); looking_for_newline = false; } - } else if buffer[i] != ('\r' as u8) { - vec.push(buffer[i]); + } else if b != b'\r' { + vec.push(b); } else { looking_for_newline = true; } @@ -529,7 +529,7 @@ fn digest_reader<'a, T: Read>( } } if windows && looking_for_newline { - vec.push('\r' as u8); + vec.push(b'\r'); digest.input(&vec); } diff --git a/src/head/head.rs b/src/head/head.rs index cd61e1082..efc0ab8db 100644 --- a/src/head/head.rs +++ b/src/head/head.rs @@ -19,9 +19,9 @@ use std::fs::File; use std::path::Path; use std::str::from_utf8; -static SYNTAX: &'static str = ""; -static SUMMARY: &'static str = ""; -static LONG_HELP: &'static str = ""; +static SYNTAX: &str = ""; +static SUMMARY: &str = ""; +static LONG_HELP: &str = ""; enum FilterMode { Bytes(usize), @@ -90,16 +90,15 @@ pub fn uumain(args: Vec) -> i32 { } } } - None => match matches.opt_str("c") { - Some(count) => match count.parse::() { + None => if let Some(count) = matches.opt_str("c") { + match count.parse::() { Ok(m) => settings.mode = FilterMode::Bytes(m), Err(e) => { show_error!("invalid byte count '{}': {}", count, e); return 1; } - }, - None => {} - }, + } + } }; let quiet = matches.opt_present("q"); @@ -129,7 +128,7 @@ pub fn uumain(args: Vec) -> i32 { for file in &files { if settings.verbose { if !firstime { - println!(""); + println!(); } println!("==> {} <==", file); } @@ -160,7 +159,7 @@ fn obsolete(options: &[String]) -> (Vec, Option) { let current = options[a].clone(); let current = current.as_bytes(); - if current.len() > 1 && current[0] == '-' as u8 { + if current.len() > 1 && current[0] == b'-' { let len = current.len(); for pos in 1..len { // Ensure that the argument is only made out of digits diff --git a/src/hostid/hostid.rs b/src/hostid/hostid.rs index a7c056502..1529e99b5 100644 --- a/src/hostid/hostid.rs +++ b/src/hostid/hostid.rs @@ -16,9 +16,9 @@ extern crate uucore; use libc::c_long; -static SYNTAX: &'static str = "[options]"; -static SUMMARY: &'static str = ""; -static LONG_HELP: &'static str = ""; +static SYNTAX: &str = "[options]"; +static SUMMARY: &str = ""; +static LONG_HELP: &str = ""; pub enum Mode { HostId, @@ -49,6 +49,6 @@ fn hostid() { result = gethostid(); } - result &= 0xffffffff; + result &= 0xffff_ffff; println!("{:0>8x}", result); } diff --git a/src/hostname/hostname.rs b/src/hostname/hostname.rs index 80b60a699..7808b6c38 100644 --- a/src/hostname/hostname.rs +++ b/src/hostname/hostname.rs @@ -38,9 +38,9 @@ use libc::gethostname; #[cfg(not(windows))] use libc::sethostname; -const SYNTAX: &'static str = "[OPTION]... [HOSTNAME]"; -const SUMMARY: &'static str = "Print or set the system's host name."; -const LONG_HELP: &'static str = ""; +const SYNTAX: &str = "[OPTION]... [HOSTNAME]"; +const SUMMARY: &str = "Print or set the system's host name."; +const LONG_HELP: &str = ""; pub fn uumain(args: Vec) -> i32 { #[cfg(windows)] diff --git a/src/install/install.rs b/src/install/install.rs index dc7b8d223..4d7aeb611 100644 --- a/src/install/install.rs +++ b/src/install/install.rs @@ -21,10 +21,10 @@ use std::fs; use std::path::{Path, PathBuf}; use std::result::Result; -static NAME: &'static str = "install"; -static SUMMARY: &'static str = "Copy SOURCE to DEST or multiple SOURCE(s) to the existing +static NAME: &str = "install"; +static SUMMARY: &str = "Copy SOURCE to DEST or multiple SOURCE(s) to the existing DIRECTORY, while setting permission modes and owner/group"; -static LONG_HELP: &'static str = ""; +static LONG_HELP: &str = ""; const DEFAULT_MODE: u32 = 755; diff --git a/src/join/join.rs b/src/join/join.rs index f86473259..2f26de014 100644 --- a/src/join/join.rs +++ b/src/join/join.rs @@ -19,8 +19,8 @@ use std::io::{stdin, BufRead, BufReader, Lines, Stdin}; use std::cmp::{min, Ordering}; use clap::{App, Arg}; -static NAME: &'static str = "join"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "join"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); #[derive(Copy, Clone, PartialEq)] enum FileNum { diff --git a/src/kill/kill.rs b/src/kill/kill.rs index 1f9a69829..739efb8df 100644 --- a/src/kill/kill.rs +++ b/src/kill/kill.rs @@ -18,9 +18,9 @@ use libc::{c_int, pid_t}; use std::io::Error; use uucore::signals::ALL_SIGNALS; -static SYNTAX: &'static str = "[options] [...]"; -static SUMMARY: &'static str = ""; -static LONG_HELP: &'static str = ""; +static SYNTAX: &str = "[options] [...]"; +static SUMMARY: &str = ""; +static LONG_HELP: &str = ""; static EXIT_OK: i32 = 0; static EXIT_ERR: i32 = 1; diff --git a/src/link/link.rs b/src/link/link.rs index 9a53f1106..4ff654f4b 100644 --- a/src/link/link.rs +++ b/src/link/link.rs @@ -16,9 +16,9 @@ use std::fs::hard_link; use std::path::Path; use std::io::Error; -static SYNTAX: &'static str = "[OPTIONS] FILE1 FILE2"; -static SUMMARY: &'static str = "Create a link named FILE2 to FILE1"; -static LONG_HELP: &'static str = ""; +static SYNTAX: &str = "[OPTIONS] FILE1 FILE2"; +static SUMMARY: &str = "Create a link named FILE2 to FILE1"; +static LONG_HELP: &str = ""; pub fn normalize_error_message(e: Error) -> String { match e.raw_os_error() { diff --git a/src/ln/ln.rs b/src/ln/ln.rs index 5d0cccb92..d182bd688 100644 --- a/src/ln/ln.rs +++ b/src/ln/ln.rs @@ -20,9 +20,9 @@ use std::os::unix::fs::symlink; use std::os::windows::fs::{symlink_dir, symlink_file}; use std::path::{Path, PathBuf}; -static NAME: &'static str = "ln"; -static SUMMARY: &'static str = ""; -static LONG_HELP: &'static str = " +static NAME: &str = "ln"; +static SUMMARY: &str = ""; +static LONG_HELP: &str = " In the 1st form, create a link to TARGET with the name LINK_NAME. In the 2nd form, create a link to TARGET in the current directory. In the 3rd and 4th forms, create links to each TARGET in DIRECTORY. diff --git a/src/logname/logname.rs b/src/logname/logname.rs index d573f2cee..f0551c021 100644 --- a/src/logname/logname.rs +++ b/src/logname/logname.rs @@ -34,9 +34,9 @@ fn get_userlogin() -> Option { } } -static SYNTAX: &'static str = ""; -static SUMMARY: &'static str = "Print user's login name"; -static LONG_HELP: &'static str = ""; +static SYNTAX: &str = ""; +static SUMMARY: &str = "Print user's login name"; +static LONG_HELP: &str = ""; pub fn uumain(args: Vec) -> i32 { new_coreopts!(SYNTAX, SUMMARY, LONG_HELP).parse(args); diff --git a/src/ls/ls.rs b/src/ls/ls.rs index 7bfaf3461..80f57f448 100644 --- a/src/ls/ls.rs +++ b/src/ls/ls.rs @@ -44,16 +44,16 @@ use unicode_width::UnicodeWidthStr; #[cfg(windows)] use std::os::windows::fs::MetadataExt; -static NAME: &'static str = "ls"; -static SUMMARY: &'static str = ""; -static LONG_HELP: &'static str = " +static NAME: &str = "ls"; +static SUMMARY: &str = ""; +static LONG_HELP: &str = " By default, ls will list the files and contents of any directories on the command line, expect that it will ignore files and directories whose names start with '.' "; #[cfg(unix)] -static DEFAULT_COLORS: &'static str = "rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:"; +static DEFAULT_COLORS: &str = "rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:"; #[cfg(unix)] lazy_static! { diff --git a/src/mkdir/mkdir.rs b/src/mkdir/mkdir.rs index 231ce3b93..9e8581c67 100644 --- a/src/mkdir/mkdir.rs +++ b/src/mkdir/mkdir.rs @@ -18,8 +18,8 @@ extern crate uucore; use std::fs; use std::path::{Path, PathBuf}; -static NAME: &'static str = "mkdir"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "mkdir"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); /** * Handles option parsing diff --git a/src/mkfifo/mkfifo.rs b/src/mkfifo/mkfifo.rs index 3e25e0510..df1012787 100644 --- a/src/mkfifo/mkfifo.rs +++ b/src/mkfifo/mkfifo.rs @@ -19,8 +19,8 @@ use libc::mkfifo; use std::ffi::CString; use std::io::Error; -static NAME: &'static str = "mkfifo"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "mkfifo"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = getopts::Options::new(); diff --git a/src/mknod/mknod.rs b/src/mknod/mknod.rs index c950a7845..0efd7cc92 100644 --- a/src/mknod/mknod.rs +++ b/src/mknod/mknod.rs @@ -23,8 +23,8 @@ use getopts::Options; use std::ffi::CString; -static NAME: &'static str = "mknod"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "mknod"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); const MODE_RW_UGO: mode_t = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; diff --git a/src/mktemp/mktemp.rs b/src/mktemp/mktemp.rs index 2b47fe4c6..97e8a3a90 100644 --- a/src/mktemp/mktemp.rs +++ b/src/mktemp/mktemp.rs @@ -26,9 +26,9 @@ use tempfile::NamedTempFileOptions; mod tempdir; -static NAME: &'static str = "mktemp"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); -static DEFAULT_TEMPLATE: &'static str = "tmp.XXXXXXXXXX"; +static NAME: &str = "mktemp"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); +static DEFAULT_TEMPLATE: &str = "tmp.XXXXXXXXXX"; pub fn uumain(args: Vec) -> i32 { let mut opts = getopts::Options::new(); diff --git a/src/more/more.rs b/src/more/more.rs index 07833928c..3a121fada 100644 --- a/src/more/more.rs +++ b/src/more/more.rs @@ -35,8 +35,8 @@ pub enum Mode { Version, } -static NAME: &'static str = "more"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "more"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = Options::new(); diff --git a/src/mv/mv.rs b/src/mv/mv.rs index dea29e94e..1b1ee68db 100644 --- a/src/mv/mv.rs +++ b/src/mv/mv.rs @@ -19,8 +19,8 @@ use std::env; use std::io::{stdin, BufRead, BufReader, Result}; use std::path::{Path, PathBuf}; -static NAME: &'static str = "mv"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "mv"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub struct Behaviour { overwrite: OverwriteMode, diff --git a/src/nice/nice.rs b/src/nice/nice.rs index 1f79983b7..e76165a8e 100644 --- a/src/nice/nice.rs +++ b/src/nice/nice.rs @@ -19,8 +19,8 @@ use libc::{c_char, c_int, execvp}; use std::ffi::CString; use std::io::Error; -const NAME: &'static str = "nice"; -const VERSION: &'static str = env!("CARGO_PKG_VERSION"); +const NAME: &str = "nice"; +const VERSION: &str = env!("CARGO_PKG_VERSION"); // XXX: PRIO_PROCESS is 0 on at least FreeBSD and Linux. Don't know about Mac OS X. const PRIO_PROCESS: c_int = 0; diff --git a/src/nl/nl.rs b/src/nl/nl.rs index 2fb50179b..6359b4b93 100644 --- a/src/nl/nl.rs +++ b/src/nl/nl.rs @@ -26,9 +26,9 @@ use std::path::Path; mod helper; -static NAME: &'static str = "nl"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); -static USAGE: &'static str = "nl [OPTION]... [FILE]..."; +static NAME: &str = "nl"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); +static USAGE: &str = "nl [OPTION]... [FILE]..."; // A regular expression matching everything. // Settings store options used by nl to produce its output. diff --git a/src/nohup/nohup.rs b/src/nohup/nohup.rs index a54e17869..d9d7de6a3 100644 --- a/src/nohup/nohup.rs +++ b/src/nohup/nohup.rs @@ -25,8 +25,8 @@ use std::path::{Path, PathBuf}; use std::env; use uucore::fs::{is_stderr_interactive, is_stdin_interactive, is_stdout_interactive}; -static NAME: &'static str = "nohup"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "nohup"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); #[cfg(target_os = "macos")] extern "C" { diff --git a/src/nproc/nproc.rs b/src/nproc/nproc.rs index d245836f7..6a35520cd 100644 --- a/src/nproc/nproc.rs +++ b/src/nproc/nproc.rs @@ -29,8 +29,8 @@ pub const _SC_NPROCESSORS_CONF: libc::c_int = 57; #[cfg(target_os = "netbsd")] pub const _SC_NPROCESSORS_CONF: libc::c_int = 1001; -static NAME: &'static str = "nproc"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "nproc"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = getopts::Options::new(); diff --git a/src/numfmt/numfmt.rs b/src/numfmt/numfmt.rs index 600cf462d..9b06bef7f 100644 --- a/src/numfmt/numfmt.rs +++ b/src/numfmt/numfmt.rs @@ -15,8 +15,8 @@ use getopts::{Matches, Options}; use std::io::BufRead; use std::fmt; -static NAME: &'static str = "numfmt"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "numfmt"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); type Result = std::result::Result; diff --git a/src/od/od.rs b/src/od/od.rs index 2c937e63f..03fd0d55a 100644 --- a/src/od/od.rs +++ b/src/od/od.rs @@ -47,10 +47,10 @@ use inputoffset::{InputOffset, Radix}; use inputdecoder::{InputDecoder, MemoryDecoder}; use output_info::OutputInfo; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static VERSION: &str = env!("CARGO_PKG_VERSION"); const PEEK_BUFFER_SIZE: usize = 4; // utf-8 can be 4 bytes -static USAGE: &'static str = r#"Usage: +static USAGE: &str = r#"Usage: od [OPTION]... [--] [FILENAME]... od [-abcdDefFhHiIlLoOsxX] [FILENAME] [[+][0x]OFFSET[.][b]] od --traditional [OPTION]... [FILENAME] [[+][0x]OFFSET[.][b] [[+][0x]LABEL[.][b]]] diff --git a/src/od/prn_char.rs b/src/od/prn_char.rs index 1b01956ee..4caf068fa 100644 --- a/src/od/prn_char.rs +++ b/src/od/prn_char.rs @@ -13,7 +13,7 @@ pub static FORMAT_ITEM_C: FormatterItemInfo = FormatterItemInfo { formatter: FormatWriter::MultibyteWriter(format_item_c), }; -static A_CHRS: [&'static str; 128] = [ +static A_CHRS: [&str; 128] = [ "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel", "bs", "ht", "nl", "vt", "ff", "cr", "so", "si", "dle", "dc1", "dc2", "dc3", "dc4", "nak", "syn", "etb", "can", "em", "sub", "esc", "fs", "gs", "rs", "us", "sp", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", diff --git a/src/paste/paste.rs b/src/paste/paste.rs index 73c9aa74f..0b5c13635 100644 --- a/src/paste/paste.rs +++ b/src/paste/paste.rs @@ -19,8 +19,8 @@ use std::iter::repeat; use std::fs::File; use std::path::Path; -static NAME: &'static str = "paste"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "paste"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = getopts::Options::new(); diff --git a/src/pathchk/pathchk.rs b/src/pathchk/pathchk.rs index dcc21b896..8159c24c9 100644 --- a/src/pathchk/pathchk.rs +++ b/src/pathchk/pathchk.rs @@ -30,12 +30,12 @@ enum Mode { Version, // show version information } -static NAME: &'static str = "pathchk"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "pathchk"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); // a few global constants as used in the GNU implementation -static POSIX_PATH_MAX: usize = 256; -static POSIX_NAME_MAX: usize = 14; +const POSIX_PATH_MAX: usize = 256; +const POSIX_NAME_MAX: usize = 14; pub fn uumain(args: Vec) -> i32 { // add options diff --git a/src/pinky/pinky.rs b/src/pinky/pinky.rs index e36d05f63..697dd158a 100644 --- a/src/pinky/pinky.rs +++ b/src/pinky/pinky.rs @@ -24,8 +24,8 @@ use std::os::unix::fs::MetadataExt; use std::path::PathBuf; -static SYNTAX: &'static str = "[OPTION]... [USER]..."; -static SUMMARY: &'static str = "A lightweight 'finger' program; print user information."; +static SYNTAX: &str = "[OPTION]... [USER]..."; +static SUMMARY: &str = "A lightweight 'finger' program; print user information."; const BUFSIZE: usize = 1024; diff --git a/src/printenv/printenv.rs b/src/printenv/printenv.rs index 72e0c2056..56ca0a653 100644 --- a/src/printenv/printenv.rs +++ b/src/printenv/printenv.rs @@ -18,8 +18,8 @@ extern crate uucore; use std::env; -static NAME: &'static str = "printenv"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "printenv"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = getopts::Options::new(); diff --git a/src/printf/cli.rs b/src/printf/cli.rs index a7a47c1d9..e69cdf3c9 100644 --- a/src/printf/cli.rs +++ b/src/printf/cli.rs @@ -4,8 +4,8 @@ use std::io::{stderr, stdout, Write}; use std::env; -pub static EXIT_OK: i32 = 0; -pub static EXIT_ERR: i32 = 1; +pub const EXIT_OK: i32 = 0; +pub const EXIT_ERR: i32 = 1; pub fn err_msg(msg: &str) { let exe_path = match env::current_exe() { diff --git a/src/printf/printf.rs b/src/printf/printf.rs index 086bc6a88..1842f8831 100644 --- a/src/printf/printf.rs +++ b/src/printf/printf.rs @@ -8,10 +8,10 @@ mod cli; mod memo; mod tokenize; -static NAME: &'static str = "printf"; -static VERSION: &'static str = "0.0.1"; -static SHORT_USAGE: &'static str = "printf: usage: printf [-v var] format [arguments]"; -static LONGHELP_LEAD: &'static str = "printf +static NAME: &str = "printf"; +static VERSION: &str = "0.0.1"; +static SHORT_USAGE: &str = "printf: usage: printf [-v var] format [arguments]"; +static LONGHELP_LEAD: &str = "printf USAGE: printf FORMATSTRING [ARGUMENT]... @@ -26,7 +26,7 @@ Options: --version output version information and exit "; -static LONGHELP_BODY: &'static str = " +static LONGHELP_BODY: &str = " Prints the , replacing escaped character sequences with character literals and substitution field sequences with passed arguments diff --git a/src/ptx/ptx.rs b/src/ptx/ptx.rs index b918b30f7..7ae696bc9 100644 --- a/src/ptx/ptx.rs +++ b/src/ptx/ptx.rs @@ -26,8 +26,8 @@ use std::default::Default; use std::fs::File; use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write}; -static NAME: &'static str = "ptx"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "ptx"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); #[derive(Debug)] enum OutFormat { diff --git a/src/pwd/pwd.rs b/src/pwd/pwd.rs index 191dff488..e4658989d 100644 --- a/src/pwd/pwd.rs +++ b/src/pwd/pwd.rs @@ -18,8 +18,8 @@ use std::env; use std::path::{Path, PathBuf}; use std::io; -static NAME: &'static str = "pwd"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "pwd"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn absolute_path(path: &Path) -> io::Result { let path_buf = path.canonicalize()?; diff --git a/src/readlink/readlink.rs b/src/readlink/readlink.rs index f3fab0ead..b4971e27f 100644 --- a/src/readlink/readlink.rs +++ b/src/readlink/readlink.rs @@ -19,8 +19,8 @@ use std::io::{stdout, Write}; use std::path::PathBuf; use uucore::fs::{canonicalize, CanonicalizeMode}; -const NAME: &'static str = "readlink"; -const VERSION: &'static str = env!("CARGO_PKG_VERSION"); +const NAME: &str = "readlink"; +const VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = getopts::Options::new(); diff --git a/src/realpath/realpath.rs b/src/realpath/realpath.rs index 258d7caf2..80e6052da 100644 --- a/src/realpath/realpath.rs +++ b/src/realpath/realpath.rs @@ -18,8 +18,8 @@ use std::fs; use std::path::{Path, PathBuf}; use uucore::fs::{canonicalize, CanonicalizeMode}; -static NAME: &'static str = "realpath"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "realpath"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = getopts::Options::new(); diff --git a/src/relpath/relpath.rs b/src/relpath/relpath.rs index 0138f1c0d..8e0bb4012 100644 --- a/src/relpath/relpath.rs +++ b/src/relpath/relpath.rs @@ -18,8 +18,8 @@ use std::env; use std::path::{Path, PathBuf}; use uucore::fs::{canonicalize, CanonicalizeMode}; -static NAME: &'static str = "relpath"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "relpath"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = getopts::Options::new(); diff --git a/src/rm/rm.rs b/src/rm/rm.rs index 3664b75f9..27fb6cc3a 100644 --- a/src/rm/rm.rs +++ b/src/rm/rm.rs @@ -42,8 +42,8 @@ struct Options { verbose: bool, } -static NAME: &'static str = "rm"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "rm"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { // TODO: make getopts support -R in addition to -r diff --git a/src/rmdir/rmdir.rs b/src/rmdir/rmdir.rs index 21e514e1b..2ef50e5bd 100644 --- a/src/rmdir/rmdir.rs +++ b/src/rmdir/rmdir.rs @@ -17,8 +17,8 @@ extern crate uucore; use std::fs; use std::path::Path; -static NAME: &'static str = "rmdir"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "rmdir"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = getopts::Options::new(); diff --git a/src/seq/seq.rs b/src/seq/seq.rs index 48dec3796..4bdbbf370 100644 --- a/src/seq/seq.rs +++ b/src/seq/seq.rs @@ -11,8 +11,8 @@ extern crate uucore; use std::cmp; use std::io::{stdout, Write}; -static NAME: &'static str = "seq"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "seq"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); #[derive(Clone)] struct SeqOptions { diff --git a/src/shred/shred.rs b/src/shred/shred.rs index 548d6ac87..ec4f99ff9 100644 --- a/src/shred/shred.rs +++ b/src/shred/shred.rs @@ -25,10 +25,10 @@ use std::path::{Path, PathBuf}; #[macro_use] extern crate uucore; -static NAME: &'static str = "shred"; -static VERSION_STR: &'static str = "1.0.0"; +static NAME: &str = "shred"; +static VERSION_STR: &str = "1.0.0"; const BLOCK_SIZE: usize = 512; -const NAMESET: &'static str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_."; +const NAMESET: &str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_."; // Patterns as shown in the GNU coreutils shred implementation const PATTERNS: [&'static [u8]; 22] = [ diff --git a/src/shuf/shuf.rs b/src/shuf/shuf.rs index 1ac2745ee..0d057f892 100644 --- a/src/shuf/shuf.rs +++ b/src/shuf/shuf.rs @@ -26,8 +26,8 @@ enum Mode { InputRange((usize, usize)), } -static NAME: &'static str = "shuf"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "shuf"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = getopts::Options::new(); diff --git a/src/sleep/sleep.rs b/src/sleep/sleep.rs index cda34e6b5..f27c42be5 100644 --- a/src/sleep/sleep.rs +++ b/src/sleep/sleep.rs @@ -17,8 +17,8 @@ extern crate uucore; use std::thread; use std::time::Duration; -static NAME: &'static str = "sleep"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "sleep"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = getopts::Options::new(); diff --git a/src/sort/sort.rs b/src/sort/sort.rs index 9c25af938..7185f1ba1 100644 --- a/src/sort/sort.rs +++ b/src/sort/sort.rs @@ -26,11 +26,11 @@ use uucore::fs::is_stdin_interactive; use semver::Version; use itertools::Itertools; // for Iterator::dedup() -static NAME: &'static str = "sort"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "sort"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); -static DECIMAL_PT: char = '.'; -static THOUSANDS_SEP: char = ','; +const DECIMAL_PT: char = '.'; +const THOUSANDS_SEP: char = ','; enum SortMode { Numeric, diff --git a/src/split/split.rs b/src/split/split.rs index 5025de6e9..e32467bb2 100644 --- a/src/split/split.rs +++ b/src/split/split.rs @@ -19,8 +19,8 @@ use std::fs::{File, OpenOptions}; use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write}; use std::path::Path; -static NAME: &'static str = "split"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "split"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = getopts::Options::new(); diff --git a/src/stdbuf/build.rs b/src/stdbuf/build.rs index c13d8bffc..cea536e4b 100644 --- a/src/stdbuf/build.rs +++ b/src/stdbuf/build.rs @@ -7,12 +7,12 @@ mod mkmain; #[cfg(target_os = "linux")] mod platform { - pub const DYLIB_EXT: &'static str = ".so"; + pub const DYLIB_EXT: &str = ".so"; } #[cfg(target_os = "macos")] mod platform { - pub const DYLIB_EXT: &'static str = ".dylib"; + pub const DYLIB_EXT: &str = ".dylib"; } fn main() { diff --git a/src/stdbuf/stdbuf.rs b/src/stdbuf/stdbuf.rs index 77629522b..480f96908 100644 --- a/src/stdbuf/stdbuf.rs +++ b/src/stdbuf/stdbuf.rs @@ -23,10 +23,10 @@ use std::os::unix::process::ExitStatusExt; use std::path::PathBuf; use std::process::Command; -static NAME: &'static str = "stdbuf"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "stdbuf"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); -const STDBUF_INJECT: &'static [u8] = include_bytes!(concat!(env!("OUT_DIR"), "/libstdbuf.so")); +const STDBUF_INJECT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/libstdbuf.so")); enum BufferType { Default, diff --git a/src/sum/sum.rs b/src/sum/sum.rs index 445bf48d6..3e1fa5921 100644 --- a/src/sum/sum.rs +++ b/src/sum/sum.rs @@ -18,8 +18,8 @@ use std::fs::File; use std::io::{stdin, Read, Result}; use std::path::Path; -static NAME: &'static str = "sum"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "sum"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); fn bsd_sum(mut reader: Box) -> (usize, u16) { let mut buf = [0; 1024]; diff --git a/src/sync/sync.rs b/src/sync/sync.rs index e1bbb2401..c9608e519 100644 --- a/src/sync/sync.rs +++ b/src/sync/sync.rs @@ -21,8 +21,8 @@ extern crate uucore; #[cfg(not(windows))] extern crate uucore; -static NAME: &'static str = "sync"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "sync"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); #[cfg(unix)] mod platform { diff --git a/src/tac/tac.rs b/src/tac/tac.rs index 6da33a82c..bc14d926b 100644 --- a/src/tac/tac.rs +++ b/src/tac/tac.rs @@ -17,8 +17,8 @@ extern crate uucore; use std::fs::File; use std::io::{stdin, stdout, BufReader, Read, Stdout, Write}; -static NAME: &'static str = "tac"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "tac"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = getopts::Options::new(); diff --git a/src/tail/tail.rs b/src/tail/tail.rs index e26d94133..c6bbbfdf2 100755 --- a/src/tail/tail.rs +++ b/src/tail/tail.rs @@ -29,8 +29,8 @@ use std::str::from_utf8; use std::thread::sleep; use std::time::Duration; -static NAME: &'static str = "tail"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "tail"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); enum FilterMode { Bytes(u64), diff --git a/src/tee/tee.rs b/src/tee/tee.rs index 3198334c1..4285df568 100644 --- a/src/tee/tee.rs +++ b/src/tee/tee.rs @@ -17,8 +17,8 @@ use std::fs::OpenOptions; use std::io::{copy, sink, stdin, stdout, Error, ErrorKind, Read, Result, Write}; use std::path::{Path, PathBuf}; -static NAME: &'static str = "tee"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "tee"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { match options(&args).and_then(exec) { diff --git a/src/test/test.rs b/src/test/test.rs index 690fbcceb..907b44888 100644 --- a/src/test/test.rs +++ b/src/test/test.rs @@ -18,7 +18,7 @@ use std::ffi::OsString; use std::env::args_os; use std::str::from_utf8; -static NAME: &'static str = "test"; +static NAME: &str = "test"; // TODO: decide how to handle non-UTF8 input for all the utils // Definitely don't use [u8], try keeping it as OsStr or OsString instead diff --git a/src/timeout/timeout.rs b/src/timeout/timeout.rs index 1058c0f39..cd8965955 100644 --- a/src/timeout/timeout.rs +++ b/src/timeout/timeout.rs @@ -21,10 +21,10 @@ use std::process::{Command, Stdio}; use std::time::Duration; use uucore::process::ChildExt; -static NAME: &'static str = "timeout"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "timeout"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); -static ERR_EXIT_STATUS: i32 = 125; +const ERR_EXIT_STATUS: i32 = 125; pub fn uumain(args: Vec) -> i32 { let program = args[0].clone(); diff --git a/src/touch/touch.rs b/src/touch/touch.rs index 5db4deb11..194a9b0be 100644 --- a/src/touch/touch.rs +++ b/src/touch/touch.rs @@ -21,8 +21,8 @@ use std::fs::{self, File}; use std::io::{self, Error}; use std::path::Path; -static NAME: &'static str = "touch"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "touch"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); // Since touch's date/timestamp parsing doesn't account for timezone, the // returned value from time::strptime() is UTC. We get system's timezone to diff --git a/src/tr/tr.rs b/src/tr/tr.rs index 86f181ee2..1fe08d454 100644 --- a/src/tr/tr.rs +++ b/src/tr/tr.rs @@ -28,8 +28,8 @@ use expand::ExpandSet; mod expand; -static NAME: &'static str = "tr"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "tr"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); const BUFFER_LEN: usize = 1024; trait SymbolTranslator { diff --git a/src/truncate/truncate.rs b/src/truncate/truncate.rs index ef1168daf..47da3149e 100644 --- a/src/truncate/truncate.rs +++ b/src/truncate/truncate.rs @@ -31,8 +31,8 @@ enum TruncateMode { RoundUp, } -static NAME: &'static str = "truncate"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "truncate"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = getopts::Options::new(); diff --git a/src/tsort/tsort.rs b/src/tsort/tsort.rs index a81104c5d..08c52cabe 100644 --- a/src/tsort/tsort.rs +++ b/src/tsort/tsort.rs @@ -20,8 +20,8 @@ use std::fs::File; use std::io::{stdin, BufRead, BufReader, Read}; use std::path::Path; -static NAME: &'static str = "tsort"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "tsort"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = getopts::Options::new(); diff --git a/src/tty/tty.rs b/src/tty/tty.rs index 173d0f0ff..eaff78c96 100644 --- a/src/tty/tty.rs +++ b/src/tty/tty.rs @@ -24,8 +24,8 @@ extern "C" { fn ttyname(filedesc: libc::c_int) -> *const libc::c_char; } -static NAME: &'static str = "tty"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "tty"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = getopts::Options::new(); diff --git a/src/uname/uname.rs b/src/uname/uname.rs index 307473454..05fce6366 100644 --- a/src/uname/uname.rs +++ b/src/uname/uname.rs @@ -19,35 +19,35 @@ extern crate uucore; use clap::{App, Arg}; use platform_info::*; -const VERSION: &'static str = env!("CARGO_PKG_VERSION"); -const ABOUT: &'static str = "Print certain system information. With no OPTION, same as -s."; +const VERSION: &str = env!("CARGO_PKG_VERSION"); +const ABOUT: &str = "Print certain system information. With no OPTION, same as -s."; -const OPT_ALL: &'static str = "all"; -const OPT_KERNELNAME: &'static str = "kernel-name"; -const OPT_NODENAME: &'static str = "nodename"; -const OPT_KERNELVERSION: &'static str = "kernel-version"; -const OPT_KERNELRELEASE: &'static str = "kernel-release"; -const OPT_MACHINE: &'static str = "machine"; +const OPT_ALL: &str = "all"; +const OPT_KERNELNAME: &str = "kernel-name"; +const OPT_NODENAME: &str = "nodename"; +const OPT_KERNELVERSION: &str = "kernel-version"; +const OPT_KERNELRELEASE: &str = "kernel-release"; +const OPT_MACHINE: &str = "machine"; //FIXME: unimplemented options //const OPT_PROCESSOR: &'static str = "processor"; //const OPT_HWPLATFORM: &'static str = "hardware-platform"; -const OPT_OS: &'static str = "operating-system"; +const OPT_OS: &str = "operating-system"; #[cfg(target_os = "linux")] -const HOST_OS: &'static str = "GNU/Linux"; +const HOST_OS: &str = "GNU/Linux"; #[cfg(target_os = "windows")] -const HOST_OS: &'static str = "Windows NT"; +const HOST_OS: &str = "Windows NT"; #[cfg(target_os = "freebsd")] -const HOST_OS: &'static str = "FreeBSD"; +const HOST_OS: &str = "FreeBSD"; #[cfg(target_os = "openbsd")] -const HOST_OS: &'static str = "OpenBSD"; +const HOST_OS: &str = "OpenBSD"; #[cfg(target_os = "macos")] -const HOST_OS: &'static str = "Darwin"; +const HOST_OS: &str = "Darwin"; #[cfg(target_os = "fuchsia")] -const HOST_OS: &'static str = "Fuchsia"; +const HOST_OS: &str = "Fuchsia"; #[cfg(target_os = "redox")] -const HOST_OS: &'static str = "Redox"; +const HOST_OS: &str = "Redox"; pub fn uumain(args: Vec) -> i32 { let usage = format!("{} [OPTION]...", executable!()); diff --git a/src/unexpand/unexpand.rs b/src/unexpand/unexpand.rs index e06caedc7..30b7343ec 100644 --- a/src/unexpand/unexpand.rs +++ b/src/unexpand/unexpand.rs @@ -22,10 +22,10 @@ use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Stdout, Write} use std::str::from_utf8; use unicode_width::UnicodeWidthChar; -static NAME: &'static str = "unexpand"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "unexpand"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); -static DEFAULT_TABSTOP: usize = 8; +const DEFAULT_TABSTOP: usize = 8; fn tabstops_parse(s: String) -> Vec { let words = s.split(',').collect::>(); diff --git a/src/uniq/uniq.rs b/src/uniq/uniq.rs index fb6918449..f82704b8b 100644 --- a/src/uniq/uniq.rs +++ b/src/uniq/uniq.rs @@ -21,8 +21,8 @@ use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write}; use std::path::Path; use std::str::FromStr; -static NAME: &'static str = "uniq"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "uniq"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); #[derive(PartialEq)] enum Delimiters { diff --git a/src/unlink/unlink.rs b/src/unlink/unlink.rs index adbc9e60d..9bca5e585 100644 --- a/src/unlink/unlink.rs +++ b/src/unlink/unlink.rs @@ -24,8 +24,8 @@ use std::io::{Error, ErrorKind}; use std::mem::uninitialized; use std::ffi::CString; -static NAME: &'static str = "unlink"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "unlink"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = Options::new(); diff --git a/src/uptime/uptime.rs b/src/uptime/uptime.rs index 4c5269001..8d9d48ab4 100644 --- a/src/uptime/uptime.rs +++ b/src/uptime/uptime.rs @@ -23,8 +23,8 @@ pub use uucore::libc; use getopts::Options; -static NAME: &'static str = "uptime"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "uptime"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); #[cfg(unix)] use libc::getloadavg; diff --git a/src/users/users.rs b/src/users/users.rs index e6c6323ad..10fb5eca5 100644 --- a/src/users/users.rs +++ b/src/users/users.rs @@ -21,8 +21,8 @@ use uucore::utmpx::*; use getopts::Options; -static NAME: &'static str = "users"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "users"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = Options::new(); diff --git a/src/uucore/utmpx.rs b/src/uucore/utmpx.rs index db0605a4e..2cb460fc3 100644 --- a/src/uucore/utmpx.rs +++ b/src/uucore/utmpx.rs @@ -64,7 +64,7 @@ macro_rules! chars2string { #[cfg(target_os = "linux")] mod ut { - pub static DEFAULT_FILE: &'static str = "/var/run/utmp"; + pub static DEFAULT_FILE: &str = "/var/run/utmp"; pub use libc::__UT_LINESIZE as UT_LINESIZE; pub use libc::__UT_NAMESIZE as UT_NAMESIZE; @@ -85,7 +85,7 @@ mod ut { #[cfg(target_os = "macos")] mod ut { - pub static DEFAULT_FILE: &'static str = "/var/run/utmpx"; + pub static DEFAULT_FILE: &str = "/var/run/utmpx"; pub use libc::_UTX_LINESIZE as UT_LINESIZE; pub use libc::_UTX_USERSIZE as UT_NAMESIZE; @@ -110,7 +110,7 @@ mod ut { mod ut { use super::libc; - pub static DEFAULT_FILE: &'static str = ""; + pub static DEFAULT_FILE: &str = ""; pub const UT_LINESIZE: usize = 16; pub const UT_NAMESIZE: usize = 32; diff --git a/src/uutils/uutils.rs b/src/uutils/uutils.rs index 59a2d7a40..e1480893a 100644 --- a/src/uutils/uutils.rs +++ b/src/uutils/uutils.rs @@ -18,8 +18,8 @@ use std::io::Write; extern crate uucore; -static NAME: &'static str = "uutils"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "uutils"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); include!(concat!(env!("OUT_DIR"), "/uutils_map.rs")); diff --git a/src/wc/wc.rs b/src/wc/wc.rs index c7a3857f5..7bc6d5d7f 100644 --- a/src/wc/wc.rs +++ b/src/wc/wc.rs @@ -67,8 +67,8 @@ struct Result { max_line_length: usize, } -static NAME: &'static str = "wc"; -static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +static NAME: &str = "wc"; +static VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn uumain(args: Vec) -> i32 { let mut opts = Options::new(); diff --git a/src/who/who.rs b/src/who/who.rs index ea32749f9..83780edbd 100644 --- a/src/who/who.rs +++ b/src/who/who.rs @@ -19,9 +19,9 @@ use std::ffi::CStr; use std::path::PathBuf; use std::os::unix::fs::MetadataExt; -static SYNTAX: &'static str = "[OPTION]... [ FILE | ARG1 ARG2 ]"; -static SUMMARY: &'static str = "Print information about users who are currently logged in."; -static LONG_HELP: &'static str = " +static SYNTAX: &str = "[OPTION]... [ FILE | ARG1 ARG2 ]"; +static SUMMARY: &str = "Print information about users who are currently logged in."; +static LONG_HELP: &str = " -a, --all same as -b -d --login -p -r -t -T -u -b, --boot time of last system boot -d, --dead print dead processes diff --git a/src/whoami/whoami.rs b/src/whoami/whoami.rs index 097812706..886126cbf 100644 --- a/src/whoami/whoami.rs +++ b/src/whoami/whoami.rs @@ -19,7 +19,7 @@ extern crate uucore; mod platform; // force a re-build whenever Cargo.toml changes -const _CARGO_TOML: &'static str = include_str!("Cargo.toml"); +const _CARGO_TOML: &str = include_str!("Cargo.toml"); pub fn uumain(args: Vec) -> i32 { let app = app_from_crate!(); From bc78bcac7df06a44fa923f691f4350aa11470ec8 Mon Sep 17 00:00:00 2001 From: Vinzent Steinberg Date: Tue, 4 Sep 2018 14:49:27 +0200 Subject: [PATCH 3/3] Remove utf8 feature All code it provides can be implemented with `std`. --- src/expand/expand.rs | 2 +- src/unexpand/Cargo.toml | 1 - src/unexpand/unexpand.rs | 2 +- src/uucore/lib.rs | 2 -- src/uucore/utf8.rs | 27 --------------------------- 5 files changed, 2 insertions(+), 32 deletions(-) delete mode 100644 src/uucore/utf8.rs diff --git a/src/expand/expand.rs b/src/expand/expand.rs index 6b358e90c..7430aa1ea 100644 --- a/src/expand/expand.rs +++ b/src/expand/expand.rs @@ -179,7 +179,7 @@ fn expand(options: Options) { while byte < buf.len() { let (ctype, cwidth, nbytes) = if options.uflag { - let nbytes = uucore::utf8::utf8_char_width(buf[byte]); + let nbytes = char::from(buf[byte]).len_utf8(); if byte + nbytes > buf.len() { // don't overrun buffer because of invalid UTF-8 diff --git a/src/unexpand/Cargo.toml b/src/unexpand/Cargo.toml index b917a95de..cecad138a 100644 --- a/src/unexpand/Cargo.toml +++ b/src/unexpand/Cargo.toml @@ -14,7 +14,6 @@ unicode-width = "0.1.5" [dependencies.uucore] path = "../uucore" -features = ["utf8"] [[bin]] name = "unexpand" diff --git a/src/unexpand/unexpand.rs b/src/unexpand/unexpand.rs index 30b7343ec..5df0dfda0 100644 --- a/src/unexpand/unexpand.rs +++ b/src/unexpand/unexpand.rs @@ -239,7 +239,7 @@ fn unexpand(options: Options) { } let (ctype, cwidth, nbytes) = if options.uflag { - let nbytes = uucore::utf8::utf8_char_width(buf[byte]); + let nbytes = char::from(buf[byte]).len_utf8(); // figure out how big the next char is, if it's UTF-8 if byte + nbytes > buf.len() { diff --git a/src/uucore/lib.rs b/src/uucore/lib.rs index bfa111564..e391d6975 100644 --- a/src/uucore/lib.rs +++ b/src/uucore/lib.rs @@ -18,8 +18,6 @@ pub mod panic; #[cfg(feature = "fs")] pub mod fs; -#[cfg(feature = "utf8")] -pub mod utf8; #[cfg(feature = "encoding")] pub mod encoding; #[cfg(feature = "parse_time")] diff --git a/src/uucore/utf8.rs b/src/uucore/utf8.rs deleted file mode 100644 index f2d2137a2..000000000 --- a/src/uucore/utf8.rs +++ /dev/null @@ -1,27 +0,0 @@ -/* This is taken from the rust_unicode crate. Remove once 'unicode' becomes stable */ - -// https://tools.ietf.org/html/rfc3629 -static UTF8_CHAR_WIDTH: [u8; 256] = [ -1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, -1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x1F -1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, -1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x3F -1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, -1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x5F -1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, -1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x7F -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0x9F -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0xBF -0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2, -2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, // 0xDF -3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, // 0xEF -4,4,4,4,4,0,0,0,0,0,0,0,0,0,0,0, // 0xFF -]; - -/// Given a first byte, determine how many bytes are in this UTF-8 character -#[inline] -pub fn utf8_char_width(b: u8) -> usize { - return UTF8_CHAR_WIDTH[b as usize] as usize; -}