1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-01 13:37:48 +00:00

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
This commit is contained in:
Haitao Li 2014-12-24 20:53:27 +11:00
parent a6f0b24089
commit b9e0ce0b1c
8 changed files with 12 additions and 12 deletions

View file

@ -40,7 +40,7 @@ fn main() {
} }
_ => { _ => {
crates.push_str(format!("extern crate {};\n", prog).as_slice()); 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<String>) -> int);\n", prog = prog).as_slice());
} }
} }
} }

View file

@ -54,7 +54,7 @@ directory).", &opts).as_slice());
for path in matches.free.iter() { for path in matches.free.iter() {
let p = std::path::Path::new(path.clone()); let p = std::path::Path::new(path.clone());
let d = std::str::from_utf8(p.dirname()); let d = std::str::from_utf8(p.dirname());
if d.is_some() { if d.is_ok() {
print(d.unwrap()); print(d.unwrap());
} }
print(separator); print(separator);

View file

@ -194,7 +194,7 @@ ers of 1000).",
let summarize = matches.opt_present("summarize"); let summarize = matches.opt_present("summarize");
let max_depth_str = matches.opt_str("max-depth"); let max_depth_str = matches.opt_str("max-depth");
let max_depth = max_depth_str.as_ref().and_then(|s| from_str::<uint>(s.as_slice())); let max_depth = max_depth_str.as_ref().and_then(|s| s.parse::<uint>());
match (max_depth_str, max_depth) { match (max_depth_str, max_depth) {
(Some(ref s), _) if summarize => { (Some(ref s), _) if summarize => {
show_error!("summarizing conflicts with --max-depth={}", *s); show_error!("summarizing conflicts with --max-depth={}", *s);
@ -246,7 +246,7 @@ ers of 1000).",
letters.push(c); letters.push(c);
} }
} }
let number = from_utf8(numbers.as_slice()).and_then(from_str::<uint>).unwrap(); let number = from_utf8(numbers.as_slice()).ok().unwrap().parse::<uint>().unwrap();
let multiple = match String::from_chars(letters.as_slice()).as_slice() { let multiple = match String::from_chars(letters.as_slice()).as_slice() {
"K" => 1024, "M" => 1024 * 1024, "G" => 1024 * 1024 * 1024, "K" => 1024, "M" => 1024 * 1024, "G" => 1024 * 1024 * 1024,
"T" => 1024 * 1024 * 1024 * 1024, "P" => 1024 * 1024 * 1024 * 1024 * 1024, "T" => 1024 * 1024 * 1024 * 1024, "P" => 1024 * 1024 * 1024 * 1024 * 1024,

View file

@ -53,7 +53,7 @@ fn isodigit(c: u8) -> bool {
} }
fn convert_str(string: &[u8], index: uint, base: uint) -> (char, uint) { 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), 8u => (3, isodigit),
16u => (2, isxdigit), 16u => (2, isxdigit),
_ => panic!(), _ => panic!(),

View file

@ -9,7 +9,7 @@
use core::iter::Peekable; use core::iter::Peekable;
use std::io::Lines; use std::io::Lines;
use std::slice::Items; use std::slice::Iter;
use std::str::CharRange; use std::str::CharRange;
use FileOrStdReader; use FileOrStdReader;
use FmtOptions; 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> { struct WordSplit<'a> {

View file

@ -176,7 +176,7 @@ fn nl<T: Reader> (reader: &mut BufferedReader<T>, settings: &Settings) {
NumberingStyle::NumberForRegularExpression(ref re) => re, NumberingStyle::NumberForRegularExpression(ref re) => re,
_ => REGEX_DUMMY, _ => REGEX_DUMMY,
}; };
let mut line_filter = pass_regex; let mut line_filter : fn(&str, &regex::Regex) -> bool = pass_regex;
for mut l in reader.lines().map(|r| r.unwrap()) { for mut l in reader.lines().map(|r| r.unwrap()) {
// Sanitize the string. We want to print the newline ourselves. // Sanitize the string. We want to print the newline ourselves.
if l.as_slice().chars().rev().next().unwrap() == '\n' { if l.as_slice().chars().rev().next().unwrap() == '\n' {

View file

@ -121,7 +121,7 @@ enum IntegerCondition {
fn integers(a: &[u8], b: &[u8], cond: IntegerCondition) -> bool { fn integers(a: &[u8], b: &[u8], cond: IntegerCondition) -> bool {
let (a, b): (&str, &str) = match (from_utf8(a), from_utf8(b)) { 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, _ => return false,
}; };
let (a, b): (i64, i64) = match (from_str(a), from_str(b)) { 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 { fn isatty(fd: &[u8]) -> bool {
use libc::{isatty}; 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) .map(|i| unsafe { isatty(i) == 1 }).unwrap_or(false)
} }

View file

@ -128,12 +128,12 @@ pub fn wc(files: Vec<String>, matches: &Matches) -> StdResult<(), int> {
// try and convert the bytes to UTF-8 first // try and convert the bytes to UTF-8 first
match from_utf8(raw_line.as_slice()) { match from_utf8(raw_line.as_slice()) {
Some(line) => { Ok(line) => {
word_count += line.words().count(); word_count += line.words().count();
current_char_count = line.char_len(); current_char_count = line.char_len();
char_count += current_char_count; char_count += current_char_count;
}, },
None => { Err(..) => {
word_count += raw_line.as_slice().split(|&x| is_word_seperator(x)).count(); word_count += raw_line.as_slice().split(|&x| is_word_seperator(x)).count();
for byte in raw_line.iter() { for byte in raw_line.iter() {
match byte.is_ascii() { match byte.is_ascii() {