From b9e0ce0b1c55b2d71eb8c844ed9baecc3aea65a0 Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Wed, 24 Dec 2014 20:53:27 +1100 Subject: [PATCH] Fix build with rustc master * core::slice::Items renamd to core::slice::Iter * from_utf8 returns Result instead of Option * Unique type per fn item. Rust Issue #19891 --- mkuutils.rs | 2 +- src/dirname/dirname.rs | 2 +- src/du/du.rs | 4 ++-- src/echo/echo.rs | 2 +- src/fmt/parasplit.rs | 4 ++-- src/nl/nl.rs | 2 +- src/test/test.rs | 4 ++-- src/wc/wc.rs | 4 ++-- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/mkuutils.rs b/mkuutils.rs index 72c9b20a4..c263297de 100644 --- a/mkuutils.rs +++ b/mkuutils.rs @@ -40,7 +40,7 @@ fn main() { } _ => { crates.push_str(format!("extern crate {};\n", prog).as_slice()); - util_map.push_str(format!("map.insert(\"{prog}\", {prog}::uumain);\n", prog = prog).as_slice()); + util_map.push_str(format!("map.insert(\"{prog}\", {prog}::uumain as fn(Vec) -> int);\n", prog = prog).as_slice()); } } } diff --git a/src/dirname/dirname.rs b/src/dirname/dirname.rs index 4fdf927cf..8b25bdb67 100644 --- a/src/dirname/dirname.rs +++ b/src/dirname/dirname.rs @@ -54,7 +54,7 @@ directory).", &opts).as_slice()); for path in matches.free.iter() { let p = std::path::Path::new(path.clone()); let d = std::str::from_utf8(p.dirname()); - if d.is_some() { + if d.is_ok() { print(d.unwrap()); } print(separator); diff --git a/src/du/du.rs b/src/du/du.rs index f98ff1a40..c84c4e283 100644 --- a/src/du/du.rs +++ b/src/du/du.rs @@ -194,7 +194,7 @@ ers of 1000).", let summarize = matches.opt_present("summarize"); let max_depth_str = matches.opt_str("max-depth"); - let max_depth = max_depth_str.as_ref().and_then(|s| from_str::(s.as_slice())); + let max_depth = max_depth_str.as_ref().and_then(|s| s.parse::()); match (max_depth_str, max_depth) { (Some(ref s), _) if summarize => { show_error!("summarizing conflicts with --max-depth={}", *s); @@ -246,7 +246,7 @@ ers of 1000).", letters.push(c); } } - let number = from_utf8(numbers.as_slice()).and_then(from_str::).unwrap(); + let number = from_utf8(numbers.as_slice()).ok().unwrap().parse::().unwrap(); let multiple = match String::from_chars(letters.as_slice()).as_slice() { "K" => 1024, "M" => 1024 * 1024, "G" => 1024 * 1024 * 1024, "T" => 1024 * 1024 * 1024 * 1024, "P" => 1024 * 1024 * 1024 * 1024 * 1024, diff --git a/src/echo/echo.rs b/src/echo/echo.rs index f546041b3..1cf203f08 100644 --- a/src/echo/echo.rs +++ b/src/echo/echo.rs @@ -53,7 +53,7 @@ fn isodigit(c: u8) -> bool { } fn convert_str(string: &[u8], index: uint, base: uint) -> (char, uint) { - let (max_digits, is_legal_digit) = match base { + let (max_digits, is_legal_digit) : (uint, fn(u8) -> bool) = match base { 8u => (3, isodigit), 16u => (2, isxdigit), _ => panic!(), diff --git a/src/fmt/parasplit.rs b/src/fmt/parasplit.rs index 0b8c02013..583262f90 100644 --- a/src/fmt/parasplit.rs +++ b/src/fmt/parasplit.rs @@ -9,7 +9,7 @@ use core::iter::Peekable; use std::io::Lines; -use std::slice::Items; +use std::slice::Iter; use std::str::CharRange; use FileOrStdReader; use FmtOptions; @@ -440,7 +440,7 @@ impl<'a> ParaWords<'a> { } } - pub fn words(&'a self) -> Items<'a, WordInfo<'a>> { return self.words.iter() } + pub fn words(&'a self) -> Iter<'a, WordInfo<'a>> { return self.words.iter() } } struct WordSplit<'a> { diff --git a/src/nl/nl.rs b/src/nl/nl.rs index 51016a4f0..3d2e2e95e 100644 --- a/src/nl/nl.rs +++ b/src/nl/nl.rs @@ -176,7 +176,7 @@ fn nl (reader: &mut BufferedReader, settings: &Settings) { NumberingStyle::NumberForRegularExpression(ref re) => re, _ => REGEX_DUMMY, }; - let mut line_filter = pass_regex; + let mut line_filter : fn(&str, ®ex::Regex) -> bool = pass_regex; for mut l in reader.lines().map(|r| r.unwrap()) { // Sanitize the string. We want to print the newline ourselves. if l.as_slice().chars().rev().next().unwrap() == '\n' { diff --git a/src/test/test.rs b/src/test/test.rs index 6db9d0787..ea41e643d 100644 --- a/src/test/test.rs +++ b/src/test/test.rs @@ -121,7 +121,7 @@ enum IntegerCondition { fn integers(a: &[u8], b: &[u8], cond: IntegerCondition) -> bool { let (a, b): (&str, &str) = match (from_utf8(a), from_utf8(b)) { - (Some(a), Some(b)) => (a, b), + (Ok(a), Ok(b)) => (a, b), _ => return false, }; let (a, b): (i64, i64) = match (from_str(a), from_str(b)) { @@ -140,7 +140,7 @@ fn integers(a: &[u8], b: &[u8], cond: IntegerCondition) -> bool { fn isatty(fd: &[u8]) -> bool { use libc::{isatty}; - from_utf8(fd).and_then(|s| from_str(s)) + from_utf8(fd).ok().and_then(|s| from_str(s)) .map(|i| unsafe { isatty(i) == 1 }).unwrap_or(false) } diff --git a/src/wc/wc.rs b/src/wc/wc.rs index 20ac836a3..e473ea4b3 100644 --- a/src/wc/wc.rs +++ b/src/wc/wc.rs @@ -128,12 +128,12 @@ pub fn wc(files: Vec, matches: &Matches) -> StdResult<(), int> { // try and convert the bytes to UTF-8 first match from_utf8(raw_line.as_slice()) { - Some(line) => { + Ok(line) => { word_count += line.words().count(); current_char_count = line.char_len(); char_count += current_char_count; }, - None => { + Err(..) => { word_count += raw_line.as_slice().split(|&x| is_word_seperator(x)).count(); for byte in raw_line.iter() { match byte.is_ascii() {