Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ebfe committed Jan 6, 2016
1 parent 865ea10 commit a2944e0
Show file tree
Hide file tree
Showing 77 changed files with 435 additions and 504 deletions.
10 changes: 5 additions & 5 deletions src/basename/basename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ fn strip_dir(fullname: &str) -> String {
// Convert to path buffer and get last path component
let pb = PathBuf::from(path);
match pb.components().last() {
Some(c) => c.as_os_str().to_str().unwrap().to_string(),
None => "".to_string()
Some(c) => c.as_os_str().to_str().unwrap().to_owned(),
None => "".to_owned()
}
}

fn strip_suffix(name: &str, suffix: &str) -> String {
if name == suffix {
return name.to_string();
return name.to_owned();
}

if name.ends_with(suffix) {
return name[..name.len() - suffix.len()].to_string();
return name[..name.len() - suffix.len()].to_owned();
}

name.to_string()
name.to_owned()
}
14 changes: 7 additions & 7 deletions src/cat/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ pub fn uumain(args: Vec<String>) -> i32 {
} else {
NumberingMode::NumberNone
};
let show_nonprint = matches.opts_present(&["A".to_string(), "e".to_string(),
"t".to_string(), "v".to_string()]);
let show_ends = matches.opts_present(&["E".to_string(), "A".to_string(),
"e".to_string()]);
let show_tabs = matches.opts_present(&["A".to_string(), "T".to_string(),
"t".to_string()]);
let show_nonprint = matches.opts_present(&["A".to_owned(), "e".to_owned(),
"t".to_owned(), "v".to_owned()]);
let show_ends = matches.opts_present(&["E".to_owned(), "A".to_owned(),
"e".to_owned()]);
let show_tabs = matches.opts_present(&["A".to_owned(), "T".to_owned(),
"t".to_owned()]);
let squeeze_blank = matches.opt_present("s");
let mut files = matches.free;
if files.is_empty() {
files.push("-".to_string());
files.push("-".to_owned());
}

exec(files, number_mode, show_nonprint, show_ends, show_tabs, squeeze_blank);
Expand Down
8 changes: 4 additions & 4 deletions src/chmod/chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'.",
fn chmod(files: Vec<String>, changes: bool, quiet: bool, verbose: bool, preserve_root: bool, recursive: bool, fmode: Option<libc::mode_t>, cmode: Option<&String>) -> Result<(), i32> {
let mut r = Ok(());

for filename in files.iter() {
for filename in &files {
let filename = &filename[..];
let file = Path::new(filename);
if file.exists() {
Expand All @@ -122,7 +122,7 @@ fn chmod(files: Vec<String>, changes: bool, quiet: bool, verbose: bool, preserve
// to chmod() and chmod_file().
r = chmod(walk_dir.filter_map(|x| match x {
Ok(o) => match o.path().into_os_string().to_str() {
Some(s) => Some(s.to_string()),
Some(s) => Some(s.to_owned()),
None => None,
},
Err(e) => None,
Expand Down Expand Up @@ -219,7 +219,7 @@ fn parse_numeric(fperm: libc::mode_t, mut mode: &str) -> Result<libc::mode_t, St
_ => unreachable!()
})
}
Err(err) => Err(err.description().to_string())
Err(err) => Err(err.description().to_owned())
}
}
}
Expand Down Expand Up @@ -273,7 +273,7 @@ fn parse_op(mode: &str, default: Option<char>) -> Result<(char, usize), String>
None => Err(format!("invalid operator (expected +, -, or =, but found {})", ch))
}
},
None => Err("unexpected end of mode".to_string())
None => Err("unexpected end of mode".to_owned())
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/chroot/chroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
if matches.opt_present("V") { version(); return 0 }
if matches.opt_present("h") { help_menu(opts); return 0 }

