From 0a64dbfe8bfbb78ad6b72a9fbd81a84abe7e88c7 Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Mon, 22 Dec 2014 01:54:51 +1100 Subject: [PATCH 1/6] Bump rust-crypto to v0.2.2 --- Makefile | 2 +- deps/rust-crypto | 2 +- src/hashsum/hashsum.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 8cf7542f8..e2b6ff48f 100644 --- a/Makefile +++ b/Makefile @@ -223,7 +223,7 @@ $(BUILDDIR)/uutils: $(SRCDIR)/uutils/uutils.rs $(BUILDDIR)/mkuutils $(RLIB_PATHS # Dependencies -include $(BUILDDIR)/rust-crypto.d $(BUILDDIR)/.rust-crypto: $(BUILDDIR)/.rust-time | $(BUILDDIR) - $(RUSTC) $(RUSTCFLAGS) --extern time=$(BUILDDIR)/libtime.rlib --crate-type rlib --dep-info $(BUILDDIR)/rust-crypto.d $(BASEDIR)/deps/rust-crypto/src/rust-crypto/lib.rs --out-dir $(BUILDDIR)/ + $(RUSTC) $(RUSTCFLAGS) --extern time=$(BUILDDIR)/libtime.rlib --crate-type rlib --crate-name crypto --dep-info $(BUILDDIR)/rust-crypto.d $(BASEDIR)/deps/rust-crypto/src/rust-crypto/lib.rs --out-dir $(BUILDDIR)/ @touch $@ $(BUILDDIR)/.rust-time: diff --git a/deps/rust-crypto b/deps/rust-crypto index b463ff97f..baa0874a7 160000 --- a/deps/rust-crypto +++ b/deps/rust-crypto @@ -1 +1 @@ -Subproject commit b463ff97f78ea06ce9bcf0f1fafe63e5966f2499 +Subproject commit baa0874a75fcb76eeb6a7e430f02aaaf4e4b2701 diff --git a/src/hashsum/hashsum.rs b/src/hashsum/hashsum.rs index fb6582039..f0a6b739e 100644 --- a/src/hashsum/hashsum.rs +++ b/src/hashsum/hashsum.rs @@ -15,7 +15,7 @@ extern crate regex; -extern crate "rust-crypto" as crypto; +extern crate crypto; extern crate getopts; use std::io::fs::File; From 9b67c372b276e9d50ad66415ec01b79f2d744758 Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Mon, 22 Dec 2014 10:48:23 +1100 Subject: [PATCH 2/6] Add semicolons to item macros --- src/common/util.rs | 32 ++++++++++++++++---------------- src/cut/cut.rs | 2 +- src/fmt/fmt.rs | 2 +- src/kill/kill.rs | 2 +- src/tail/tail.rs | 2 +- src/uptime/uptime.rs | 2 +- test/mv.rs | 4 ++-- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/common/util.rs b/src/common/util.rs index 8531a5aa3..5986eca63 100644 --- a/src/common/util.rs +++ b/src/common/util.rs @@ -17,7 +17,7 @@ macro_rules! show_error( pipe_write!(&mut ::std::io::stderr(), "{}: error: ", ::NAME); pipe_writeln!(&mut ::std::io::stderr(), $($args),+); }) -) +); #[macro_export] macro_rules! show_warning( @@ -25,7 +25,7 @@ macro_rules! show_warning( pipe_write!(&mut ::std::io::stderr(), "{}: warning: ", ::NAME); pipe_writeln!(&mut ::std::io::stderr(), $($args),+); }) -) +); #[macro_export] macro_rules! show_info( @@ -33,17 +33,17 @@ macro_rules! show_info( pipe_write!(&mut ::std::io::stderr(), "{}: ", ::NAME); pipe_writeln!(&mut ::std::io::stderr(), $($args),+); }) -) +); #[macro_export] macro_rules! eprint( ($($args:expr),+) => (pipe_write!(&mut ::std::io::stderr(), $($args),+)) -) +); #[macro_export] macro_rules! eprintln( ($($args:expr),+) => (pipe_writeln!(&mut ::std::io::stderr(), $($args),+)) -) +); #[macro_export] macro_rules! crash( @@ -51,14 +51,14 @@ macro_rules! crash( show_error!($($args),+); unsafe { ::util::libc::exit($exitcode as ::util::libc::c_int); } }) -) +); #[macro_export] macro_rules! exit( ($exitcode:expr) => ({ unsafe { ::util::libc::exit($exitcode); } }) -) +); #[macro_export] macro_rules! crash_if_err( @@ -68,7 +68,7 @@ macro_rules! crash_if_err( Err(f) => crash!($exitcode, "{}", f.to_string()) } ) -) +); #[macro_export] macro_rules! return_if_err( @@ -81,7 +81,7 @@ macro_rules! return_if_err( } } ) -) +); // XXX: should the pipe_* macros return an Err just to show the write failed? @@ -99,7 +99,7 @@ macro_rules! pipe_print( } } ) -) +); #[macro_export] macro_rules! pipe_println( @@ -115,7 +115,7 @@ macro_rules! pipe_println( } } ) -) +); #[macro_export] macro_rules! pipe_write( @@ -131,7 +131,7 @@ macro_rules! pipe_write( } } ) -) +); #[macro_export] macro_rules! pipe_writeln( @@ -147,7 +147,7 @@ macro_rules! pipe_writeln( } } ) -) +); #[macro_export] macro_rules! safe_write( @@ -157,7 +157,7 @@ macro_rules! safe_write( Err(f) => panic!(f.to_string()) } ) -) +); #[macro_export] macro_rules! safe_writeln( @@ -167,7 +167,7 @@ macro_rules! safe_writeln( Err(f) => panic!(f.to_string()) } ) -) +); #[macro_export] macro_rules! safe_unwrap( @@ -177,4 +177,4 @@ macro_rules! safe_unwrap( Err(f) => crash!(1, "{}", f.to_string()) } ) -) +); diff --git a/src/cut/cut.rs b/src/cut/cut.rs index bf97e1d14..9d793204d 100644 --- a/src/cut/cut.rs +++ b/src/cut/cut.rs @@ -463,7 +463,7 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts(args.tail(), &opts) { Ok(m) => m, Err(f) => { - show_error!("Invalid options\n{}", f) + show_error!("Invalid options\n{}", f); return 1; } }; diff --git a/src/fmt/fmt.rs b/src/fmt/fmt.rs index f3dd1915c..eaee850c4 100644 --- a/src/fmt/fmt.rs +++ b/src/fmt/fmt.rs @@ -27,7 +27,7 @@ macro_rules! silent_unwrap( Err(_) => unsafe { ::util::libc::exit(1) } } ) -) +); #[path = "../common/util.rs"] mod util; mod linebreak; diff --git a/src/kill/kill.rs b/src/kill/kill.rs index 6ed91df25..cec00d0b0 100644 --- a/src/kill/kill.rs +++ b/src/kill/kill.rs @@ -146,7 +146,7 @@ fn table() { fn print_signal(signal_name_or_value: &str) { for signal in ALL_SIGNALS.iter() { if signal.name == signal_name_or_value || (format!("SIG{}", signal.name).as_slice()) == signal_name_or_value { - println!("{}", signal.value) + println!("{}", signal.value); exit!(EXIT_OK as i32) } else if signal_name_or_value == signal.value.to_string().as_slice() { println!("{}", signal.name); diff --git a/src/tail/tail.rs b/src/tail/tail.rs index 6dbd10694..af95a4685 100644 --- a/src/tail/tail.rs +++ b/src/tail/tail.rs @@ -266,7 +266,7 @@ macro_rules! tail_impl ( $kindprint(&mut stdout, datum); } }) -) +); fn tail(reader: &mut BufferedReader, mut line_count: uint, mut byte_count: uint, beginning: bool, lines: bool, follow: bool, sleep_msec: u64) { if lines { diff --git a/src/uptime/uptime.rs b/src/uptime/uptime.rs index af980e3f3..3ddaa0838 100644 --- a/src/uptime/uptime.rs +++ b/src/uptime/uptime.rs @@ -97,7 +97,7 @@ fn print_loadavg() { print!("\n"); } else { - print!("load average: ") + print!("load average: "); for n in range(0, loads) { print!("{:.2}{}", avg[n as uint], if n == loads - 1 { "\n" } else { ", " } ); diff --git a/test/mv.rs b/test/mv.rs index 322e58f67..241780216 100644 --- a/test/mv.rs +++ b/test/mv.rs @@ -17,7 +17,7 @@ macro_rules! assert_empty_stderr( panic!(format!("stderr: {}", $cond.stderr)) } ); -) +); struct CmdResult { success: bool, stderr: String, @@ -388,7 +388,7 @@ fn test_mv_backup_dir() { assert_empty_stderr!(result); assert_eq!(result.stdout.as_slice(), - format!("‘{}’ -> ‘{}’ (backup: ‘{}~’)\n", dir_a, dir_b, dir_b).as_slice()) + format!("‘{}’ -> ‘{}’ (backup: ‘{}~’)\n", dir_a, dir_b, dir_b).as_slice()); assert!(result.success); assert!(!Path::new(dir_a).is_dir()); From 5cfde0dcb9a1c4b84f314e7173b3722b196f20c1 Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Mon, 22 Dec 2014 10:50:38 +1100 Subject: [PATCH 3/6] Avoid shadowing lifetime names --- src/fmt/parasplit.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fmt/parasplit.rs b/src/fmt/parasplit.rs index 9680484c9..0b8c02013 100644 --- a/src/fmt/parasplit.rs +++ b/src/fmt/parasplit.rs @@ -72,7 +72,7 @@ pub struct FileLines<'a> { } impl<'a> FileLines<'a> { - fn new<'a>(opts: &'a FmtOptions, lines: Lines<'a, FileOrStdReader>) -> FileLines<'a> { + fn new<'b>(opts: &'b FmtOptions, lines: Lines<'b, FileOrStdReader>) -> FileLines<'b> { FileLines { opts: opts, lines: lines } } @@ -216,7 +216,7 @@ pub struct ParagraphStream<'a> { } impl<'a> ParagraphStream<'a> { - pub fn new<'a>(opts: &'a FmtOptions, reader: &'a mut FileOrStdReader) -> ParagraphStream<'a> { + pub fn new<'b>(opts: &'b FmtOptions, reader: &'b mut FileOrStdReader) -> ParagraphStream<'b> { let lines = FileLines::new(opts, reader.lines()).peekable(); // at the beginning of the file, we might find mail headers ParagraphStream { lines: lines, next_mail: true, opts: opts } @@ -399,7 +399,7 @@ pub struct ParaWords<'a> { } impl<'a> ParaWords<'a> { - pub fn new<'a>(opts: &'a FmtOptions, para: &'a Paragraph) -> ParaWords<'a> { + pub fn new<'b>(opts: &'b FmtOptions, para: &'b Paragraph) -> ParaWords<'b> { let mut pw = ParaWords { opts: opts, para: para, words: Vec::new() }; pw.create_words(); pw @@ -478,7 +478,7 @@ impl<'a> WordSplit<'a> { } impl<'a> WordSplit<'a> { - fn new<'a>(opts: &'a FmtOptions, string: &'a str) -> WordSplit<'a> { + fn new<'b>(opts: &'b FmtOptions, string: &'b str) -> WordSplit<'b> { // wordsplits *must* start at a non-whitespace character let trim_string = string.trim_left(); WordSplit { opts: opts, string: trim_string, length: string.len(), position: 0, prev_punct: false } From 872bb0010ae4302bcf8c4648ecda9e27ea5ba259 Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Mon, 22 Dec 2014 10:51:19 +1100 Subject: [PATCH 4/6] regex::Captures::{at,name} returns Option --- src/chmod/chmod.rs | 6 +++--- src/hashsum/hashsum.rs | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/chmod/chmod.rs b/src/chmod/chmod.rs index de8ae0c7d..6a9d0ce7b 100644 --- a/src/chmod/chmod.rs +++ b/src/chmod/chmod.rs @@ -205,9 +205,9 @@ fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool }; for mode in cmode.unwrap().as_slice().split(',') { // cmode is guaranteed to be Some in this case let cap = REGEXP.captures(mode).unwrap(); // mode was verified earlier, so this is safe - if cap.at(1) != "" { + if cap.at(1).unwrap() != "" { // symbolic - let mut levels = cap.at(2); + let mut levels = cap.at(2).unwrap(); if levels.len() == 0 { levels = "a"; } @@ -272,7 +272,7 @@ fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool } } else { // numeric - let change = cap.at(4); + let change = cap.at(4).unwrap(); let ch = change.char_at(0); let (action, slice) = match ch { '+' | '-' | '=' => (ch, change.slice_from(1)), diff --git a/src/hashsum/hashsum.rs b/src/hashsum/hashsum.rs index f0a6b739e..d9d022b5a 100644 --- a/src/hashsum/hashsum.rs +++ b/src/hashsum/hashsum.rs @@ -213,9 +213,13 @@ fn hashsum(algoname: &str, mut digest: Box, files: Vec, binary: for (i, line) in buffer.lines().enumerate() { let line = safe_unwrap!(line); let (ck_filename, sum, binary_check): (_, Vec, _) = match gnu_re.captures(line.as_slice()) { - Some(caps) => (caps.name("fileName"), caps.name("digest").to_ascii().iter().map(|ch| ch.to_lowercase()).collect(), caps.name("binary") == "*"), + Some(caps) => (caps.name("fileName").unwrap(), + caps.name("digest").unwrap().to_ascii().iter().map(|ch| ch.to_lowercase()).collect(), + caps.name("binary").unwrap() == "*"), None => match bsd_re.captures(line.as_slice()) { - Some(caps) => (caps.name("fileName"), caps.name("digest").to_ascii().iter().map(|ch| ch.to_lowercase()).collect(), true), + Some(caps) => (caps.name("fileName").unwrap(), + caps.name("digest").unwrap().to_ascii().iter().map(|ch| ch.to_lowercase()).collect(), + true), None => { bad_format += 1; if strict { From 8cb5d03d0c8e84a16b04067a3adee25bcfd61f51 Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Mon, 22 Dec 2014 10:53:54 +1100 Subject: [PATCH 5/6] Fix a mismatched types compilation error --- src/hashsum/hashsum.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hashsum/hashsum.rs b/src/hashsum/hashsum.rs index d9d022b5a..944f7a249 100644 --- a/src/hashsum/hashsum.rs +++ b/src/hashsum/hashsum.rs @@ -232,7 +232,8 @@ fn hashsum(algoname: &str, mut digest: Box, files: Vec, binary: } } }; - let real_sum: Vec = safe_unwrap!(digest_reader(&mut digest, &mut safe_unwrap!(File::open(&Path::new(ck_filename))), binary_check)) + let mut ckf = safe_unwrap!(File::open(&Path::new(ck_filename))); + let real_sum: Vec = safe_unwrap!(digest_reader(&mut digest, &mut ckf, binary_check)) .as_slice().to_ascii().iter().map(|ch| ch.to_lowercase()).collect(); if sum.as_slice() == real_sum.as_slice() { if !quiet { From 75425f1fe804ca93cf534178fbe8513c3ea820f9 Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Mon, 22 Dec 2014 11:39:02 +1100 Subject: [PATCH 6/6] Fix build with rust nightly Dec-20-2014 --- src/paste/paste.rs | 3 ++- src/split/split.rs | 5 +++-- src/tac/tac.rs | 3 ++- src/uniq/uniq.rs | 6 ++++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/paste/paste.rs b/src/paste/paste.rs index 38d210c43..04b77ee4c 100644 --- a/src/paste/paste.rs +++ b/src/paste/paste.rs @@ -62,7 +62,8 @@ fn paste(filenames: Vec, serial: bool, delimiters: &str) { if name.as_slice() == "-" { box io::stdio::stdin_raw() as Box } else { - box crash_if_err!(1, io::File::open(&Path::new(name))) as Box + let r = crash_if_err!(1, io::File::open(&Path::new(name))); + box r as Box } ) ).collect(); diff --git a/src/split/split.rs b/src/split/split.rs index e4b4fc6a8..f6d99fb86 100644 --- a/src/split/split.rs +++ b/src/split/split.rs @@ -221,10 +221,11 @@ fn split(settings: &Settings) -> int { if settings.input.as_slice() == "-" { box io::stdio::stdin_raw() as Box } else { - box match io::File::open(&Path::new(settings.input.clone())) { + let r = match io::File::open(&Path::new(settings.input.clone())) { Ok(a) => a, Err(_) => crash!(1, "cannot open '{}' for reading: No such file or directory", settings.input) - } as Box + }; + box r as Box } ); diff --git a/src/tac/tac.rs b/src/tac/tac.rs index 6eab7e6a1..cadbd43e4 100644 --- a/src/tac/tac.rs +++ b/src/tac/tac.rs @@ -75,7 +75,8 @@ fn tac(filenames: Vec, before: bool, _: bool, separator: &str) { if filename.as_slice() == "-" { box io::stdio::stdin_raw() as Box } else { - box crash_if_err!(1, io::File::open(&Path::new(filename))) as Box + let r = crash_if_err!(1, io::File::open(&Path::new(filename))); + box r as Box } ); let mut data = crash_if_err!(1, file.read_to_string()); diff --git a/src/uniq/uniq.rs b/src/uniq/uniq.rs index d082e6712..98fe7e2d1 100644 --- a/src/uniq/uniq.rs +++ b/src/uniq/uniq.rs @@ -196,7 +196,8 @@ fn open_input_file(in_file_name: String) -> io::BufferedReader + let r = crash_if_err!(1, in_file); + box r as Box }; io::BufferedReader::new(in_file) } @@ -207,7 +208,8 @@ fn open_output_file(out_file_name: String) -> io::BufferedWriter + let w = crash_if_err!(1, in_file); + box w as Box }; io::BufferedWriter::new(out_file) }