diff options
| author | Jorge Aparicio <japaricious@gmail.com> | 2016-03-22 22:01:37 -0500 |
|---|---|---|
| committer | Jorge Aparicio <japaricious@gmail.com> | 2016-03-22 22:01:37 -0500 |
| commit | 0f02309e4b0ea05ee905205278fb6d131341c41f (patch) | |
| tree | a259129eeb84705de15b51587ddebd0f82735075 /src/libterm | |
| parent | 0dcc413e42f15f4fc51a0ca88a99cc89454ec43d (diff) | |
| download | rust-0f02309e4b0ea05ee905205278fb6d131341c41f.tar.gz rust-0f02309e4b0ea05ee905205278fb6d131341c41f.zip | |
try! -> ?
Automated conversion using the untry tool [1] and the following command: ``` $ find -name '*.rs' -type f | xargs untry ``` at the root of the Rust repo. [1]: https://github.com/japaric/untry
Diffstat (limited to 'src/libterm')
| -rw-r--r-- | src/libterm/terminfo/mod.rs | 2 | ||||
| -rw-r--r-- | src/libterm/terminfo/parm.rs | 4 | ||||
| -rw-r--r-- | src/libterm/terminfo/parser/compiled.rs | 32 |
3 files changed, 17 insertions, 21 deletions
diff --git a/src/libterm/terminfo/mod.rs b/src/libterm/terminfo/mod.rs index e54f763fd0d..395d966b9f2 100644 --- a/src/libterm/terminfo/mod.rs +++ b/src/libterm/terminfo/mod.rs @@ -109,7 +109,7 @@ impl TermInfo { } // Keep the metadata small fn _from_path(path: &Path) -> Result<TermInfo, Error> { - let file = try!(File::open(path).map_err(|e| Error::IoError(e))); + let file = File::open(path).map_err(|e| Error::IoError(e))?; let mut reader = BufReader::new(file); parse(&mut reader, false).map_err(|e| Error::MalformedTerminfo(e)) } diff --git a/src/libterm/terminfo/parm.rs b/src/libterm/terminfo/parm.rs index aceaa0c10bc..60b5dffac59 100644 --- a/src/libterm/terminfo/parm.rs +++ b/src/libterm/terminfo/parm.rs @@ -209,7 +209,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result<Vec< 'd' | 'o' | 'x' | 'X' | 's' => { if let Some(arg) = stack.pop() { let flags = Flags::new(); - let res = try!(format(arg, FormatOp::from_char(cur), flags)); + let res = format(arg, FormatOp::from_char(cur), flags)?; output.extend(res.iter().map(|x| *x)); } else { return Err("stack is empty".to_string()); @@ -317,7 +317,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) -> Result<Vec< match (*fstate, cur) { (_, 'd') | (_, 'o') | (_, 'x') | (_, 'X') | (_, 's') => { if let Some(arg) = stack.pop() { - let res = try!(format(arg, FormatOp::from_char(cur), *flags)); + let res = format(arg, FormatOp::from_char(cur), *flags)?; output.extend(res.iter().map(|x| *x)); // will cause state to go to Nothing old_state = FormatPattern(*flags, *fstate); diff --git a/src/libterm/terminfo/parser/compiled.rs b/src/libterm/terminfo/parser/compiled.rs index 558d35c2ae2..9ce3a2aadd5 100644 --- a/src/libterm/terminfo/parser/compiled.rs +++ b/src/libterm/terminfo/parser/compiled.rs @@ -168,7 +168,7 @@ fn read_le_u16(r: &mut io::Read) -> io::Result<u16> { let mut b = [0; 2]; let mut amt = 0; while amt < b.len() { - match try!(r.read(&mut b[amt..])) { + match r.read(&mut b[amt..])? { 0 => return Err(io::Error::new(io::ErrorKind::Other, "end of file")), n => amt += n, } @@ -200,7 +200,7 @@ pub fn parse(file: &mut io::Read, longnames: bool) -> Result<TermInfo, String> { }; // Check magic number - let magic = try!(read_le_u16(file)); + let magic = read_le_u16(file)?; if magic != 0x011A { return Err(format!("invalid magic number: expected {:x}, found {:x}", 0x011A, @@ -243,7 +243,7 @@ pub fn parse(file: &mut io::Read, longnames: bool) -> Result<TermInfo, String> { // don't read NUL let mut bytes = Vec::new(); - try!(file.take((names_bytes - 1) as u64).read_to_end(&mut bytes)); + file.take((names_bytes - 1) as u64).read_to_end(&mut bytes)?; let names_str = match String::from_utf8(bytes) { Ok(s) => s, Err(_) => return Err("input not utf-8".to_string()), @@ -253,39 +253,35 @@ pub fn parse(file: &mut io::Read, longnames: bool) -> Result<TermInfo, String> { .map(|s| s.to_string()) .collect(); // consume NUL - if try!(read_byte(file)) != b'\0' { + if read_byte(file)? != b'\0' { return Err("incompatible file: missing null terminator for names section".to_string()); } - let bools_map: HashMap<String, bool> = try! { - (0..bools_bytes).filter_map(|i| match read_byte(file) { + let bools_map: HashMap<String, bool> = (0..bools_bytes).filter_map(|i| match read_byte(file) { Err(e) => Some(Err(e)), Ok(1) => Some(Ok((bnames[i].to_string(), true))), Ok(_) => None - }).collect() - }; + }).collect()?; if (bools_bytes + names_bytes) % 2 == 1 { - try!(read_byte(file)); // compensate for padding + read_byte(file)?; // compensate for padding } - let numbers_map: HashMap<String, u16> = try! { - (0..numbers_count).filter_map(|i| match read_le_u16(file) { + let numbers_map: HashMap<String, u16> = (0..numbers_count).filter_map(|i| match read_le_u16(file) { Ok(0xFFFF) => None, Ok(n) => Some(Ok((nnames[i].to_string(), n))), Err(e) => Some(Err(e)) - }).collect() - }; + }).collect()?; let string_map: HashMap<String, Vec<u8>> = if string_offsets_count > 0 { - let string_offsets: Vec<u16> = try!((0..string_offsets_count) + let string_offsets: Vec<u16> = (0..string_offsets_count) .map(|_| read_le_u16(file)) - .collect()); + .collect()?; let mut string_table = Vec::new(); - try!(file.take(string_table_bytes as u64).read_to_end(&mut string_table)); + file.take(string_table_bytes as u64).read_to_end(&mut string_table)?; - try!(string_offsets.into_iter().enumerate().filter(|&(_, offset)| { + string_offsets.into_iter().enumerate().filter(|&(_, offset)| { // non-entry offset != 0xFFFF }).map(|(i, offset)| { @@ -309,7 +305,7 @@ pub fn parse(file: &mut io::Read, longnames: bool) -> Result<TermInfo, String> { Some(len) => Ok((name.to_string(), string_table[offset..offset + len].to_vec())), None => Err("invalid file: missing NUL in string_table".to_string()), } - }).collect()) + }).collect()? } else { HashMap::new() }; |