if matches.free.len() == 0 {
if matches.free.is_empty() {
println!("Missing operand: NEWROOT");
println!("Try `{} --help` for more information.", NAME);
return 1
Expand Down Expand Up @@ -191,7 +191,7 @@ fn set_groups_from_str(groups: &str) {

fn set_user(user: &str) {
if !user.is_empty() {
let user_id = get_pw_from_args(&vec!(user.to_string())).unwrap().pw_uid;
let user_id = get_pw_from_args(&vec!(user.to_owned())).unwrap().pw_uid;
let err = unsafe { setuid(user_id as libc::uid_t) };
if err != 0 {
crash!(1, "cannot set user to {}: {}", user, Error::last_os_error())
Expand Down
2 changes: 1 addition & 1 deletion src/cksum/cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Print CRC and size for each file.", NAME, VERSION);
}

let mut exit_code = 0;
for fname in files.iter() {
for fname in &files {
match cksum(fname.as_ref()) {
Ok((crc, size)) => println!("{} {} {}", crc, size, fname),
Err(err) => {
Expand Down
8 changes: 4 additions & 4 deletions src/comm/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn mkdelim(col: usize, opts: &getopts::Matches) -> String {
let mut s = String::new();
let delim = match opts.opt_str("output-delimiter") {
Some(d) => d.clone(),
None => "\t".to_string(),
None => "\t".to_owned(),
};

if col > 1 && !opts.opt_present("1") {
Expand All @@ -51,9 +51,9 @@ enum LineReader {

impl LineReader {
fn read_line(&mut self, buf: &mut String) -> io::Result<usize> {
match self {
&mut LineReader::Stdin(ref mut r) => r.read_line(buf),
&mut LineReader::FileIn(ref mut r) => r.read_line(buf),
match *self {
LineReader::Stdin(ref mut r) => r.read_line(buf),
LineReader::FileIn(ref mut r) => r.read_line(buf),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/cp/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn version() {
println!("{} {}", NAME, VERSION);
}

fn help(usage: &String) {
fn help(usage: &str) {
let msg = format!("{0} {1}\n\n\
Usage: {0} SOURCE DEST\n \
or: {0} SOURCE... DIRECTORY\n \
Expand All @@ -82,7 +82,7 @@ fn copy(matches: getopts::Matches) {
panic!()
} else {
// All but the last argument:
matches.free[..matches.free.len() - 1].iter().map(|arg| arg.clone()).collect()
matches.free[..matches.free.len() - 1].iter().cloned().collect()
};
let dest = if matches.free.len() < 2 {
show_error!("Missing DEST argument. Try --help.");
Expand Down Expand Up @@ -123,7 +123,7 @@ fn copy(matches: getopts::Matches) {
panic!();
}

for src in sources.iter() {
for src in &sources {
let source = Path::new(&src);

if !source.is_file() {
Expand Down
13 changes: 5 additions & 8 deletions src/cut/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,10 @@ impl<R: Read> ByteReader<R> {
Err(e) => crash!(1, "read error: {}", e),
};

match filled_buf.iter().position(|byte| *byte == b'\n') {
Some(idx) => {
consume_val = idx + 1;
bytes_consumed += consume_val;
break;
}
_ => ()
if let Some(idx) = filled_buf.iter().position(|byte| *byte == b'\n') {
consume_val = idx + 1;
bytes_consumed += consume_val;
break;
}

consume_val = filled_buf.len();
Expand All @@ -94,7 +91,7 @@ impl<R: Read> ByteReader<R> {
}

self.consume(consume_val);
return bytes_consumed;
bytes_consumed
}
}

Expand Down
38 changes: 19 additions & 19 deletions src/cut/cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn list_to_ranges(list: &str, complement: bool) -> Result<Vec<Range>, String> {
}
}

fn cut_bytes<R: Read>(reader: R, ranges: &Vec<Range>, opts: &Options) -> i32 {
fn cut_bytes<R: Read>(reader: R, ranges: &[Range], opts: &Options) -> i32 {
use buffer::Bytes::Select;
use buffer::Bytes::Selected::*;

Expand Down Expand Up @@ -125,7 +125,7 @@ fn cut_bytes<R: Read>(reader: R, ranges: &Vec<Range>, opts: &Options) -> i32 {
0
}

fn cut_characters<R: Read>(reader: R, ranges: &Vec<Range>, opts: &Options) -> i32 {
fn cut_characters<R: Read>(reader: R, ranges: &[Range], opts: &Options) -> i32 {
let mut buf_in = BufReader::new(reader);
let mut out = stdout();
let mut buffer = String::new();
Expand All @@ -135,7 +135,7 @@ fn cut_characters<R: Read>(reader: R, ranges: &Vec<Range>, opts: &Options) -> i3
match buf_in.read_line(&mut buffer) {
Ok(n) if n == 0 => break,
Err(e) => {
if buffer.len() == 0 {
if buffer.is_empty() {
crash!(1, "read error: {}", e);
}
},
Expand Down Expand Up @@ -195,7 +195,7 @@ fn cut_characters<R: Read>(reader: R, ranges: &Vec<Range>, opts: &Options) -> i3
0
}

fn cut_fields_delimiter<R: Read>(reader: R, ranges: &Vec<Range>, delim: &String, only_delimited: bool, out_delim: &String) -> i32 {
fn cut_fields_delimiter<R: Read>(reader: R, ranges: &[Range], delim: &str, only_delimited: bool, out_delim: &str) -> i32 {
let mut buf_in = BufReader::new(reader);
let mut out = stdout();
let mut buffer = Vec::new();
Expand All @@ -205,7 +205,7 @@ fn cut_fields_delimiter<R: Read>(reader: R, ranges: &Vec<Range>, delim: &String,
match buf_in.read_until(b'\n', &mut buffer) {
Ok(n) if n == 0 => break,
Err(e) => {
if buffer.len() == 0 {
if buffer.is_empty() {
crash!(1, "read error: {}", e);
}
},
Expand Down Expand Up @@ -273,7 +273,7 @@ fn cut_fields_delimiter<R: Read>(reader: R, ranges: &Vec<Range>, delim: &String,
0
}

fn cut_fields<R: Read>(reader: R, ranges: &Vec<Range>, opts: &FieldOptions) -> i32 {
fn cut_fields<R: Read>(reader: R, ranges: &[Range], opts: &FieldOptions) -> i32 {
match opts.out_delimeter {
Some(ref o_delim) => {
return cut_fields_delimiter(reader, ranges, &opts.delimiter,
Expand All @@ -291,7 +291,7 @@ fn cut_fields<R: Read>(reader: R, ranges: &Vec<Range>, opts: &FieldOptions) -> i
match buf_in.read_until(b'\n', &mut buffer) {
Ok(n) if n == 0 => break,
Err(e) => {
if buffer.len() == 0 {
if buffer.is_empty() {
crash!(1, "read error: {}", e);
}
},
Expand Down Expand Up @@ -362,9 +362,9 @@ fn cut_files(mut filenames: Vec<String>, mode: Mode) -> i32 {
let mut stdin_read = false;
let mut exit_code = 0;

if filenames.len() == 0 { filenames.push("-".to_string()); }
if filenames.is_empty() { filenames.push("-".to_owned()); }

for filename in filenames.iter() {
for filename in &filenames {
if filename == "-" {
if stdin_read { continue }

Expand Down Expand Up @@ -469,8 +469,8 @@ pub fn uumain(args: Vec<String>) -> i32 {
{
let out_delim = match matches.opt_str("output-delimiter") {
Some(s) => {
if s.len() == 0 {
Some("\0".to_string())
if s.is_empty() {
Some("\0".to_owned())
} else {
Some(s)
}
Expand All @@ -483,10 +483,10 @@ pub fn uumain(args: Vec<String>) -> i32 {
match matches.opt_str("delimiter") {
Some(delim) => {
if delim.chars().count() > 1 {
Err("the delimiter must be a single character, or the empty string for null".to_string())
Err("the delimiter must be a single character, or the empty string for null".to_owned())
} else {
let delim = if delim.len() == 0 {
"\0".to_string()
let delim = if delim.is_empty() {
"\0".to_owned()
} else {
delim
};
Expand All @@ -501,7 +501,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
}
None => Ok(Mode::Fields(ranges,
FieldOptions {
delimiter: "\t".to_string(),
delimiter: "\t".to_owned(),
out_delimeter: out_delim,
only_delimited: only_delimited
}))
Expand All @@ -510,19 +510,19 @@ pub fn uumain(args: Vec<String>) -> i32 {
)
}
(ref b, ref c, ref f) if b.is_some() || c.is_some() || f.is_some() => {
Err("only one type of list may be specified".to_string())
Err("only one type of list may be specified".to_owned())
}
_ => Err("you must specify a list of bytes, characters, or fields".to_string())
_ => Err("you must specify a list of bytes, characters, or fields".to_owned())
};

let mode_parse = match mode_parse {
Err(_) => mode_parse,
Ok(mode) => {
match mode {
Mode::Bytes(_, _) | Mode::Characters(_, _) if matches.opt_present("delimiter") =>
Err("an input delimiter may be specified only when operating on fields".to_string()),
Err("an input delimiter may be specified only when operating on fields".to_owned()),
Mode::Bytes(_, _) | Mode::Characters(_, _) if matches.opt_present("only-delimited") =>
Err("suppressing non-delimited lines makes sense only when operating on fields".to_string()),
Err("suppressing non-delimited lines makes sense only when operating on fields".to_owned()),
_ => Ok(mode),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cut/ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Range {
}
}

pub fn complement(ranges: &Vec<Range>) -> Vec<Range> {
pub fn complement(ranges: &[Range]) -> Vec<Range> {
use std::usize;

let mut complements = Vec::with_capacity(ranges.len() + 1);
Expand Down
7 changes: 2 additions & 5 deletions src/dirname/dirname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,10 @@ directory).", NAME, VERSION);
return 0;
}

let separator = match matches.opt_present("zero") {
true => "\0",
false => "\n"
};
let separator = if matches.opt_present("zero") {"\0"} else {"\n"};

if !matches.free.is_empty() {
for path in matches.free.iter() {
for path in &matches.free {
let p = Path::new(path);
match p.parent() {
Some(d) => {
Expand Down
Loading

0 comments on commit a2944e0

Please sign in to comment.