From 7bb498bd7a09f024fe46fc58ea17fe44cbc68df0 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 19 Feb 2014 10:07:49 -0800 Subject: [PATCH] Mass rename if_ok! to try! This "bubble up an error" macro was originally named if_ok! in order to get it landed, but after the fact it was discovered that this name is not exactly desirable. The name `if_ok!` isn't immediately clear that is has much to do with error handling, and it doesn't look fantastic in all contexts (if if_ok!(...) {}). In general, the agreed opinion about `if_ok!` is that is came in as subpar. The name `try!` is more invocative of error handling, it's shorter by 2 letters, and it looks fitting in almost all circumstances. One concern about the word `try!` is that it's too invocative of exceptions, but the belief is that this will be overcome with documentation and examples. Close #12037 --- src/libextra/json.rs | 104 +- src/libextra/stats.rs | 22 +- src/libnative/io/pipe_unix.rs | 10 +- src/libnative/io/pipe_win32.rs | 6 +- src/librustc/back/archive.rs | 4 +- src/librustc/driver/driver.rs | 32 +- src/librustc/metadata/decoder.rs | 12 +- src/librustc/middle/dataflow.rs | 12 +- src/librustc/middle/liveness.rs | 2 +- src/librustdoc/html/escape.rs | 6 +- src/librustdoc/html/format.rs | 88 +- src/librustdoc/html/render.rs | 324 +++--- src/librustdoc/lib.rs | 4 +- src/libsemver/lib.rs | 14 +- src/libserialize/ebml.rs | 12 +- src/libstd/fmt/mod.rs | 22 +- src/libstd/hashmap.rs | 12 +- src/libstd/io/buffered.rs | 12 +- src/libstd/io/fs.rs | 22 +- src/libstd/io/mem.rs | 8 +- src/libstd/io/mod.rs | 10 +- src/libstd/io/util.rs | 2 +- src/libstd/macros.rs | 2 +- src/libstd/repr.rs | 100 +- src/libstd/tuple.rs | 6 +- src/libstd/vec.rs | 6 +- src/libsyntax/diagnostic.rs | 42 +- src/libsyntax/print/pp.rs | 10 +- src/libsyntax/print/pprust.rs | 1412 +++++++++++------------ src/libterm/lib.rs | 10 +- src/libterm/terminfo/parser/compiled.rs | 28 +- src/libtest/lib.rs | 92 +- 32 files changed, 1222 insertions(+), 1226 deletions(-) diff --git a/src/libextra/json.rs b/src/libextra/json.rs index 5043cad6f20..370d1026c41 100644 --- a/src/libextra/json.rs +++ b/src/libextra/json.rs @@ -246,7 +246,7 @@ use serialize::Encodable; use serialize; use collections::TreeMap; -macro_rules! if_ok( ($e:expr) => ( +macro_rules! try( ($e:expr) => ( match $e { Ok(e) => e, Err(e) => { self.error = Err(e); return } } ) ) @@ -342,7 +342,7 @@ impl<'a> Encoder<'a> { } impl<'a> serialize::Encoder for Encoder<'a> { - fn emit_nil(&mut self) { if_ok!(write!(self.wr, "null")) } + fn emit_nil(&mut self) { try!(write!(self.wr, "null")) } fn emit_uint(&mut self, v: uint) { self.emit_f64(v as f64); } fn emit_u64(&mut self, v: u64) { self.emit_f64(v as f64); } @@ -358,20 +358,20 @@ impl<'a> serialize::Encoder for Encoder<'a> { fn emit_bool(&mut self, v: bool) { if v { - if_ok!(write!(self.wr, "true")); + try!(write!(self.wr, "true")); } else { - if_ok!(write!(self.wr, "false")); + try!(write!(self.wr, "false")); } } fn emit_f64(&mut self, v: f64) { - if_ok!(write!(self.wr, "{}", f64::to_str_digits(v, 6u))) + try!(write!(self.wr, "{}", f64::to_str_digits(v, 6u))) } fn emit_f32(&mut self, v: f32) { self.emit_f64(v as f64); } fn emit_char(&mut self, v: char) { self.emit_str(str::from_char(v)) } fn emit_str(&mut self, v: &str) { - if_ok!(write!(self.wr, "{}", escape_str(v))) + try!(write!(self.wr, "{}", escape_str(v))) } fn emit_enum(&mut self, _name: &str, f: |&mut Encoder<'a>|) { f(self) } @@ -385,19 +385,19 @@ impl<'a> serialize::Encoder for Encoder<'a> { // Bunny => "Bunny" // Kangaroo(34,"William") => {"variant": "Kangaroo", "fields": [34,"William"]} if cnt == 0 { - if_ok!(write!(self.wr, "{}", escape_str(name))); + try!(write!(self.wr, "{}", escape_str(name))); } else { - if_ok!(write!(self.wr, "\\{\"variant\":")); - if_ok!(write!(self.wr, "{}", escape_str(name))); - if_ok!(write!(self.wr, ",\"fields\":[")); + try!(write!(self.wr, "\\{\"variant\":")); + try!(write!(self.wr, "{}", escape_str(name))); + try!(write!(self.wr, ",\"fields\":[")); f(self); - if_ok!(write!(self.wr, "]\\}")); + try!(write!(self.wr, "]\\}")); } } fn emit_enum_variant_arg(&mut self, idx: uint, f: |&mut Encoder<'a>|) { if idx != 0 { - if_ok!(write!(self.wr, ",")); + try!(write!(self.wr, ",")); } f(self); } @@ -418,17 +418,17 @@ impl<'a> serialize::Encoder for Encoder<'a> { } fn emit_struct(&mut self, _: &str, _: uint, f: |&mut Encoder<'a>|) { - if_ok!(write!(self.wr, r"\{")); + try!(write!(self.wr, r"\{")); f(self); - if_ok!(write!(self.wr, r"\}")); + try!(write!(self.wr, r"\}")); } fn emit_struct_field(&mut self, name: &str, idx: uint, f: |&mut Encoder<'a>|) { - if idx != 0 { if_ok!(write!(self.wr, ",")) } - if_ok!(write!(self.wr, "{}:", escape_str(name))); + if idx != 0 { try!(write!(self.wr, ",")) } + try!(write!(self.wr, "{}:", escape_str(name))); f(self); } @@ -454,31 +454,31 @@ impl<'a> serialize::Encoder for Encoder<'a> { fn emit_option_some(&mut self, f: |&mut Encoder<'a>|) { f(self); } fn emit_seq(&mut self, _len: uint, f: |&mut Encoder<'a>|) { - if_ok!(write!(self.wr, "[")); + try!(write!(self.wr, "[")); f(self); - if_ok!(write!(self.wr, "]")); + try!(write!(self.wr, "]")); } fn emit_seq_elt(&mut self, idx: uint, f: |&mut Encoder<'a>|) { if idx != 0 { - if_ok!(write!(self.wr, ",")); + try!(write!(self.wr, ",")); } f(self) } fn emit_map(&mut self, _len: uint, f: |&mut Encoder<'a>|) { - if_ok!(write!(self.wr, r"\{")); + try!(write!(self.wr, r"\{")); f(self); - if_ok!(write!(self.wr, r"\}")); + try!(write!(self.wr, r"\}")); } fn emit_map_elt_key(&mut self, idx: uint, f: |&mut Encoder<'a>|) { - if idx != 0 { if_ok!(write!(self.wr, ",")) } + if idx != 0 { try!(write!(self.wr, ",")) } f(self) } fn emit_map_elt_val(&mut self, _idx: uint, f: |&mut Encoder<'a>|) { - if_ok!(write!(self.wr, ":")); + try!(write!(self.wr, ":")); f(self) } } @@ -503,7 +503,7 @@ impl<'a> PrettyEncoder<'a> { } impl<'a> serialize::Encoder for PrettyEncoder<'a> { - fn emit_nil(&mut self) { if_ok!(write!(self.wr, "null")); } + fn emit_nil(&mut self) { try!(write!(self.wr, "null")); } fn emit_uint(&mut self, v: uint) { self.emit_f64(v as f64); } fn emit_u64(&mut self, v: u64) { self.emit_f64(v as f64); } @@ -519,20 +519,20 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> { fn emit_bool(&mut self, v: bool) { if v { - if_ok!(write!(self.wr, "true")); + try!(write!(self.wr, "true")); } else { - if_ok!(write!(self.wr, "false")); + try!(write!(self.wr, "false")); } } fn emit_f64(&mut self, v: f64) { - if_ok!(write!(self.wr, "{}", f64::to_str_digits(v, 6u))); + try!(write!(self.wr, "{}", f64::to_str_digits(v, 6u))); } fn emit_f32(&mut self, v: f32) { self.emit_f64(v as f64); } fn emit_char(&mut self, v: char) { self.emit_str(str::from_char(v)) } fn emit_str(&mut self, v: &str) { - if_ok!(write!(self.wr, "{}", escape_str(v))); + try!(write!(self.wr, "{}", escape_str(v))); } fn emit_enum(&mut self, _name: &str, f: |&mut PrettyEncoder<'a>|) { @@ -545,14 +545,14 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> { cnt: uint, f: |&mut PrettyEncoder<'a>|) { if cnt == 0 { - if_ok!(write!(self.wr, "{}", escape_str(name))); + try!(write!(self.wr, "{}", escape_str(name))); } else { self.indent += 2; - if_ok!(write!(self.wr, "[\n{}{},\n", spaces(self.indent), + try!(write!(self.wr, "[\n{}{},\n", spaces(self.indent), escape_str(name))); f(self); self.indent -= 2; - if_ok!(write!(self.wr, "\n{}]", spaces(self.indent))); + try!(write!(self.wr, "\n{}]", spaces(self.indent))); } } @@ -560,9 +560,9 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> { idx: uint, f: |&mut PrettyEncoder<'a>|) { if idx != 0 { - if_ok!(write!(self.wr, ",\n")); + try!(write!(self.wr, ",\n")); } - if_ok!(write!(self.wr, "{}", spaces(self.indent))); + try!(write!(self.wr, "{}", spaces(self.indent))); f(self) } @@ -587,13 +587,13 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> { len: uint, f: |&mut PrettyEncoder<'a>|) { if len == 0 { - if_ok!(write!(self.wr, "\\{\\}")); + try!(write!(self.wr, "\\{\\}")); } else { - if_ok!(write!(self.wr, "\\{")); + try!(write!(self.wr, "\\{")); self.indent += 2; f(self); self.indent -= 2; - if_ok!(write!(self.wr, "\n{}\\}", spaces(self.indent))); + try!(write!(self.wr, "\n{}\\}", spaces(self.indent))); } } @@ -602,11 +602,11 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> { idx: uint, f: |&mut PrettyEncoder<'a>|) { if idx == 0 { - if_ok!(write!(self.wr, "\n")); + try!(write!(self.wr, "\n")); } else { - if_ok!(write!(self.wr, ",\n")); + try!(write!(self.wr, ",\n")); } - if_ok!(write!(self.wr, "{}{}: ", spaces(self.indent), escape_str(name))); + try!(write!(self.wr, "{}{}: ", spaces(self.indent), escape_str(name))); f(self); } @@ -635,50 +635,50 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> { fn emit_seq(&mut self, len: uint, f: |&mut PrettyEncoder<'a>|) { if len == 0 { - if_ok!(write!(self.wr, "[]")); + try!(write!(self.wr, "[]")); } else { - if_ok!(write!(self.wr, "[")); + try!(write!(self.wr, "[")); self.indent += 2; f(self); self.indent -= 2; - if_ok!(write!(self.wr, "\n{}]", spaces(self.indent))); + try!(write!(self.wr, "\n{}]", spaces(self.indent))); } } fn emit_seq_elt(&mut self, idx: uint, f: |&mut PrettyEncoder<'a>|) { if idx == 0 { - if_ok!(write!(self.wr, "\n")); + try!(write!(self.wr, "\n")); } else { - if_ok!(write!(self.wr, ",\n")); + try!(write!(self.wr, ",\n")); } - if_ok!(write!(self.wr, "{}", spaces(self.indent))); + try!(write!(self.wr, "{}", spaces(self.indent))); f(self) } fn emit_map(&mut self, len: uint, f: |&mut PrettyEncoder<'a>|) { if len == 0 { - if_ok!(write!(self.wr, "\\{\\}")); + try!(write!(self.wr, "\\{\\}")); } else { - if_ok!(write!(self.wr, "\\{")); + try!(write!(self.wr, "\\{")); self.indent += 2; f(self); self.indent -= 2; - if_ok!(write!(self.wr, "\n{}\\}", spaces(self.indent))); + try!(write!(self.wr, "\n{}\\}", spaces(self.indent))); } } fn emit_map_elt_key(&mut self, idx: uint, f: |&mut PrettyEncoder<'a>|) { if idx == 0 { - if_ok!(write!(self.wr, "\n")); + try!(write!(self.wr, "\n")); } else { - if_ok!(write!(self.wr, ",\n")); + try!(write!(self.wr, ",\n")); } - if_ok!(write!(self.wr, "{}", spaces(self.indent))); + try!(write!(self.wr, "{}", spaces(self.indent))); f(self); } fn emit_map_elt_val(&mut self, _idx: uint, f: |&mut PrettyEncoder<'a>|) { - if_ok!(write!(self.wr, ": ")); + try!(write!(self.wr, ": ")); f(self); } } diff --git a/src/libextra/stats.rs b/src/libextra/stats.rs index 1687f5550b4..181ea6766c5 100644 --- a/src/libextra/stats.rs +++ b/src/libextra/stats.rs @@ -376,48 +376,48 @@ pub fn write_boxplot(w: &mut io::Writer, s: &Summary, let range_width = width_hint - overhead_width;; let char_step = range / (range_width as f64); - if_ok!(write!(w, "{} |", lostr)); + try!(write!(w, "{} |", lostr)); let mut c = 0; let mut v = lo; while c < range_width && v < s.min { - if_ok!(write!(w, " ")); + try!(write!(w, " ")); v += char_step; c += 1; } - if_ok!(write!(w, "[")); + try!(write!(w, "[")); c += 1; while c < range_width && v < q1 { - if_ok!(write!(w, "-")); + try!(write!(w, "-")); v += char_step; c += 1; } while c < range_width && v < q2 { - if_ok!(write!(w, "*")); + try!(write!(w, "*")); v += char_step; c += 1; } - if_ok!(write!(w, r"\#")); + try!(write!(w, r"\#")); c += 1; while c < range_width && v < q3 { - if_ok!(write!(w, "*")); + try!(write!(w, "*")); v += char_step; c += 1; } while c < range_width && v < s.max { - if_ok!(write!(w, "-")); + try!(write!(w, "-")); v += char_step; c += 1; } - if_ok!(write!(w, "]")); + try!(write!(w, "]")); while c < range_width { - if_ok!(write!(w, " ")); + try!(write!(w, " ")); v += char_step; c += 1; } - if_ok!(write!(w, "| {}", histr)); + try!(write!(w, "| {}", histr)); Ok(()) } diff --git a/src/libnative/io/pipe_unix.rs b/src/libnative/io/pipe_unix.rs index a6d75d93d67..64acdbf7f48 100644 --- a/src/libnative/io/pipe_unix.rs +++ b/src/libnative/io/pipe_unix.rs @@ -77,8 +77,8 @@ impl Drop for Inner { } fn connect(addr: &CString, ty: libc::c_int) -> IoResult { - let (addr, len) = if_ok!(addr_to_sockaddr_un(addr)); - let inner = Inner { fd: if_ok!(unix_socket(ty)) }; + let (addr, len) = try!(addr_to_sockaddr_un(addr)); + let inner = Inner { fd: try!(unix_socket(ty)) }; let addrp = &addr as *libc::sockaddr_storage; match retry(|| unsafe { libc::connect(inner.fd, addrp as *libc::sockaddr, @@ -90,8 +90,8 @@ fn connect(addr: &CString, ty: libc::c_int) -> IoResult { } fn bind(addr: &CString, ty: libc::c_int) -> IoResult { - let (addr, len) = if_ok!(addr_to_sockaddr_un(addr)); - let inner = Inner { fd: if_ok!(unix_socket(ty)) }; + let (addr, len) = try!(addr_to_sockaddr_un(addr)); + let inner = Inner { fd: try!(unix_socket(ty)) }; let addrp = &addr as *libc::sockaddr_storage; match unsafe { libc::bind(inner.fd, addrp as *libc::sockaddr, len as libc::socklen_t) @@ -198,7 +198,7 @@ impl UnixDatagram { } pub fn sendto(&mut self, buf: &[u8], dst: &CString) -> IoResult<()> { - let (dst, len) = if_ok!(addr_to_sockaddr_un(dst)); + let (dst, len) = try!(addr_to_sockaddr_un(dst)); let dstp = &dst as *libc::sockaddr_storage; let ret = retry(|| unsafe { libc::sendto(self.fd(), diff --git a/src/libnative/io/pipe_win32.rs b/src/libnative/io/pipe_win32.rs index 83731cc02a6..fc4fc0fa789 100644 --- a/src/libnative/io/pipe_win32.rs +++ b/src/libnative/io/pipe_win32.rs @@ -262,7 +262,7 @@ impl UnixStream { impl rtio::RtioPipe for UnixStream { fn read(&mut self, buf: &mut [u8]) -> IoResult { if self.read.is_none() { - self.read = Some(if_ok!(Event::new(true, false))); + self.read = Some(try!(Event::new(true, false))); } let mut bytes_read = 0; @@ -298,7 +298,7 @@ impl rtio::RtioPipe for UnixStream { fn write(&mut self, buf: &[u8]) -> IoResult<()> { if self.write.is_none() { - self.write = Some(if_ok!(Event::new(true, false))); + self.write = Some(try!(Event::new(true, false))); } let mut offset = 0; @@ -371,7 +371,7 @@ impl UnixListener { pub fn native_listen(self) -> IoResult { Ok(UnixAcceptor { listener: self, - event: if_ok!(Event::new(true, false)), + event: try!(Event::new(true, false)), }) } } diff --git a/src/librustc/back/archive.rs b/src/librustc/back/archive.rs index 406c3026614..d5d784cc2de 100644 --- a/src/librustc/back/archive.rs +++ b/src/librustc/back/archive.rs @@ -161,7 +161,7 @@ impl Archive { // We skip any files explicitly desired for skipping, and we also skip // all SYMDEF files as these are just magical placeholders which get // re-created when we make a new archive anyway. - let files = if_ok!(fs::readdir(loc.path())); + let files = try!(fs::readdir(loc.path())); let mut inputs = ~[]; for file in files.iter() { let filename = file.filename_str().unwrap(); @@ -170,7 +170,7 @@ impl Archive { let filename = format!("r-{}-{}", name, filename); let new_filename = file.with_filename(filename); - if_ok!(fs::rename(file, &new_filename)); + try!(fs::rename(file, &new_filename)); inputs.push(new_filename); } if inputs.len() == 0 { return Ok(()) } diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 5edf7a3251c..f2d82bfdf3c 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -521,9 +521,9 @@ fn write_out_deps(sess: Session, }) .collect() }; - let mut file = if_ok!(io::File::create(&deps_filename)); + let mut file = try!(io::File::create(&deps_filename)); for path in out_filenames.iter() { - if_ok!(write!(&mut file as &mut Writer, + try!(write!(&mut file as &mut Writer, "{}: {}\n\n", path.display(), files.connect(" "))); } Ok(()) @@ -575,21 +575,21 @@ impl pprust::PpAnn for IdentifiedAnnotation { fn post(&self, node: pprust::AnnNode) -> io::IoResult<()> { match node { pprust::NodeItem(s, item) => { - if_ok!(pp::space(&mut s.s)); - if_ok!(pprust::synth_comment(s, item.id.to_str())); + try!(pp::space(&mut s.s)); + try!(pprust::synth_comment(s, item.id.to_str())); } pprust::NodeBlock(s, blk) => { - if_ok!(pp::space(&mut s.s)); - if_ok!(pprust::synth_comment(s, ~"block " + blk.id.to_str())); + try!(pp::space(&mut s.s)); + try!(pprust::synth_comment(s, ~"block " + blk.id.to_str())); } pprust::NodeExpr(s, expr) => { - if_ok!(pp::space(&mut s.s)); - if_ok!(pprust::synth_comment(s, expr.id.to_str())); - if_ok!(pprust::pclose(s)); + try!(pp::space(&mut s.s)); + try!(pprust::synth_comment(s, expr.id.to_str())); + try!(pprust::pclose(s)); } pprust::NodePat(s, pat) => { - if_ok!(pp::space(&mut s.s)); - if_ok!(pprust::synth_comment(s, ~"pat " + pat.id.to_str())); + try!(pp::space(&mut s.s)); + try!(pprust::synth_comment(s, ~"pat " + pat.id.to_str())); } } Ok(()) @@ -611,12 +611,12 @@ impl pprust::PpAnn for TypedAnnotation { let tcx = self.analysis.ty_cx; match node { pprust::NodeExpr(s, expr) => { - if_ok!(pp::space(&mut s.s)); - if_ok!(pp::word(&mut s.s, "as")); - if_ok!(pp::space(&mut s.s)); - if_ok!(pp::word(&mut s.s, + try!(pp::space(&mut s.s)); + try!(pp::word(&mut s.s, "as")); + try!(pp::space(&mut s.s)); + try!(pp::word(&mut s.s, ppaux::ty_to_str(tcx, ty::expr_ty(tcx, expr)))); - if_ok!(pprust::pclose(s)); + try!(pprust::pclose(s)); } _ => () } diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 44aa9c84101..58917eabb64 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -1088,11 +1088,11 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::Attribute] { fn list_crate_attributes(md: ebml::Doc, hash: &str, out: &mut io::Writer) -> io::IoResult<()> { - if_ok!(write!(out, "=Crate Attributes ({})=\n", hash)); + try!(write!(out, "=Crate Attributes ({})=\n", hash)); let r = get_attributes(md); for attr in r.iter() { - if_ok!(write!(out, "{}\n", pprust::attribute_to_str(attr))); + try!(write!(out, "{}\n", pprust::attribute_to_str(attr))); } write!(out, "\n\n") @@ -1131,11 +1131,11 @@ pub fn get_crate_deps(data: &[u8]) -> ~[CrateDep] { } fn list_crate_deps(data: &[u8], out: &mut io::Writer) -> io::IoResult<()> { - if_ok!(write!(out, "=External Dependencies=\n")); + try!(write!(out, "=External Dependencies=\n")); let r = get_crate_deps(data); for dep in r.iter() { - if_ok!(write!(out, + try!(write!(out, "{} {}-{}-{}\n", dep.cnum, token::get_ident(dep.name), @@ -1143,7 +1143,7 @@ fn list_crate_deps(data: &[u8], out: &mut io::Writer) -> io::IoResult<()> { dep.vers)); } - if_ok!(write!(out, "\n")); + try!(write!(out, "\n")); Ok(()) } @@ -1164,7 +1164,7 @@ pub fn get_crate_vers(data: &[u8]) -> ~str { pub fn list_crate_metadata(bytes: &[u8], out: &mut io::Writer) -> io::IoResult<()> { let hash = get_crate_hash(bytes); let md = reader::Doc(bytes); - if_ok!(list_crate_attributes(md, hash, out)); + try!(list_crate_attributes(md, hash, out)); list_crate_deps(bytes, out) } diff --git a/src/librustc/middle/dataflow.rs b/src/librustc/middle/dataflow.rs index 60d83d7559e..e8e05b0979a 100644 --- a/src/librustc/middle/dataflow.rs +++ b/src/librustc/middle/dataflow.rs @@ -113,8 +113,8 @@ impl pprust::PpAnn for DataFlowContext { let comment_str = format!("id {}: {}{}{}", id, entry_str, gens_str, kills_str); - if_ok!(pprust::synth_comment(ps, comment_str)); - if_ok!(pp::space(&mut ps.s)); + try!(pprust::synth_comment(ps, comment_str)); + try!(pp::space(&mut ps.s)); } Ok(()) } @@ -351,10 +351,10 @@ impl DataFlowContext { fn pretty_print_to(&self, wr: ~io::Writer, blk: &ast::Block) -> io::IoResult<()> { let mut ps = pprust::rust_printer_annotated(wr, self); - if_ok!(pprust::cbox(&mut ps, pprust::indent_unit)); - if_ok!(pprust::ibox(&mut ps, 0u)); - if_ok!(pprust::print_block(&mut ps, blk)); - if_ok!(pp::eof(&mut ps.s)); + try!(pprust::cbox(&mut ps, pprust::indent_unit)); + try!(pprust::ibox(&mut ps, 0u)); + try!(pprust::print_block(&mut ps, blk)); + try!(pp::eof(&mut ps.s)); Ok(()) } } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 70b5aab4c93..efe88b7847f 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -740,7 +740,7 @@ impl Liveness { for var_idx in range(0u, self.ir.num_vars.get()) { let idx = node_base_idx + var_idx; if test(idx).is_valid() { - if_ok!(write!(wr, " {}", Variable(var_idx).to_str())); + try!(write!(wr, " {}", Variable(var_idx).to_str())); } } Ok(()) diff --git a/src/librustdoc/html/escape.rs b/src/librustdoc/html/escape.rs index 153de66363b..bb6b1eeaedd 100644 --- a/src/librustdoc/html/escape.rs +++ b/src/librustdoc/html/escape.rs @@ -29,7 +29,7 @@ impl<'a> fmt::Show for Escape<'a> { for (i, ch) in s.bytes().enumerate() { match ch as char { '<' | '>' | '&' | '\'' | '"' => { - if_ok!(fmt.buf.write(pile_o_bits.slice(last, i).as_bytes())); + try!(fmt.buf.write(pile_o_bits.slice(last, i).as_bytes())); let s = match ch as char { '>' => ">", '<' => "<", @@ -38,7 +38,7 @@ impl<'a> fmt::Show for Escape<'a> { '"' => """, _ => unreachable!() }; - if_ok!(fmt.buf.write(s.as_bytes())); + try!(fmt.buf.write(s.as_bytes())); last = i + 1; } _ => {} @@ -46,7 +46,7 @@ impl<'a> fmt::Show for Escape<'a> { } if last < s.len() { - if_ok!(fmt.buf.write(pile_o_bits.slice_from(last).as_bytes())); + try!(fmt.buf.write(pile_o_bits.slice_from(last).as_bytes())); } Ok(()) } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index c08f2ca382d..a8b7e374a6a 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -50,46 +50,46 @@ impl PuritySpace { impl fmt::Show for clean::Generics { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if self.lifetimes.len() == 0 && self.type_params.len() == 0 { return Ok(()) } - if_ok!(f.buf.write("<".as_bytes())); + try!(f.buf.write("<".as_bytes())); for (i, life) in self.lifetimes.iter().enumerate() { if i > 0 { - if_ok!(f.buf.write(", ".as_bytes())); + try!(f.buf.write(", ".as_bytes())); } - if_ok!(write!(f.buf, "{}", *life)); + try!(write!(f.buf, "{}", *life)); } if self.type_params.len() > 0 { if self.lifetimes.len() > 0 { - if_ok!(f.buf.write(", ".as_bytes())); + try!(f.buf.write(", ".as_bytes())); } for (i, tp) in self.type_params.iter().enumerate() { if i > 0 { - if_ok!(f.buf.write(", ".as_bytes())) + try!(f.buf.write(", ".as_bytes())) } - if_ok!(f.buf.write(tp.name.as_bytes())); + try!(f.buf.write(tp.name.as_bytes())); if tp.bounds.len() > 0 { - if_ok!(f.buf.write(": ".as_bytes())); + try!(f.buf.write(": ".as_bytes())); for (i, bound) in tp.bounds.iter().enumerate() { if i > 0 { - if_ok!(f.buf.write(" + ".as_bytes())); + try!(f.buf.write(" + ".as_bytes())); } - if_ok!(write!(f.buf, "{}", *bound)); + try!(write!(f.buf, "{}", *bound)); } } } } - if_ok!(f.buf.write(">".as_bytes())); + try!(f.buf.write(">".as_bytes())); Ok(()) } } impl fmt::Show for clean::Lifetime { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if_ok!(f.buf.write("'".as_bytes())); - if_ok!(f.buf.write(self.get_ref().as_bytes())); + try!(f.buf.write("'".as_bytes())); + try!(f.buf.write(self.get_ref().as_bytes())); Ok(()) } } @@ -110,32 +110,32 @@ impl fmt::Show for clean::TyParamBound { impl fmt::Show for clean::Path { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if self.global { - if_ok!(f.buf.write("::".as_bytes())) + try!(f.buf.write("::".as_bytes())) } for (i, seg) in self.segments.iter().enumerate() { if i > 0 { - if_ok!(f.buf.write("::".as_bytes())) + try!(f.buf.write("::".as_bytes())) } - if_ok!(f.buf.write(seg.name.as_bytes())); + try!(f.buf.write(seg.name.as_bytes())); if seg.lifetimes.len() > 0 || seg.types.len() > 0 { - if_ok!(f.buf.write("<".as_bytes())); + try!(f.buf.write("<".as_bytes())); let mut comma = false; for lifetime in seg.lifetimes.iter() { if comma { - if_ok!(f.buf.write(", ".as_bytes())); + try!(f.buf.write(", ".as_bytes())); } comma = true; - if_ok!(write!(f.buf, "{}", *lifetime)); + try!(write!(f.buf, "{}", *lifetime)); } for ty in seg.types.iter() { if comma { - if_ok!(f.buf.write(", ".as_bytes())); + try!(f.buf.write(", ".as_bytes())); } comma = true; - if_ok!(write!(f.buf, "{}", *ty)); + try!(write!(f.buf, "{}", *ty)); } - if_ok!(f.buf.write(">".as_bytes())); + try!(f.buf.write(">".as_bytes())); } } Ok(()) @@ -222,11 +222,11 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool, let mut root = root; for seg in path.segments.slice_to(amt).iter() { if "super" == seg.name || "self" == seg.name { - if_ok!(write!(w, "{}::", seg.name)); + try!(write!(w, "{}::", seg.name)); } else { root.push_str(seg.name); root.push_str("/"); - if_ok!(write!(w, "{}::", root, seg.name)); @@ -235,7 +235,7 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool, } None => { for seg in path.segments.slice_to(amt).iter() { - if_ok!(write!(w, "{}::", seg.name)); + try!(write!(w, "{}::", seg.name)); } } } @@ -263,15 +263,15 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool, } } - if_ok!(write!(w, "{}", + try!(write!(w, "{}", shortty, url, fqp.connect("::"), last.name)); } _ => { - if_ok!(write!(w, "{}", last.name)); + try!(write!(w, "{}", last.name)); } } - if_ok!(write!(w, "{}", generics)); + try!(write!(w, "{}", generics)); Ok(()) }) }) @@ -282,14 +282,14 @@ fn typarams(w: &mut io::Writer, typarams: &Option<~[clean::TyParamBound]>) -> fmt::Result { match *typarams { Some(ref params) => { - if_ok!(write!(w, "<")); + try!(write!(w, "<")); for (i, param) in params.iter().enumerate() { if i > 0 { - if_ok!(write!(w, ", ")); + try!(write!(w, ", ")); } - if_ok!(write!(w, "{}", *param)); + try!(write!(w, "{}", *param)); } - if_ok!(write!(w, ">")); + try!(write!(w, ">")); Ok(()) } None => Ok(()) @@ -306,12 +306,12 @@ impl fmt::Show for clean::Type { }) } clean::ResolvedPath{id, typarams: ref tp, path: ref path} => { - if_ok!(resolved_path(f.buf, id, path, false)); + try!(resolved_path(f.buf, id, path, false)); typarams(f.buf, tp) } clean::ExternalPath{path: ref path, typarams: ref tp, fqn: ref fqn, kind, krate} => { - if_ok!(external_path(f.buf, path, false, fqn.as_slice(), kind, + try!(external_path(f.buf, path, false, fqn.as_slice(), kind, krate)) typarams(f.buf, tp) } @@ -364,12 +364,12 @@ impl fmt::Show for clean::Type { decl.decl) } clean::Tuple(ref typs) => { - if_ok!(f.buf.write("(".as_bytes())); + try!(f.buf.write("(".as_bytes())); for (i, typ) in typs.iter().enumerate() { if i > 0 { - if_ok!(f.buf.write(", ".as_bytes())) + try!(f.buf.write(", ".as_bytes())) } - if_ok!(write!(f.buf, "{}", *typ)); + try!(write!(f.buf, "{}", *typ)); } f.buf.write(")".as_bytes()) } @@ -407,11 +407,11 @@ impl fmt::Show for clean::Type { impl fmt::Show for clean::Arguments { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { for (i, input) in self.values.iter().enumerate() { - if i > 0 { if_ok!(write!(f.buf, ", ")); } + if i > 0 { try!(write!(f.buf, ", ")); } if input.name.len() > 0 { - if_ok!(write!(f.buf, "{}: ", input.name)); + try!(write!(f.buf, "{}: ", input.name)); } - if_ok!(write!(f.buf, "{}", input.type_)); + try!(write!(f.buf, "{}", input.type_)); } Ok(()) } @@ -495,12 +495,12 @@ impl fmt::Show for clean::ViewPath { write!(f.buf, "use {}::*;", *src) } clean::ImportList(ref src, ref names) => { - if_ok!(write!(f.buf, "use {}::\\{", *src)); + try!(write!(f.buf, "use {}::\\{", *src)); for (i, n) in names.iter().enumerate() { if i > 0 { - if_ok!(write!(f.buf, ", ")); + try!(write!(f.buf, ", ")); } - if_ok!(write!(f.buf, "{}", *n)); + try!(write!(f.buf, "{}", *n)); } write!(f.buf, "\\};") } @@ -518,9 +518,9 @@ impl fmt::Show for clean::ImportSource { _ => { for (i, seg) in self.path.segments.iter().enumerate() { if i > 0 { - if_ok!(write!(f.buf, "::")) + try!(write!(f.buf, "::")) } - if_ok!(write!(f.buf, "{}", seg.name)); + try!(write!(f.buf, "{}", seg.name)); } Ok(()) } diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 649d5f592c5..0f017a04da3 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -209,7 +209,7 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> { }, include_sources: true, }; - if_ok!(mkdir(&cx.dst)); + try!(mkdir(&cx.dst)); match krate.module.as_ref().map(|m| m.doc_list().unwrap_or(&[])) { Some(attrs) => { @@ -254,12 +254,12 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> { // Add all the static files let mut dst = cx.dst.join(krate.name.as_slice()); - if_ok!(mkdir(&dst)); - if_ok!(write(dst.join("jquery.js"), + try!(mkdir(&dst)); + try!(write(dst.join("jquery.js"), include_str!("static/jquery-2.1.0.min.js"))); - if_ok!(write(dst.join("main.js"), include_str!("static/main.js"))); - if_ok!(write(dst.join("main.css"), include_str!("static/main.css"))); - if_ok!(write(dst.join("normalize.css"), + try!(write(dst.join("main.js"), include_str!("static/main.js"))); + try!(write(dst.join("main.css"), include_str!("static/main.css"))); + try!(write(dst.join("normalize.css"), include_str!("static/normalize.css"))); // Publish the search index @@ -267,42 +267,42 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> { dst.push("search-index.js"); let mut w = BufferedWriter::new(File::create(&dst).unwrap()); let w = &mut w as &mut Writer; - if_ok!(write!(w, "var searchIndex = [")); + try!(write!(w, "var searchIndex = [")); for (i, item) in cache.search_index.iter().enumerate() { if i > 0 { - if_ok!(write!(w, ",")); + try!(write!(w, ",")); } - if_ok!(write!(w, "\\{ty:\"{}\",name:\"{}\",path:\"{}\",desc:{}", + try!(write!(w, "\\{ty:\"{}\",name:\"{}\",path:\"{}\",desc:{}", item.ty, item.name, item.path, item.desc.to_json().to_str())); match item.parent { Some(id) => { - if_ok!(write!(w, ",parent:'{}'", id)); + try!(write!(w, ",parent:'{}'", id)); } None => {} } - if_ok!(write!(w, "\\}")); + try!(write!(w, "\\}")); } - if_ok!(write!(w, "];")); - if_ok!(write!(w, "var allPaths = \\{")); + try!(write!(w, "];")); + try!(write!(w, "var allPaths = \\{")); for (i, (&id, &(ref fqp, short))) in cache.paths.iter().enumerate() { if i > 0 { - if_ok!(write!(w, ",")); + try!(write!(w, ",")); } - if_ok!(write!(w, "'{}':\\{type:'{}',name:'{}'\\}", + try!(write!(w, "'{}':\\{type:'{}',name:'{}'\\}", id, short, *fqp.last().unwrap())); } - if_ok!(write!(w, "\\};")); - if_ok!(w.flush()); + try!(write!(w, "\\};")); + try!(w.flush()); } // Render all source files (this may turn into a giant no-op) { info!("emitting source files"); let dst = cx.dst.join("src"); - if_ok!(mkdir(&dst)); + try!(mkdir(&dst)); let dst = dst.join(krate.name.as_slice()); - if_ok!(mkdir(&dst)); + try!(mkdir(&dst)); let mut folder = SourceCollector { dst: dst, seen: HashSet::new(), @@ -442,7 +442,7 @@ impl<'a> SourceCollector<'a> { }); cur.push(p.filename().expect("source has no filename") + bytes!(".html")); - let mut w = BufferedWriter::new(if_ok!(File::create(&cur))); + let mut w = BufferedWriter::new(try!(File::create(&cur))); let title = format!("{} -- source", cur.filename_display()); let page = layout::Page { @@ -450,9 +450,9 @@ impl<'a> SourceCollector<'a> { ty: "source", root_path: root_path, }; - if_ok!(layout::render(&mut w as &mut Writer, &self.cx.layout, + try!(layout::render(&mut w as &mut Writer, &self.cx.layout, &page, &(""), &Source(contents.as_slice()))); - if_ok!(w.flush()); + try!(w.flush()); return Ok(()); } } @@ -714,7 +714,7 @@ impl Context { let mut work = ~[(self, item)]; loop { match work.pop() { - Some((mut cx, item)) => if_ok!(cx.item(item, |cx, item| { + Some((mut cx, item)) => try!(cx.item(item, |cx, item| { work.push((cx.clone(), item)); })), None => break, @@ -753,7 +753,7 @@ impl Context { // of the pain by using a buffered writer instead of invoking the // write sycall all the time. let mut writer = BufferedWriter::new(w); - if_ok!(layout::render(&mut writer as &mut Writer, &cx.layout, &page, + try!(layout::render(&mut writer as &mut Writer, &cx.layout, &page, &Sidebar{ cx: cx, item: it }, &Item{ cx: cx, item: it })); writer.flush() @@ -768,8 +768,8 @@ impl Context { self.recurse(name, |this| { let item = item.take_unwrap(); let dst = this.dst.join("index.html"); - let dst = if_ok!(File::create(&dst)); - if_ok!(render(dst, this, &item, false)); + let dst = try!(File::create(&dst)); + try!(render(dst, this, &item, false)); let m = match item.inner { clean::ModuleItem(m) => m, @@ -787,7 +787,7 @@ impl Context { // pages dedicated to them. _ if item.name.is_some() => { let dst = self.dst.join(item_path(&item)); - let dst = if_ok!(File::create(&dst)); + let dst = try!(File::create(&dst)); render(dst, self, &item, true) } @@ -829,7 +829,7 @@ impl<'a> fmt::Show for Item<'a> { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { match attr::find_stability(self.item.attrs.iter()) { Some(ref stability) => { - if_ok!(write!(fmt.buf, + try!(write!(fmt.buf, "{lvl}", lvl = stability.level.to_str(), reason = match stability.text { @@ -850,7 +850,7 @@ impl<'a> fmt::Show for Item<'a> { } else { format!("{}-{}", self.item.source.loline, self.item.source.hiline) }; - if_ok!(write!(fmt.buf, + try!(write!(fmt.buf, "\ [src]", @@ -861,13 +861,13 @@ impl<'a> fmt::Show for Item<'a> { } // Write the breadcrumb trail header for the top - if_ok!(write!(fmt.buf, "

")); + try!(write!(fmt.buf, "

")); match self.item.inner { - clean::ModuleItem(..) => if_ok!(write!(fmt.buf, "Module ")), - clean::FunctionItem(..) => if_ok!(write!(fmt.buf, "Function ")), - clean::TraitItem(..) => if_ok!(write!(fmt.buf, "Trait ")), - clean::StructItem(..) => if_ok!(write!(fmt.buf, "Struct ")), - clean::EnumItem(..) => if_ok!(write!(fmt.buf, "Enum ")), + clean::ModuleItem(..) => try!(write!(fmt.buf, "Module ")), + clean::FunctionItem(..) => try!(write!(fmt.buf, "Function ")), + clean::TraitItem(..) => try!(write!(fmt.buf, "Trait ")), + clean::StructItem(..) => try!(write!(fmt.buf, "Struct ")), + clean::EnumItem(..) => try!(write!(fmt.buf, "Enum ")), _ => {} } let cur = self.cx.current.as_slice(); @@ -877,10 +877,10 @@ impl<'a> fmt::Show for Item<'a> { for _ in range(0, cur.len() - i - 1) { trail.push_str("../"); } - if_ok!(write!(fmt.buf, "{}::", + try!(write!(fmt.buf, "{}::", trail, component.as_slice())); } - if_ok!(write!(fmt.buf, "{}

", + try!(write!(fmt.buf, "{}", shortty(self.item), self.item.name.get_ref().as_slice())); match self.item.inner { @@ -932,7 +932,7 @@ fn shorter<'a>(s: Option<&'a str>) -> &'a str { fn document(w: &mut Writer, item: &clean::Item) -> fmt::Result { match item.doc_value() { Some(s) => { - if_ok!(write!(w, "
{}
", Markdown(s))); + try!(write!(w, "
{}
", Markdown(s))); } None => {} } @@ -941,7 +941,7 @@ fn document(w: &mut Writer, item: &clean::Item) -> fmt::Result { fn item_module(w: &mut Writer, cx: &Context, item: &clean::Item, items: &[clean::Item]) -> fmt::Result { - if_ok!(document(w, item)); + try!(document(w, item)); debug!("{:?}", items); let mut indices = vec::from_fn(items.len(), |i| i); @@ -994,10 +994,10 @@ fn item_module(w: &mut Writer, cx: &Context, let myty = shortty(myitem); if myty != curty { if curty != "" { - if_ok!(write!(w, "")); + try!(write!(w, "")); } curty = myty; - if_ok!(write!(w, "

{}

\n", match myitem.inner { + try!(write!(w, "

{}

\n
", match myitem.inner { clean::ModuleItem(..) => "Modules", clean::StructItem(..) => "Structs", clean::EnumItem(..) => "Enums", @@ -1024,15 +1024,15 @@ fn item_module(w: &mut Writer, cx: &Context, fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let Initializer(s) = *self; if s.len() == 0 { return Ok(()); } - if_ok!(write!(f.buf, " = ")); + try!(write!(f.buf, " = ")); let tag = if s.contains("\n") { "pre" } else { "code" }; - if_ok!(write!(f.buf, "<{tag}>{}", + try!(write!(f.buf, "<{tag}>{}", s.as_slice(), tag=tag)); Ok(()) } } - if_ok!(write!(w, " + try!(write!(w, " @@ -1048,19 +1048,19 @@ fn item_module(w: &mut Writer, cx: &Context, clean::ViewItemItem(ref item) => { match item.inner { clean::ExternMod(ref name, ref src, _) => { - if_ok!(write!(w, "")); + try!(write!(w, ";")); } clean::Import(ref imports) => { for import in imports.iter() { - if_ok!(write!(w, "", + try!(write!(w, "", VisSpace(myitem.visibility), *import)); } @@ -1071,7 +1071,7 @@ fn item_module(w: &mut Writer, cx: &Context, _ => { if myitem.name.is_none() { continue } - if_ok!(write!(w, " + try!(write!(w, " @@ -1091,7 +1091,7 @@ fn item_module(w: &mut Writer, cx: &Context, fn item_function(w: &mut Writer, it: &clean::Item, f: &clean::Function) -> fmt::Result { - if_ok!(write!(w, "
{vis}{purity}fn {name}{generics}{decl}
", + try!(write!(w, "
{vis}{purity}fn {name}{generics}{decl}
", vis = VisSpace(it.visibility), purity = PuritySpace(f.purity), name = it.name.get_ref().as_slice(), @@ -1112,7 +1112,7 @@ fn item_trait(w: &mut Writer, it: &clean::Item, } // Output the trait definition - if_ok!(write!(w, "
{}trait {}{}{} ",
+    try!(write!(w, "
{}trait {}{}{} ",
                   VisSpace(it.visibility),
                   it.name.get_ref().as_slice(),
                   t.generics,
@@ -1121,81 +1121,81 @@ fn item_trait(w: &mut Writer, it: &clean::Item,
     let provided = t.methods.iter().filter(|m| !m.is_req()).to_owned_vec();
 
     if t.methods.len() == 0 {
-        if_ok!(write!(w, "\\{ \\}"));
+        try!(write!(w, "\\{ \\}"));
     } else {
-        if_ok!(write!(w, "\\{\n"));
+        try!(write!(w, "\\{\n"));
         for m in required.iter() {
-            if_ok!(write!(w, "    "));
-            if_ok!(render_method(w, m.item()));
-            if_ok!(write!(w, ";\n"));
+            try!(write!(w, "    "));
+            try!(render_method(w, m.item()));
+            try!(write!(w, ";\n"));
         }
         if required.len() > 0 && provided.len() > 0 {
-            if_ok!(w.write("\n".as_bytes()));
+            try!(w.write("\n".as_bytes()));
         }
         for m in provided.iter() {
-            if_ok!(write!(w, "    "));
-            if_ok!(render_method(w, m.item()));
-            if_ok!(write!(w, " \\{ ... \\}\n"));
+            try!(write!(w, "    "));
+            try!(render_method(w, m.item()));
+            try!(write!(w, " \\{ ... \\}\n"));
         }
-        if_ok!(write!(w, "\\}"));
+        try!(write!(w, "\\}"));
     }
-    if_ok!(write!(w, "
")); + try!(write!(w, "
")); // Trait documentation - if_ok!(document(w, it)); + try!(document(w, it)); fn meth(w: &mut Writer, m: &clean::TraitMethod) -> fmt::Result { - if_ok!(write!(w, "

", + try!(write!(w, "

", shortty(m.item()), *m.item().name.get_ref())); - if_ok!(render_method(w, m.item())); - if_ok!(write!(w, "

")); - if_ok!(document(w, m.item())); + try!(render_method(w, m.item())); + try!(write!(w, "

")); + try!(document(w, m.item())); Ok(()) } // Output the documentation for each function individually if required.len() > 0 { - if_ok!(write!(w, " + try!(write!(w, "

Required Methods

")); for m in required.iter() { - if_ok!(meth(w, *m)); + try!(meth(w, *m)); } - if_ok!(write!(w, "
")); + try!(write!(w, "")); } if provided.len() > 0 { - if_ok!(write!(w, " + try!(write!(w, "

Provided Methods

")); for m in provided.iter() { - if_ok!(meth(w, *m)); + try!(meth(w, *m)); } - if_ok!(write!(w, "
")); + try!(write!(w, "")); } local_data::get(cache_key, |cache| { let cache = cache.unwrap().get(); match cache.implementors.find(&it.id) { Some(implementors) => { - if_ok!(write!(w, " + try!(write!(w, "

Implementors

    ")); for i in implementors.iter() { match *i { PathType(ref ty) => { - if_ok!(write!(w, "
  • {}
  • ", *ty)); + try!(write!(w, "
  • {}
  • ", *ty)); } OtherType(ref generics, ref trait_, ref for_) => { - if_ok!(write!(w, "
  • impl{} {} for {}
  • ", + try!(write!(w, "
  • impl{} {} for {}
  • ", *generics, *trait_, *for_)); } } } - if_ok!(write!(w, "
")); + try!(write!(w, "")); } None => {} } @@ -1231,23 +1231,23 @@ fn render_method(w: &mut Writer, meth: &clean::Item) -> fmt::Result { fn item_struct(w: &mut Writer, it: &clean::Item, s: &clean::Struct) -> fmt::Result { - if_ok!(write!(w, "
"));
-    if_ok!(render_struct(w, it, Some(&s.generics), s.struct_type, s.fields,
+    try!(write!(w, "
"));
+    try!(render_struct(w, it, Some(&s.generics), s.struct_type, s.fields,
                          s.fields_stripped, "", true));
-    if_ok!(write!(w, "
")); + try!(write!(w, "
")); - if_ok!(document(w, it)); + try!(document(w, it)); match s.struct_type { doctree::Plain if s.fields.len() > 0 => { - if_ok!(write!(w, "

Fields

\n
{}static {}: {}{} {} 
extern crate {}", + try!(write!(w, "
extern crate {}", name.as_slice())); match *src { - Some(ref src) => if_ok!(write!(w, " = \"{}\"", + Some(ref src) => try!(write!(w, " = \"{}\"", src.as_slice())), None => {} } - if_ok!(write!(w, ";
{}{}
{}{}
{}
")); + try!(write!(w, "

Fields

\n
")); for field in s.fields.iter() { - if_ok!(write!(w, "")); + try!(document(w, field)); + try!(write!(w, "")); } - if_ok!(write!(w, "
\ + try!(write!(w, "
\ {name}", name = field.name.get_ref().as_slice())); - if_ok!(document(w, field)); - if_ok!(write!(w, "
")); + try!(write!(w, "")); } _ => {} } @@ -1255,33 +1255,33 @@ fn item_struct(w: &mut Writer, it: &clean::Item, } fn item_enum(w: &mut Writer, it: &clean::Item, e: &clean::Enum) -> fmt::Result { - if_ok!(write!(w, "
{}enum {}{}",
+    try!(write!(w, "
{}enum {}{}",
                   VisSpace(it.visibility),
                   it.name.get_ref().as_slice(),
                   e.generics));
     if e.variants.len() == 0 && !e.variants_stripped {
-        if_ok!(write!(w, " \\{\\}"));
+        try!(write!(w, " \\{\\}"));
     } else {
-        if_ok!(write!(w, " \\{\n"));
+        try!(write!(w, " \\{\n"));
         for v in e.variants.iter() {
-            if_ok!(write!(w, "    "));
+            try!(write!(w, "    "));
             let name = v.name.get_ref().as_slice();
             match v.inner {
                 clean::VariantItem(ref var) => {
                     match var.kind {
-                        clean::CLikeVariant => if_ok!(write!(w, "{}", name)),
+                        clean::CLikeVariant => try!(write!(w, "{}", name)),
                         clean::TupleVariant(ref tys) => {
-                            if_ok!(write!(w, "{}(", name));
+                            try!(write!(w, "{}(", name));
                             for (i, ty) in tys.iter().enumerate() {
                                 if i > 0 {
-                                    if_ok!(write!(w, ", "))
+                                    try!(write!(w, ", "))
                                 }
-                                if_ok!(write!(w, "{}", *ty));
+                                try!(write!(w, "{}", *ty));
                             }
-                            if_ok!(write!(w, ")"));
+                            try!(write!(w, ")"));
                         }
                         clean::StructVariant(ref s) => {
-                            if_ok!(render_struct(w, v, None, s.struct_type,
+                            try!(render_struct(w, v, None, s.struct_type,
                                                  s.fields, s.fields_stripped,
                                                  "    ", false));
                         }
@@ -1289,51 +1289,51 @@ fn item_enum(w: &mut Writer, it: &clean::Item, e: &clean::Enum) -> fmt::Result {
                 }
                 _ => unreachable!()
             }
-            if_ok!(write!(w, ",\n"));
+            try!(write!(w, ",\n"));
         }
 
         if e.variants_stripped {
-            if_ok!(write!(w, "    // some variants omitted\n"));
+            try!(write!(w, "    // some variants omitted\n"));
         }
-        if_ok!(write!(w, "\\}"));
+        try!(write!(w, "\\}"));
     }
-    if_ok!(write!(w, "
")); + try!(write!(w, "
")); - if_ok!(document(w, it)); + try!(document(w, it)); if e.variants.len() > 0 { - if_ok!(write!(w, "

Variants

\n")); + try!(write!(w, "

Variants

\n
")); for variant in e.variants.iter() { - if_ok!(write!(w, "
{name}", + try!(write!(w, "
{name}", name = variant.name.get_ref().as_slice())); - if_ok!(document(w, variant)); + try!(document(w, variant)); match variant.inner { clean::VariantItem(ref var) => { match var.kind { clean::StructVariant(ref s) => { - if_ok!(write!(w, "

Fields

\n + try!(write!(w, "

Fields

\n ")); for field in s.fields.iter() { - if_ok!(write!(w, "")); + try!(document(w, field)); + try!(write!(w, "")); } - if_ok!(write!(w, "
\ {f}", v = variant.name.get_ref().as_slice(), f = field.name.get_ref().as_slice())); - if_ok!(document(w, field)); - if_ok!(write!(w, "
")); + try!(write!(w, "
")); } _ => () } } _ => () } - if_ok!(write!(w, "")); + try!(write!(w, "")); } - if_ok!(write!(w, "")); + try!(write!(w, "")); } - if_ok!(render_methods(w, it)); + try!(render_methods(w, it)); Ok(()) } @@ -1344,21 +1344,21 @@ fn render_struct(w: &mut Writer, it: &clean::Item, fields_stripped: bool, tab: &str, structhead: bool) -> fmt::Result { - if_ok!(write!(w, "{}{}{}", + try!(write!(w, "{}{}{}", VisSpace(it.visibility), if structhead {"struct "} else {""}, it.name.get_ref().as_slice())); match g { - Some(g) => if_ok!(write!(w, "{}", *g)), + Some(g) => try!(write!(w, "{}", *g)), None => {} } match ty { doctree::Plain => { - if_ok!(write!(w, " \\{\n{}", tab)); + try!(write!(w, " \\{\n{}", tab)); for field in fields.iter() { match field.inner { clean::StructFieldItem(ref ty) => { - if_ok!(write!(w, " {}{}: {},\n{}", + try!(write!(w, " {}{}: {},\n{}", VisSpace(field.visibility), field.name.get_ref().as_slice(), ty.type_, @@ -1369,27 +1369,27 @@ fn render_struct(w: &mut Writer, it: &clean::Item, } if fields_stripped { - if_ok!(write!(w, " // some fields omitted\n{}", tab)); + try!(write!(w, " // some fields omitted\n{}", tab)); } - if_ok!(write!(w, "\\}")); + try!(write!(w, "\\}")); } doctree::Tuple | doctree::Newtype => { - if_ok!(write!(w, "(")); + try!(write!(w, "(")); for (i, field) in fields.iter().enumerate() { if i > 0 { - if_ok!(write!(w, ", ")); + try!(write!(w, ", ")); } match field.inner { clean::StructFieldItem(ref field) => { - if_ok!(write!(w, "{}", field.type_)); + try!(write!(w, "{}", field.type_)); } _ => unreachable!() } } - if_ok!(write!(w, ");")); + try!(write!(w, ");")); } doctree::Unit => { - if_ok!(write!(w, ";")); + try!(write!(w, ";")); } } Ok(()) @@ -1410,16 +1410,16 @@ fn render_methods(w: &mut Writer, it: &clean::Item) -> fmt::Result { let traits = traits.to_owned_vec(); if non_trait.len() > 0 { - if_ok!(write!(w, "

Methods

")); + try!(write!(w, "

Methods

")); for &(ref i, ref dox) in non_trait.move_iter() { - if_ok!(render_impl(w, i, dox)); + try!(render_impl(w, i, dox)); } } if traits.len() > 0 { - if_ok!(write!(w, "

Trait \ + try!(write!(w, "

Trait \ Implementations

")); for &(ref i, ref dox) in traits.move_iter() { - if_ok!(render_impl(w, i, dox)); + try!(render_impl(w, i, dox)); } } } @@ -1431,10 +1431,10 @@ fn render_methods(w: &mut Writer, it: &clean::Item) -> fmt::Result { fn render_impl(w: &mut Writer, i: &clean::Impl, dox: &Option<~str>) -> fmt::Result { - if_ok!(write!(w, "

impl{} ", i.generics)); + try!(write!(w, "

impl{} ", i.generics)); let trait_id = match i.trait_ { Some(ref ty) => { - if_ok!(write!(w, "{} for ", *ty)); + try!(write!(w, "{} for ", *ty)); match *ty { clean::ResolvedPath { id, .. } => Some(id), _ => None, @@ -1442,32 +1442,32 @@ fn render_impl(w: &mut Writer, i: &clean::Impl, } None => None }; - if_ok!(write!(w, "{}

", i.for_)); + try!(write!(w, "{}

", i.for_)); match *dox { Some(ref dox) => { - if_ok!(write!(w, "
{}
", + try!(write!(w, "
{}
", Markdown(dox.as_slice()))); } None => {} } fn docmeth(w: &mut Writer, item: &clean::Item) -> io::IoResult { - if_ok!(write!(w, "

", + try!(write!(w, "

", *item.name.get_ref())); - if_ok!(render_method(w, item)); - if_ok!(write!(w, "

\n")); + try!(render_method(w, item)); + try!(write!(w, "

\n")); match item.doc_value() { Some(s) => { - if_ok!(write!(w, "
{}
", Markdown(s))); + try!(write!(w, "
{}
", Markdown(s))); Ok(true) } None => Ok(false) } } - if_ok!(write!(w, "
")); + try!(write!(w, "
")); for meth in i.methods.iter() { - if if_ok!(docmeth(w, meth)) { + if try!(docmeth(w, meth)) { continue } @@ -1476,7 +1476,7 @@ fn render_impl(w: &mut Writer, i: &clean::Impl, None => continue, Some(id) => id, }; - if_ok!(local_data::get(cache_key, |cache| { + try!(local_data::get(cache_key, |cache| { let cache = cache.unwrap().get(); match cache.traits.find(&trait_id) { Some(t) => { @@ -1485,7 +1485,7 @@ fn render_impl(w: &mut Writer, i: &clean::Impl, Some(method) => { match method.item().doc_value() { Some(s) => { - if_ok!(write!(w, + try!(write!(w, "
{}
", Markdown(s))); } @@ -1506,7 +1506,7 @@ fn render_impl(w: &mut Writer, i: &clean::Impl, match trait_id { None => {} Some(id) => { - if_ok!(local_data::get(cache_key, |cache| { + try!(local_data::get(cache_key, |cache| { let cache = cache.unwrap().get(); match cache.traits.find(&id) { Some(t) => { @@ -1517,7 +1517,7 @@ fn render_impl(w: &mut Writer, i: &clean::Impl, None => {} } - if_ok!(docmeth(w, method.item())); + try!(docmeth(w, method.item())); } } None => {} @@ -1526,13 +1526,13 @@ fn render_impl(w: &mut Writer, i: &clean::Impl, })) } } - if_ok!(write!(w, "
")); + try!(write!(w, "
")); Ok(()) } fn item_typedef(w: &mut Writer, it: &clean::Item, t: &clean::Typedef) -> fmt::Result { - if_ok!(write!(w, "
type {}{} = {};
", + try!(write!(w, "
type {}{} = {};
", it.name.get_ref().as_slice(), t.generics, t.type_)); @@ -1544,17 +1544,17 @@ impl<'a> fmt::Show for Sidebar<'a> { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { let cx = self.cx; let it = self.item; - if_ok!(write!(fmt.buf, "

")); + try!(write!(fmt.buf, "

")); let len = cx.current.len() - if it.is_mod() {1} else {0}; for (i, name) in cx.current.iter().take(len).enumerate() { if i > 0 { - if_ok!(write!(fmt.buf, "&\\#8203;::")); + try!(write!(fmt.buf, "&\\#8203;::")); } - if_ok!(write!(fmt.buf, "{}", + try!(write!(fmt.buf, "{}", cx.root_path.slice_to((cx.current.len() - i - 1) * 3), *name)); } - if_ok!(write!(fmt.buf, "

")); + try!(write!(fmt.buf, "

")); fn block(w: &mut Writer, short: &str, longty: &str, cur: &clean::Item, cx: &Context) -> fmt::Result { @@ -1562,11 +1562,11 @@ impl<'a> fmt::Show for Sidebar<'a> { Some(items) => items.as_slice(), None => return Ok(()) }; - if_ok!(write!(w, "

{}

", short, longty)); + try!(write!(w, "

{}

", short, longty)); for item in items.iter() { let class = if cur.name.get_ref() == item && short == shortty(cur) { "current" } else { "" }; - if_ok!(write!(w, " fmt::Show for Sidebar<'a> { curty = shortty(cur), name = item.as_slice())); } - if_ok!(write!(w, "
")); + try!(write!(w, "
")); Ok(()) } - if_ok!(block(fmt.buf, "mod", "Modules", it, cx)); - if_ok!(block(fmt.buf, "struct", "Structs", it, cx)); - if_ok!(block(fmt.buf, "enum", "Enums", it, cx)); - if_ok!(block(fmt.buf, "trait", "Traits", it, cx)); - if_ok!(block(fmt.buf, "fn", "Functions", it, cx)); + try!(block(fmt.buf, "mod", "Modules", it, cx)); + try!(block(fmt.buf, "struct", "Structs", it, cx)); + try!(block(fmt.buf, "enum", "Enums", it, cx)); + try!(block(fmt.buf, "trait", "Traits", it, cx)); + try!(block(fmt.buf, "fn", "Functions", it, cx)); Ok(()) } } @@ -1620,20 +1620,20 @@ impl<'a> fmt::Show for Source<'a> { cols += 1; tmp /= 10; } - if_ok!(write!(fmt.buf, "
"));
+        try!(write!(fmt.buf, "
"));
         for i in range(1, lines + 1) {
-            if_ok!(write!(fmt.buf, "{0:1$u}\n", i, cols));
+            try!(write!(fmt.buf, "{0:1$u}\n", i, cols));
         }
-        if_ok!(write!(fmt.buf, "
")); - if_ok!(write!(fmt.buf, "
"));
-        if_ok!(write!(fmt.buf, "{}", Escape(s.as_slice())));
-        if_ok!(write!(fmt.buf, "
")); + try!(write!(fmt.buf, "
")); + try!(write!(fmt.buf, "
"));
+        try!(write!(fmt.buf, "{}", Escape(s.as_slice())));
+        try!(write!(fmt.buf, "
")); Ok(()) } } fn item_macro(w: &mut Writer, it: &clean::Item, t: &clean::Macro) -> fmt::Result { - if_ok!(write!(w, "
{}
", t.source)); + try!(write!(w, "
{}
", t.source)); document(w, it) } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index de992e68fe0..6502ab1dce3 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -351,7 +351,7 @@ fn json_output(krate: clean::Crate, res: ~[plugins::PluginJson], json.insert(~"crate", crate_json); json.insert(~"plugins", json::Object(plugins_json)); - let mut file = if_ok!(File::create(&dst)); - if_ok!(json::Object(json).to_writer(&mut file)); + let mut file = try!(File::create(&dst)); + try!(json::Object(json).to_writer(&mut file)); Ok(()) } diff --git a/src/libsemver/lib.rs b/src/libsemver/lib.rs index 6c794e031ab..d03d230d8bf 100644 --- a/src/libsemver/lib.rs +++ b/src/libsemver/lib.rs @@ -99,19 +99,19 @@ pub struct Version { impl fmt::Show for Version { #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if_ok!(write!(f.buf, "{}.{}.{}", self.major, self.minor, self.patch)) + try!(write!(f.buf, "{}.{}.{}", self.major, self.minor, self.patch)) if !self.pre.is_empty() { - if_ok!(write!(f.buf, "-")); + try!(write!(f.buf, "-")); for (i, x) in self.pre.iter().enumerate() { - if i != 0 { if_ok!(write!(f.buf, ".")) }; - if_ok!(x.fmt(f)); + if i != 0 { try!(write!(f.buf, ".")) }; + try!(x.fmt(f)); } } if !self.build.is_empty() { - if_ok!(write!(f.buf, "+")); + try!(write!(f.buf, "+")); for (i, x) in self.build.iter().enumerate() { - if i != 0 { if_ok!(write!(f.buf, ".")) }; - if_ok!(x.fmt(f)); + if i != 0 { try!(write!(f.buf, ".")) }; + try!(x.fmt(f)); } } Ok(()) diff --git a/src/libserialize/ebml.rs b/src/libserialize/ebml.rs index 6dc23f586db..e65c21a6b5f 100644 --- a/src/libserialize/ebml.rs +++ b/src/libserialize/ebml.rs @@ -12,7 +12,7 @@ use std::str; -macro_rules! if_ok( ($e:expr) => ( +macro_rules! try( ($e:expr) => ( match $e { Ok(e) => e, Err(e) => { self.last_error = Err(e); return } } ) ) @@ -665,18 +665,18 @@ pub mod writer { write_vuint(self.writer, tag_id); // Write a placeholder four-byte size. - self.size_positions.push(if_ok!(self.writer.tell()) as uint); + self.size_positions.push(try!(self.writer.tell()) as uint); let zeroes: &[u8] = &[0u8, 0u8, 0u8, 0u8]; - if_ok!(self.writer.write(zeroes)); + try!(self.writer.write(zeroes)); } pub fn end_tag(&mut self) { let last_size_pos = self.size_positions.pop().unwrap(); - let cur_pos = if_ok!(self.writer.tell()); - if_ok!(self.writer.seek(last_size_pos as i64, io::SeekSet)); + let cur_pos = try!(self.writer.tell()); + try!(self.writer.seek(last_size_pos as i64, io::SeekSet)); let size = (cur_pos as uint - last_size_pos - 4); write_sized_vuint(self.writer, size, 4u); - if_ok!(self.writer.seek(cur_pos as i64, io::SeekSet)); + try!(self.writer.seek(cur_pos as i64, io::SeekSet)); debug!("End tag (size = {})", size); } diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index 354b812f675..9c70d34cc0f 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -702,7 +702,7 @@ pub unsafe fn write_unsafe(output: &mut io::Writer, curarg: args.iter(), }; for piece in fmt.iter() { - if_ok!(formatter.run(piece, None)); + try!(formatter.run(piece, None)); } Ok(()) } @@ -859,13 +859,13 @@ impl<'a> Formatter<'a> { for s in selectors.iter() { if s.selector == value { for piece in s.result.iter() { - if_ok!(self.run(piece, Some(value))); + try!(self.run(piece, Some(value))); } return Ok(()); } } for piece in default.iter() { - if_ok!(self.run(piece, Some(value))); + try!(self.run(piece, Some(value))); } Ok(()) } @@ -876,7 +876,7 @@ impl<'a> Formatter<'a> { ::uint::to_str_bytes(value, 10, |buf| { let valuestr = str::from_utf8(buf).unwrap(); for piece in pieces.iter() { - if_ok!(self.run(piece, Some(valuestr))); + try!(self.run(piece, Some(valuestr))); } Ok(()) }) @@ -917,12 +917,12 @@ impl<'a> Formatter<'a> { let sign = |this: &mut Formatter| { if !signprinted { if this.flags & 1 << (FlagSignPlus as uint) != 0 && positive { - if_ok!(this.buf.write(['+' as u8])); + try!(this.buf.write(['+' as u8])); } else if !positive { - if_ok!(this.buf.write(['-' as u8])); + try!(this.buf.write(['-' as u8])); } if this.flags & 1 << (FlagAlternate as uint) != 0 { - if_ok!(this.buf.write(alternate_prefix.as_bytes())); + try!(this.buf.write(alternate_prefix.as_bytes())); } signprinted = true; } @@ -939,7 +939,7 @@ impl<'a> Formatter<'a> { Some(min) => { if self.flags & 1 << (FlagSignAwareZeroPad as uint) != 0 { self.fill = '0'; - if_ok!(sign(self)); + try!(sign(self)); } self.with_padding(min - actual_len, parse::AlignRight, |me| { emit(me) @@ -1011,15 +1011,15 @@ impl<'a> Formatter<'a> { parse::AlignLeft | parse::AlignRight => self.align }; if align == parse::AlignLeft { - if_ok!(f(self)); + try!(f(self)); } let mut fill = [0u8, ..4]; let len = self.fill.encode_utf8(fill); for _ in range(0, padding) { - if_ok!(self.buf.write(fill.slice_to(len))); + try!(self.buf.write(fill.slice_to(len))); } if align == parse::AlignRight { - if_ok!(f(self)); + try!(f(self)); } Ok(()) } diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index 1ac599d0654..5d4db106728 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -599,15 +599,15 @@ impl Clone for HashMap { impl fmt::Show for HashMap { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if_ok!(write!(f.buf, r"\{")) + try!(write!(f.buf, r"\{")) let mut first = true; for (key, value) in self.iter() { if first { first = false; } else { - if_ok!(write!(f.buf, ", ")); + try!(write!(f.buf, ", ")); } - if_ok!(write!(f.buf, "{}: {}", *key, *value)); + try!(write!(f.buf, "{}: {}", *key, *value)); } write!(f.buf, r"\}") } @@ -877,15 +877,15 @@ impl Clone for HashSet { impl fmt::Show for HashSet
{ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if_ok!(write!(f.buf, r"\{")) + try!(write!(f.buf, r"\{")) let mut first = true; for x in self.iter() { if first { first = false; } else { - if_ok!(write!(f.buf, ", ")); + try!(write!(f.buf, ", ")); } - if_ok!(write!(f.buf, "{}", *x)); + try!(write!(f.buf, "{}", *x)); } write!(f.buf, r"\}") } diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 227f3a0a083..df2a800c292 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -88,7 +88,7 @@ impl BufferedReader { impl Buffer for BufferedReader { fn fill<'a>(&'a mut self) -> IoResult<&'a [u8]> { if self.pos == self.cap { - self.cap = if_ok!(self.inner.read(self.buf)); + self.cap = try!(self.inner.read(self.buf)); self.pos = 0; } Ok(self.buf.slice(self.pos, self.cap)) @@ -103,7 +103,7 @@ impl Buffer for BufferedReader { impl Reader for BufferedReader { fn read(&mut self, buf: &mut [u8]) -> IoResult { let nread = { - let available = if_ok!(self.fill()); + let available = try!(self.fill()); let nread = cmp::min(available.len(), buf.len()); vec::bytes::copy_memory(buf, available.slice_to(nread)); nread @@ -182,7 +182,7 @@ impl BufferedWriter { impl Writer for BufferedWriter { fn write(&mut self, buf: &[u8]) -> IoResult<()> { if self.pos + buf.len() > self.buf.len() { - if_ok!(self.flush_buf()); + try!(self.flush_buf()); } if buf.len() > self.buf.len() { @@ -233,9 +233,9 @@ impl Writer for LineBufferedWriter { fn write(&mut self, buf: &[u8]) -> IoResult<()> { match buf.iter().rposition(|&b| b == '\n' as u8) { Some(i) => { - if_ok!(self.inner.write(buf.slice_to(i + 1))); - if_ok!(self.inner.flush()); - if_ok!(self.inner.write(buf.slice_from(i + 1))); + try!(self.inner.write(buf.slice_to(i + 1))); + try!(self.inner.flush()); + try!(self.inner.write(buf.slice_from(i + 1))); Ok(()) } None => self.inner.write(buf), diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index cd6c6763f66..7f2af92b078 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -339,8 +339,8 @@ pub fn copy(from: &Path, to: &Path) -> IoResult<()> { }) } - let mut reader = if_ok!(File::open(from)); - let mut writer = if_ok!(File::create(to)); + let mut reader = try!(File::open(from)); + let mut writer = try!(File::create(to)); let mut buf = [0, ..io::DEFAULT_BUF_SIZE]; loop { @@ -349,10 +349,10 @@ pub fn copy(from: &Path, to: &Path) -> IoResult<()> { Err(ref e) if e.kind == io::EndOfFile => { break } Err(e) => return Err(e) }; - if_ok!(writer.write(buf.slice_to(amt))); + try!(writer.write(buf.slice_to(amt))); } - chmod(to, if_ok!(from.stat()).perm) + chmod(to, try!(from.stat()).perm) } /// Changes the permission mode bits found on a file or a directory. This @@ -460,10 +460,10 @@ pub fn rmdir(path: &Path) -> IoResult<()> { /// // one possible implementation of fs::walk_dir only visiting files /// fn visit_dirs(dir: &Path, cb: |&Path|) -> io::IoResult<()> { /// if dir.is_dir() { -/// let contents = if_ok!(fs::readdir(dir)); +/// let contents = try!(fs::readdir(dir)); /// for entry in contents.iter() { /// if entry.is_dir() { -/// if_ok!(visit_dirs(entry, |p| cb(p))); +/// try!(visit_dirs(entry, |p| cb(p))); /// } else { /// cb(entry); /// } @@ -490,7 +490,7 @@ pub fn readdir(path: &Path) -> IoResult<~[Path]> { /// rooted at `path`. The path given will not be iterated over, and this will /// perform iteration in a top-down order. pub fn walk_dir(path: &Path) -> IoResult { - Ok(Directories { stack: if_ok!(readdir(path)) }) + Ok(Directories { stack: try!(readdir(path)) }) } /// An iterator which walks over a directory @@ -529,7 +529,7 @@ pub fn mkdir_recursive(path: &Path, mode: FilePermission) -> IoResult<()> { return Ok(()) } if path.filename().is_some() { - if_ok!(mkdir_recursive(&path.dir_path(), mode)); + try!(mkdir_recursive(&path.dir_path(), mode)); } mkdir(path, mode) } @@ -542,12 +542,12 @@ pub fn mkdir_recursive(path: &Path, mode: FilePermission) -> IoResult<()> { /// This function will return an `Err` value if an error happens. See /// `file::unlink` and `fs::readdir` for possible error conditions. pub fn rmdir_recursive(path: &Path) -> IoResult<()> { - let children = if_ok!(readdir(path)); + let children = try!(readdir(path)); for child in children.iter() { if child.is_dir() { - if_ok!(rmdir_recursive(child)); + try!(rmdir_recursive(child)); } else { - if_ok!(unlink(child)); + try!(unlink(child)); } } // Directory should now be empty diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index ff61ef15fa5..49c37b4520f 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -113,7 +113,7 @@ impl Writer for MemWriter { impl Seek for MemWriter { fn tell(&self) -> IoResult { Ok(self.pos as u64) } fn seek(&mut self, pos: i64, style: SeekStyle) -> IoResult<()> { - let new = if_ok!(combine(style, self.pos, self.buf.len(), pos)); + let new = try!(combine(style, self.pos, self.buf.len(), pos)); self.pos = new as uint; Ok(()) } @@ -183,7 +183,7 @@ impl Reader for MemReader { impl Seek for MemReader { fn tell(&self) -> IoResult { Ok(self.pos as u64) } fn seek(&mut self, pos: i64, style: SeekStyle) -> IoResult<()> { - let new = if_ok!(combine(style, self.pos, self.buf.len(), pos)); + let new = try!(combine(style, self.pos, self.buf.len(), pos)); self.pos = new as uint; Ok(()) } @@ -253,7 +253,7 @@ impl<'a> Writer for BufWriter<'a> { impl<'a> Seek for BufWriter<'a> { fn tell(&self) -> IoResult { Ok(self.pos as u64) } fn seek(&mut self, pos: i64, style: SeekStyle) -> IoResult<()> { - let new = if_ok!(combine(style, self.pos, self.buf.len(), pos)); + let new = try!(combine(style, self.pos, self.buf.len(), pos)); self.pos = new as uint; Ok(()) } @@ -313,7 +313,7 @@ impl<'a> Reader for BufReader<'a> { impl<'a> Seek for BufReader<'a> { fn tell(&self) -> IoResult { Ok(self.pos as u64) } fn seek(&mut self, pos: i64, style: SeekStyle) -> IoResult<()> { - let new = if_ok!(combine(style, self.pos, self.buf.len(), pos)); + let new = try!(combine(style, self.pos, self.buf.len(), pos)); self.pos = new as uint; Ok(()) } diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 2eadf9a7f4f..db5ee09fa14 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -365,7 +365,7 @@ pub struct IoError { impl fmt::Show for IoError { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - if_ok!(fmt.buf.write_str(self.desc)); + try!(fmt.buf.write_str(self.desc)); match self.detail { Some(ref s) => write!(fmt.buf, " ({})", *s), None => Ok(()) @@ -581,7 +581,7 @@ pub trait Reader { let mut pos = 0; let mut i = nbytes; while i > 0 { - val += (if_ok!(self.read_u8()) as u64) << pos; + val += (try!(self.read_u8()) as u64) << pos; pos += 8; i -= 1; } @@ -605,7 +605,7 @@ pub trait Reader { let mut i = nbytes; while i > 0 { i -= 1; - val += (if_ok!(self.read_u8()) as u64) << i * 8; + val += (try!(self.read_u8()) as u64) << i * 8; } Ok(val) } @@ -1191,7 +1191,7 @@ pub trait Buffer: Reader { /// This function will also return error if the stream does not contain a /// valid utf-8 encoded codepoint as the next few bytes in the stream. fn read_char(&mut self) -> IoResult { - let first_byte = if_ok!(self.read_byte()); + let first_byte = try!(self.read_byte()); let width = str::utf8_char_width(first_byte); if width == 1 { return Ok(first_byte as char) } if width == 0 { return Err(standard_error(InvalidInput)) } // not utf8 @@ -1199,7 +1199,7 @@ pub trait Buffer: Reader { { let mut start = 1; while start < width { - match if_ok!(self.read(buf.mut_slice(start, width))) { + match try!(self.read(buf.mut_slice(start, width))) { n if n == width - start => break, n if n < width - start => { start += n; } _ => return Err(standard_error(InvalidInput)), diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 79ae9faf629..acaffd00665 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -189,7 +189,7 @@ pub fn copy(r: &mut R, w: &mut W) -> io::IoResult<()> { Err(ref e) if e.kind == io::EndOfFile => return Ok(()), Err(e) => return Err(e), }; - if_ok!(w.write(buf.slice_to(len))); + try!(w.write(buf.slice_to(len))); } } diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 34b33003786..3e8a4d24f3e 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -355,6 +355,6 @@ macro_rules! local_data_key( /// error if the value of the expression is `Err`. For more information, see /// `std::io`. #[macro_export] -macro_rules! if_ok( +macro_rules! try( ($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) }) ) diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index fb2053ddaf6..d367aaa6dc4 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -32,7 +32,7 @@ use vec::OwnedVector; use unstable::intrinsics::{Disr, Opaque, TyDesc, TyVisitor, get_tydesc, visit_tydesc}; use unstable::raw; -macro_rules! if_ok( ($me:expr, $e:expr) => ( +macro_rules! try( ($me:expr, $e:expr) => ( match $e { Ok(()) => {}, Err(e) => { $me.last_err = Some(e); return false; } @@ -181,23 +181,23 @@ impl<'a> ReprVisitor<'a> { #[inline] pub fn write(&mut self) -> bool { self.get(|this, v:&T| { - if_ok!(this, v.write_repr(this.writer)); + try!(this, v.write_repr(this.writer)); true }) } pub fn write_escaped_slice(&mut self, slice: &str) -> bool { - if_ok!(self, self.writer.write(['"' as u8])); + try!(self, self.writer.write(['"' as u8])); for ch in slice.chars() { if !self.write_escaped_char(ch, true) { return false } } - if_ok!(self, self.writer.write(['"' as u8])); + try!(self, self.writer.write(['"' as u8])); true } pub fn write_mut_qualifier(&mut self, mtbl: uint) -> bool { if mtbl == 0 { - if_ok!(self, self.writer.write("mut ".as_bytes())); + try!(self, self.writer.write("mut ".as_bytes())); } else if mtbl == 1 { // skip, this is ast::m_imm } else { @@ -209,7 +209,7 @@ impl<'a> ReprVisitor<'a> { pub fn write_vec_range(&mut self, ptr: *(), len: uint, inner: *TyDesc) -> bool { let mut p = ptr as *u8; let (sz, al) = unsafe { ((*inner).size, (*inner).align) }; - if_ok!(self, self.writer.write(['[' as u8])); + try!(self, self.writer.write(['[' as u8])); let mut first = true; let mut left = len; // unit structs have 0 size, and don't loop forever. @@ -218,13 +218,13 @@ impl<'a> ReprVisitor<'a> { if first { first = false; } else { - if_ok!(self, self.writer.write(", ".as_bytes())); + try!(self, self.writer.write(", ".as_bytes())); } self.visit_ptr_inner(p as *u8, inner); p = align(unsafe { p.offset(sz as int) as uint }, al) as *u8; left -= dec; } - if_ok!(self, self.writer.write([']' as u8])); + try!(self, self.writer.write([']' as u8])); true } @@ -233,7 +233,7 @@ impl<'a> ReprVisitor<'a> { } fn write_escaped_char(&mut self, ch: char, is_str: bool) -> bool { - if_ok!(self, match ch { + try!(self, match ch { '\t' => self.writer.write("\\t".as_bytes()), '\r' => self.writer.write("\\r".as_bytes()), '\n' => self.writer.write("\\n".as_bytes()), @@ -266,7 +266,7 @@ impl<'a> ReprVisitor<'a> { impl<'a> TyVisitor for ReprVisitor<'a> { fn visit_bot(&mut self) -> bool { - if_ok!(self, self.writer.write("!".as_bytes())); + try!(self, self.writer.write("!".as_bytes())); true } fn visit_nil(&mut self) -> bool { self.write::<()>() } @@ -288,9 +288,9 @@ impl<'a> TyVisitor for ReprVisitor<'a> { fn visit_char(&mut self) -> bool { self.get::(|this, &ch| { - if_ok!(this, this.writer.write(['\'' as u8])); + try!(this, this.writer.write(['\'' as u8])); if !this.write_escaped_char(ch, false) { return false } - if_ok!(this, this.writer.write(['\'' as u8])); + try!(this, this.writer.write(['\'' as u8])); true }) } @@ -301,7 +301,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> { fn visit_estr_uniq(&mut self) -> bool { self.get::<~str>(|this, s| { - if_ok!(this, this.writer.write(['~' as u8])); + try!(this, this.writer.write(['~' as u8])); this.write_escaped_slice(*s) }) } @@ -315,7 +315,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> { _align: uint) -> bool { fail!(); } fn visit_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - if_ok!(self, self.writer.write(['@' as u8])); + try!(self, self.writer.write(['@' as u8])); self.write_mut_qualifier(mtbl); self.get::<&raw::Box<()>>(|this, b| { let p = &b.data as *() as *u8; @@ -324,7 +324,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> { } fn visit_uniq(&mut self, _mtbl: uint, inner: *TyDesc) -> bool { - if_ok!(self, self.writer.write(['~' as u8])); + try!(self, self.writer.write(['~' as u8])); self.get::<*u8>(|this, b| { this.visit_ptr_inner(*b, inner) }) @@ -332,15 +332,15 @@ impl<'a> TyVisitor for ReprVisitor<'a> { fn visit_ptr(&mut self, mtbl: uint, _inner: *TyDesc) -> bool { self.get::<*u8>(|this, p| { - if_ok!(this, write!(this.writer, "({} as *", *p)); + try!(this, write!(this.writer, "({} as *", *p)); this.write_mut_qualifier(mtbl); - if_ok!(this, this.writer.write("())".as_bytes())); + try!(this, this.writer.write("())".as_bytes())); true }) } fn visit_rptr(&mut self, mtbl: uint, inner: *TyDesc) -> bool { - if_ok!(self, self.writer.write(['&' as u8])); + try!(self, self.writer.write(['&' as u8])); self.write_mut_qualifier(mtbl); self.get::<*u8>(|this, p| { this.visit_ptr_inner(*p, inner) @@ -358,7 +358,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> { fn visit_evec_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool { self.get::<&raw::Box>>(|this, b| { - if_ok!(this, this.writer.write(['@' as u8])); + try!(this, this.writer.write(['@' as u8])); this.write_mut_qualifier(mtbl); this.write_unboxed_vec_repr(mtbl, &b.data, inner) }) @@ -366,14 +366,14 @@ impl<'a> TyVisitor for ReprVisitor<'a> { fn visit_evec_uniq(&mut self, mtbl: uint, inner: *TyDesc) -> bool { self.get::<&raw::Vec<()>>(|this, b| { - if_ok!(this, this.writer.write(['~' as u8])); + try!(this, this.writer.write(['~' as u8])); this.write_unboxed_vec_repr(mtbl, *b, inner) }) } fn visit_evec_slice(&mut self, mtbl: uint, inner: *TyDesc) -> bool { self.get::>(|this, s| { - if_ok!(this, this.writer.write(['&' as u8])); + try!(this, this.writer.write(['&' as u8])); this.write_mut_qualifier(mtbl); let size = unsafe { if (*inner).size == 0 { 1 } else { (*inner).size } @@ -392,36 +392,36 @@ impl<'a> TyVisitor for ReprVisitor<'a> { fn visit_enter_rec(&mut self, _n_fields: uint, _sz: uint, _align: uint) -> bool { - if_ok!(self, self.writer.write(['{' as u8])); + try!(self, self.writer.write(['{' as u8])); true } fn visit_rec_field(&mut self, i: uint, name: &str, mtbl: uint, inner: *TyDesc) -> bool { if i != 0 { - if_ok!(self, self.writer.write(", ".as_bytes())); + try!(self, self.writer.write(", ".as_bytes())); } self.write_mut_qualifier(mtbl); - if_ok!(self, self.writer.write(name.as_bytes())); - if_ok!(self, self.writer.write(": ".as_bytes())); + try!(self, self.writer.write(name.as_bytes())); + try!(self, self.writer.write(": ".as_bytes())); self.visit_inner(inner); true } fn visit_leave_rec(&mut self, _n_fields: uint, _sz: uint, _align: uint) -> bool { - if_ok!(self, self.writer.write(['}' as u8])); + try!(self, self.writer.write(['}' as u8])); true } fn visit_enter_class(&mut self, name: &str, named_fields: bool, n_fields: uint, _sz: uint, _align: uint) -> bool { - if_ok!(self, self.writer.write(name.as_bytes())); + try!(self, self.writer.write(name.as_bytes())); if n_fields != 0 { if named_fields { - if_ok!(self, self.writer.write(['{' as u8])); + try!(self, self.writer.write(['{' as u8])); } else { - if_ok!(self, self.writer.write(['(' as u8])); + try!(self, self.writer.write(['(' as u8])); } } true @@ -430,11 +430,11 @@ impl<'a> TyVisitor for ReprVisitor<'a> { fn visit_class_field(&mut self, i: uint, name: &str, named: bool, _mtbl: uint, inner: *TyDesc) -> bool { if i != 0 { - if_ok!(self, self.writer.write(", ".as_bytes())); + try!(self, self.writer.write(", ".as_bytes())); } if named { - if_ok!(self, self.writer.write(name.as_bytes())); - if_ok!(self, self.writer.write(": ".as_bytes())); + try!(self, self.writer.write(name.as_bytes())); + try!(self, self.writer.write(": ".as_bytes())); } self.visit_inner(inner); true @@ -444,9 +444,9 @@ impl<'a> TyVisitor for ReprVisitor<'a> { _sz: uint, _align: uint) -> bool { if n_fields != 0 { if named_fields { - if_ok!(self, self.writer.write(['}' as u8])); + try!(self, self.writer.write(['}' as u8])); } else { - if_ok!(self, self.writer.write([')' as u8])); + try!(self, self.writer.write([')' as u8])); } } true @@ -454,13 +454,13 @@ impl<'a> TyVisitor for ReprVisitor<'a> { fn visit_enter_tup(&mut self, _n_fields: uint, _sz: uint, _align: uint) -> bool { - if_ok!(self, self.writer.write(['(' as u8])); + try!(self, self.writer.write(['(' as u8])); true } fn visit_tup_field(&mut self, i: uint, inner: *TyDesc) -> bool { if i != 0 { - if_ok!(self, self.writer.write(", ".as_bytes())); + try!(self, self.writer.write(", ".as_bytes())); } self.visit_inner(inner); true @@ -469,9 +469,9 @@ impl<'a> TyVisitor for ReprVisitor<'a> { fn visit_leave_tup(&mut self, _n_fields: uint, _sz: uint, _align: uint) -> bool { if _n_fields == 1 { - if_ok!(self, self.writer.write([',' as u8])); + try!(self, self.writer.write([',' as u8])); } - if_ok!(self, self.writer.write([')' as u8])); + try!(self, self.writer.write([')' as u8])); true } @@ -507,9 +507,9 @@ impl<'a> TyVisitor for ReprVisitor<'a> { } if write { - if_ok!(self, self.writer.write(name.as_bytes())); + try!(self, self.writer.write(name.as_bytes())); if n_fields > 0 { - if_ok!(self, self.writer.write(['(' as u8])); + try!(self, self.writer.write(['(' as u8])); } } true @@ -523,7 +523,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> { match self.var_stk[self.var_stk.len() - 1] { Matched => { if i != 0 { - if_ok!(self, self.writer.write(", ".as_bytes())); + try!(self, self.writer.write(", ".as_bytes())); } if ! self.visit_inner(inner) { return false; @@ -541,7 +541,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> { match self.var_stk[self.var_stk.len() - 1] { Matched => { if n_fields > 0 { - if_ok!(self, self.writer.write([')' as u8])); + try!(self, self.writer.write([')' as u8])); } } _ => () @@ -563,29 +563,29 @@ impl<'a> TyVisitor for ReprVisitor<'a> { fn visit_enter_fn(&mut self, _purity: uint, _proto: uint, _n_inputs: uint, _retstyle: uint) -> bool { - if_ok!(self, self.writer.write("fn(".as_bytes())); + try!(self, self.writer.write("fn(".as_bytes())); true } fn visit_fn_input(&mut self, i: uint, _mode: uint, inner: *TyDesc) -> bool { if i != 0 { - if_ok!(self, self.writer.write(", ".as_bytes())); + try!(self, self.writer.write(", ".as_bytes())); } let name = unsafe { (*inner).name }; - if_ok!(self, self.writer.write(name.as_bytes())); + try!(self, self.writer.write(name.as_bytes())); true } fn visit_fn_output(&mut self, _retstyle: uint, variadic: bool, inner: *TyDesc) -> bool { if variadic { - if_ok!(self, self.writer.write(", ...".as_bytes())); + try!(self, self.writer.write(", ...".as_bytes())); } - if_ok!(self, self.writer.write(")".as_bytes())); + try!(self, self.writer.write(")".as_bytes())); let name = unsafe { (*inner).name }; if name != "()" { - if_ok!(self, self.writer.write(" -> ".as_bytes())); - if_ok!(self, self.writer.write(name.as_bytes())); + try!(self, self.writer.write(" -> ".as_bytes())); + try!(self, self.writer.write(name.as_bytes())); } true } @@ -595,7 +595,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> { fn visit_trait(&mut self, name: &str) -> bool { - if_ok!(self, self.writer.write(name.as_bytes())); + try!(self, self.writer.write(name.as_bytes())); true } diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index 7a81e69f30a..b0d51cba103 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -161,9 +161,9 @@ macro_rules! write_tuple { write!($buf, "({},)", *$x) ); ($buf:expr, $hd:expr, $($tl:expr),+) => ({ - if_ok!(write!($buf, "(")); - if_ok!(write!($buf, "{}", *$hd)); - $(if_ok!(write!($buf, ", {}", *$tl));)+ + try!(write!($buf, "(")); + try!(write!($buf, "{}", *$hd)); + $(try!(write!($buf, ", {}", *$tl));)+ write!($buf, ")") }); } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index d16ad54a25d..5a42df0a389 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -2645,15 +2645,15 @@ impl DeepClone for ~[A] { impl<'a, T: fmt::Show> fmt::Show for &'a [T] { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if_ok!(write!(f.buf, "[")); + try!(write!(f.buf, "[")); let mut is_first = true; for x in self.iter() { if is_first { is_first = false; } else { - if_ok!(write!(f.buf, ", ")); + try!(write!(f.buf, ", ")); } - if_ok!(write!(f.buf, "{}", *x)) + try!(write!(f.buf, "{}", *x)) } write!(f.buf, "]") } diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 3f6540570b0..9455df063f1 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -192,9 +192,9 @@ fn print_maybe_styled(msg: &str, color: term::attr::Attr) -> io::IoResult<()> { } fn write_pretty(term: &mut term::Terminal, s: &str, c: term::attr::Attr) -> io::IoResult<()> { - if_ok!(term.attr(c)); - if_ok!(term.write(s.as_bytes())); - if_ok!(term.reset()); + try!(term.attr(c)); + try!(term.write(s.as_bytes())); + try!(term.reset()); Ok(()) } @@ -230,12 +230,12 @@ fn print_maybe_styled(msg: &str, color: term::attr::Attr) -> io::IoResult<()> { fn print_diagnostic(topic: &str, lvl: Level, msg: &str) -> io::IoResult<()> { if !topic.is_empty() { let mut stderr = io::stderr(); - if_ok!(write!(&mut stderr as &mut io::Writer, "{} ", topic)); + try!(write!(&mut stderr as &mut io::Writer, "{} ", topic)); } - if_ok!(print_maybe_styled(format!("{}: ", lvl.to_str()), + try!(print_maybe_styled(format!("{}: ", lvl.to_str()), term::attr::ForegroundColor(lvl.color()))); - if_ok!(print_maybe_styled(format!("{}\n", msg), term::attr::Bold)); + try!(print_maybe_styled(format!("{}\n", msg), term::attr::Bold)); Ok(()) } @@ -276,11 +276,11 @@ fn emit(cm: &codemap::CodeMap, sp: Span, // the span) let span_end = Span { lo: sp.hi, hi: sp.hi, expn_info: sp.expn_info}; let ses = cm.span_to_str(span_end); - if_ok!(print_diagnostic(ses, lvl, msg)); - if_ok!(custom_highlight_lines(cm, sp, lvl, lines)); + try!(print_diagnostic(ses, lvl, msg)); + try!(custom_highlight_lines(cm, sp, lvl, lines)); } else { - if_ok!(print_diagnostic(ss, lvl, msg)); - if_ok!(highlight_lines(cm, sp, lvl, lines)); + try!(print_diagnostic(ss, lvl, msg)); + try!(highlight_lines(cm, sp, lvl, lines)); } print_macro_backtrace(cm, sp) } @@ -301,13 +301,13 @@ fn highlight_lines(cm: &codemap::CodeMap, } // Print the offending lines for line in display_lines.iter() { - if_ok!(write!(err, "{}:{} {}\n", fm.name, *line + 1, + try!(write!(err, "{}:{} {}\n", fm.name, *line + 1, fm.get_line(*line as int))); } if elided { let last_line = display_lines[display_lines.len() - 1u]; let s = format!("{}:{} ", fm.name, last_line + 1u); - if_ok!(write!(err, "{0:1$}...\n", "", s.len())); + try!(write!(err, "{0:1$}...\n", "", s.len())); } // FIXME (#3260) @@ -339,7 +339,7 @@ fn highlight_lines(cm: &codemap::CodeMap, _ => s.push_char(' '), }; } - if_ok!(write!(err, "{}", s)); + try!(write!(err, "{}", s)); let mut s = ~"^"; let hi = cm.lookup_char_pos(sp.hi); if hi.col != lo.col { @@ -347,7 +347,7 @@ fn highlight_lines(cm: &codemap::CodeMap, let num_squigglies = hi.col.to_uint()-lo.col.to_uint()-1u; for _ in range(0, num_squigglies) { s.push_char('~'); } } - if_ok!(print_maybe_styled(s + "\n", + try!(print_maybe_styled(s + "\n", term::attr::ForegroundColor(lvl.color()))); } Ok(()) @@ -369,15 +369,15 @@ fn custom_highlight_lines(cm: &codemap::CodeMap, let lines = lines.lines.as_slice(); if lines.len() > MAX_LINES { - if_ok!(write!(err, "{}:{} {}\n", fm.name, + try!(write!(err, "{}:{} {}\n", fm.name, lines[0] + 1, fm.get_line(lines[0] as int))); - if_ok!(write!(err, "...\n")); + try!(write!(err, "...\n")); let last_line = lines[lines.len()-1]; - if_ok!(write!(err, "{}:{} {}\n", fm.name, + try!(write!(err, "{}:{} {}\n", fm.name, last_line + 1, fm.get_line(last_line as int))); } else { for line in lines.iter() { - if_ok!(write!(err, "{}:{} {}\n", fm.name, + try!(write!(err, "{}:{} {}\n", fm.name, *line + 1, fm.get_line(*line as int))); } } @@ -398,12 +398,12 @@ fn print_macro_backtrace(cm: &codemap::CodeMap, sp: Span) -> io::IoResult<()> { codemap::MacroAttribute => ("#[", "]"), codemap::MacroBang => ("", "!") }; - if_ok!(print_diagnostic(ss, Note, + try!(print_diagnostic(ss, Note, format!("in expansion of {}{}{}", pre, ei.callee.name, post))); let ss = cm.span_to_str(ei.call_site); - if_ok!(print_diagnostic(ss, Note, "expansion site")); - if_ok!(print_macro_backtrace(cm, ei.call_site)); + try!(print_diagnostic(ss, Note, "expansion site")); + try!(print_macro_backtrace(cm, ei.call_site)); } Ok(()) } diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index f6952261723..14d8c662aae 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -299,7 +299,7 @@ impl Printer { if !self.scan_stack_empty { self.check_stack(0); let left = self.token[self.left].clone(); - if_ok!(self.advance_left(left, self.size[self.left])); + try!(self.advance_left(left, self.size[self.left])); } self.indent(0); Ok(()) @@ -377,9 +377,9 @@ impl Printer { } } let left = self.token[self.left].clone(); - if_ok!(self.advance_left(left, self.size[self.left])); + try!(self.advance_left(left, self.size[self.left])); if self.left != self.right { - if_ok!(self.check_stream()); + try!(self.check_stream()); } } Ok(()) @@ -436,7 +436,7 @@ impl Printer { self.left += 1u; self.left %= self.buf_len; let left = self.token[self.left].clone(); - if_ok!(self.advance_left(left, self.size[self.left])); + try!(self.advance_left(left, self.size[self.left])); } ret } else { @@ -491,7 +491,7 @@ impl Printer { } pub fn print_str(&mut self, s: &str) -> io::IoResult<()> { while self.pending_indentation > 0 { - if_ok!(write!(self.out, " ")); + try!(write!(self.out, " ")); self.pending_indentation -= 1; } write!(self.out, "{}", s) diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index ceaa7d1a9a1..21e1998208c 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -147,9 +147,9 @@ pub fn print_crate(cm: @CodeMap, } pub fn print_crate_(s: &mut State, krate: &ast::Crate) -> io::IoResult<()> { - if_ok!(print_mod(s, &krate.module, krate.attrs)); - if_ok!(print_remaining_comments(s)); - if_ok!(eof(&mut s.s)); + try!(print_mod(s, &krate.module, krate.attrs)); + try!(print_remaining_comments(s)); + try!(eof(&mut s.s)); Ok(()) } @@ -254,12 +254,12 @@ pub fn rbox(s: &mut State, u: uint, b: pp::Breaks) -> io::IoResult<()> { pub fn nbsp(s: &mut State) -> io::IoResult<()> { word(&mut s.s, " ") } pub fn word_nbsp(s: &mut State, w: &str) -> io::IoResult<()> { - if_ok!(word(&mut s.s, w)); + try!(word(&mut s.s, w)); nbsp(s) } pub fn word_space(s: &mut State, w: &str) -> io::IoResult<()> { - if_ok!(word(&mut s.s, w)); + try!(word(&mut s.s, w)); space(&mut s.s) } @@ -269,19 +269,19 @@ pub fn pclose(s: &mut State) -> io::IoResult<()> { word(&mut s.s, ")") } pub fn head(s: &mut State, w: &str) -> io::IoResult<()> { // outer-box is consistent - if_ok!(cbox(s, indent_unit)); + try!(cbox(s, indent_unit)); // head-box is inconsistent - if_ok!(ibox(s, w.len() + 1)); + try!(ibox(s, w.len() + 1)); // keyword that starts the head if !w.is_empty() { - if_ok!(word_nbsp(s, w)); + try!(word_nbsp(s, w)); } Ok(()) } pub fn bopen(s: &mut State) -> io::IoResult<()> { - if_ok!(word(&mut s.s, "{")); - if_ok!(end(s)); // close the head-box + try!(word(&mut s.s, "{")); + try!(end(s)); // close the head-box Ok(()) } @@ -291,11 +291,11 @@ pub fn bclose_(s: &mut State, span: codemap::Span, } pub fn bclose_maybe_open (s: &mut State, span: codemap::Span, indented: uint, close_box: bool) -> io::IoResult<()> { - if_ok!(maybe_print_comment(s, span.hi)); - if_ok!(break_offset_if_not_bol(s, 1u, -(indented as int))); - if_ok!(word(&mut s.s, "}")); + try!(maybe_print_comment(s, span.hi)); + try!(break_offset_if_not_bol(s, 1u, -(indented as int))); + try!(word(&mut s.s, "}")); if close_box { - if_ok!(end(s)); // close the outer-box + try!(end(s)); // close the outer-box } Ok(()) } @@ -324,18 +324,18 @@ pub fn in_cbox(s: &mut State) -> bool { pub fn hardbreak_if_not_bol(s: &mut State) -> io::IoResult<()> { if !is_bol(s) { - if_ok!(hardbreak(&mut s.s)) + try!(hardbreak(&mut s.s)) } Ok(()) } pub fn space_if_not_bol(s: &mut State) -> io::IoResult<()> { - if !is_bol(s) { if_ok!(space(&mut s.s)); } + if !is_bol(s) { try!(space(&mut s.s)); } Ok(()) } pub fn break_offset_if_not_bol(s: &mut State, n: uint, off: int) -> io::IoResult<()> { if !is_bol(s) { - if_ok!(break_offset(&mut s.s, n, off)); + try!(break_offset(&mut s.s, n, off)); } else { if off != 0 && s.s.last_token().is_hardbreak_tok() { // We do something pretty sketchy here: tuck the nonzero @@ -350,11 +350,11 @@ pub fn break_offset_if_not_bol(s: &mut State, n: uint, // Synthesizes a comment that was not textually present in the original source // file. pub fn synth_comment(s: &mut State, text: ~str) -> io::IoResult<()> { - if_ok!(word(&mut s.s, "/*")); - if_ok!(space(&mut s.s)); - if_ok!(word(&mut s.s, text)); - if_ok!(space(&mut s.s)); - if_ok!(word(&mut s.s, "*/")); + try!(word(&mut s.s, "/*")); + try!(space(&mut s.s)); + try!(word(&mut s.s, text)); + try!(space(&mut s.s)); + try!(word(&mut s.s, "*/")); Ok(()) } @@ -362,11 +362,11 @@ pub fn commasep(s: &mut State, b: Breaks, elts: &[T], op: |&mut State, &T| -> io::IoResult<()>) -> io::IoResult<()> { - if_ok!(rbox(s, 0u, b)); + try!(rbox(s, 0u, b)); let mut first = true; for elt in elts.iter() { - if first { first = false; } else { if_ok!(word_space(s, ",")); } - if_ok!(op(s, elt)); + if first { first = false; } else { try!(word_space(s, ",")); } + try!(op(s, elt)); } end(s) } @@ -378,18 +378,18 @@ pub fn commasep_cmnt( elts: &[T], op: |&mut State, &T| -> io::IoResult<()>, get_span: |&T| -> codemap::Span) -> io::IoResult<()> { - if_ok!(rbox(s, 0u, b)); + try!(rbox(s, 0u, b)); let len = elts.len(); let mut i = 0u; for elt in elts.iter() { - if_ok!(maybe_print_comment(s, get_span(elt).hi)); - if_ok!(op(s, elt)); + try!(maybe_print_comment(s, get_span(elt).hi)); + try!(op(s, elt)); i += 1u; if i < len { - if_ok!(word(&mut s.s, ",")); - if_ok!(maybe_print_trailing_comment(s, get_span(elt), + try!(word(&mut s.s, ",")); + try!(maybe_print_trailing_comment(s, get_span(elt), Some(get_span(&elts[i]).hi))); - if_ok!(space_if_not_bol(s)); + try!(space_if_not_bol(s)); } } end(s) @@ -402,24 +402,24 @@ pub fn commasep_exprs(s: &mut State, b: Breaks, pub fn print_mod(s: &mut State, _mod: &ast::Mod, attrs: &[ast::Attribute]) -> io::IoResult<()> { - if_ok!(print_inner_attributes(s, attrs)); + try!(print_inner_attributes(s, attrs)); for vitem in _mod.view_items.iter() { - if_ok!(print_view_item(s, vitem)); + try!(print_view_item(s, vitem)); } for item in _mod.items.iter() { - if_ok!(print_item(s, *item)); + try!(print_item(s, *item)); } Ok(()) } pub fn print_foreign_mod(s: &mut State, nmod: &ast::ForeignMod, attrs: &[ast::Attribute]) -> io::IoResult<()> { - if_ok!(print_inner_attributes(s, attrs)); + try!(print_inner_attributes(s, attrs)); for vitem in nmod.view_items.iter() { - if_ok!(print_view_item(s, vitem)); + try!(print_view_item(s, vitem)); } for item in nmod.items.iter() { - if_ok!(print_foreign_item(s, *item)); + try!(print_foreign_item(s, *item)); } Ok(()) } @@ -427,54 +427,54 @@ pub fn print_foreign_mod(s: &mut State, nmod: &ast::ForeignMod, pub fn print_opt_lifetime(s: &mut State, lifetime: &Option) -> io::IoResult<()> { for l in lifetime.iter() { - if_ok!(print_lifetime(s, l)); - if_ok!(nbsp(s)); + try!(print_lifetime(s, l)); + try!(nbsp(s)); } Ok(()) } pub fn print_type(s: &mut State, ty: &ast::Ty) -> io::IoResult<()> { - if_ok!(maybe_print_comment(s, ty.span.lo)); - if_ok!(ibox(s, 0u)); + try!(maybe_print_comment(s, ty.span.lo)); + try!(ibox(s, 0u)); match ty.node { - ast::TyNil => if_ok!(word(&mut s.s, "()")), - ast::TyBot => if_ok!(word(&mut s.s, "!")), + ast::TyNil => try!(word(&mut s.s, "()")), + ast::TyBot => try!(word(&mut s.s, "!")), ast::TyBox(ty) => { - if_ok!(word(&mut s.s, "@")); - if_ok!(print_type(s, ty)); + try!(word(&mut s.s, "@")); + try!(print_type(s, ty)); } ast::TyUniq(ty) => { - if_ok!(word(&mut s.s, "~")); - if_ok!(print_type(s, ty)); + try!(word(&mut s.s, "~")); + try!(print_type(s, ty)); } ast::TyVec(ty) => { - if_ok!(word(&mut s.s, "[")); - if_ok!(print_type(s, ty)); - if_ok!(word(&mut s.s, "]")); + try!(word(&mut s.s, "[")); + try!(print_type(s, ty)); + try!(word(&mut s.s, "]")); } ast::TyPtr(ref mt) => { - if_ok!(word(&mut s.s, "*")); - if_ok!(print_mt(s, mt)); + try!(word(&mut s.s, "*")); + try!(print_mt(s, mt)); } ast::TyRptr(ref lifetime, ref mt) => { - if_ok!(word(&mut s.s, "&")); - if_ok!(print_opt_lifetime(s, lifetime)); - if_ok!(print_mt(s, mt)); + try!(word(&mut s.s, "&")); + try!(print_opt_lifetime(s, lifetime)); + try!(print_mt(s, mt)); } ast::TyTup(ref elts) => { - if_ok!(popen(s)); - if_ok!(commasep(s, Inconsistent, *elts, print_type_ref)); + try!(popen(s)); + try!(commasep(s, Inconsistent, *elts, print_type_ref)); if elts.len() == 1 { - if_ok!(word(&mut s.s, ",")); + try!(word(&mut s.s, ",")); } - if_ok!(pclose(s)); + try!(pclose(s)); } ast::TyBareFn(f) => { let generics = ast::Generics { lifetimes: f.lifetimes.clone(), ty_params: opt_vec::Empty }; - if_ok!(print_ty_fn(s, Some(f.abis), None, &None, + try!(print_ty_fn(s, Some(f.abis), None, &None, f.purity, ast::Many, f.decl, None, &None, Some(&generics), None)); } @@ -483,24 +483,24 @@ pub fn print_type(s: &mut State, ty: &ast::Ty) -> io::IoResult<()> { lifetimes: f.lifetimes.clone(), ty_params: opt_vec::Empty }; - if_ok!(print_ty_fn(s, None, Some(f.sigil), &f.region, + try!(print_ty_fn(s, None, Some(f.sigil), &f.region, f.purity, f.onceness, f.decl, None, &f.bounds, Some(&generics), None)); } ast::TyPath(ref path, ref bounds, _) => { - if_ok!(print_bounded_path(s, path, bounds)); + try!(print_bounded_path(s, path, bounds)); } ast::TyFixedLengthVec(ty, v) => { - if_ok!(word(&mut s.s, "[")); - if_ok!(print_type(s, ty)); - if_ok!(word(&mut s.s, ", ..")); - if_ok!(print_expr(s, v)); - if_ok!(word(&mut s.s, "]")); + try!(word(&mut s.s, "[")); + try!(print_type(s, ty)); + try!(word(&mut s.s, ", ..")); + try!(print_expr(s, v)); + try!(word(&mut s.s, "]")); } ast::TyTypeof(e) => { - if_ok!(word(&mut s.s, "typeof(")); - if_ok!(print_expr(s, e)); - if_ok!(word(&mut s.s, ")")); + try!(word(&mut s.s, "typeof(")); + try!(print_expr(s, e)); + try!(word(&mut s.s, ")")); } ast::TyInfer => { fail!("print_type shouldn't see a ty_infer"); @@ -515,61 +515,61 @@ pub fn print_type_ref(s: &mut State, ty: &P) -> io::IoResult<()> { pub fn print_foreign_item(s: &mut State, item: &ast::ForeignItem) -> io::IoResult<()> { - if_ok!(hardbreak_if_not_bol(s)); - if_ok!(maybe_print_comment(s, item.span.lo)); - if_ok!(print_outer_attributes(s, item.attrs)); + try!(hardbreak_if_not_bol(s)); + try!(maybe_print_comment(s, item.span.lo)); + try!(print_outer_attributes(s, item.attrs)); match item.node { ast::ForeignItemFn(decl, ref generics) => { - if_ok!(print_fn(s, decl, None, AbiSet::Rust(), item.ident, generics, + try!(print_fn(s, decl, None, AbiSet::Rust(), item.ident, generics, None, item.vis)); - if_ok!(end(s)); // end head-ibox - if_ok!(word(&mut s.s, ";")); - if_ok!(end(s)); // end the outer fn box + try!(end(s)); // end head-ibox + try!(word(&mut s.s, ";")); + try!(end(s)); // end the outer fn box } ast::ForeignItemStatic(t, m) => { - if_ok!(head(s, visibility_qualified(item.vis, "static"))); + try!(head(s, visibility_qualified(item.vis, "static"))); if m { - if_ok!(word_space(s, "mut")); + try!(word_space(s, "mut")); } - if_ok!(print_ident(s, item.ident)); - if_ok!(word_space(s, ":")); - if_ok!(print_type(s, t)); - if_ok!(word(&mut s.s, ";")); - if_ok!(end(s)); // end the head-ibox - if_ok!(end(s)); // end the outer cbox + try!(print_ident(s, item.ident)); + try!(word_space(s, ":")); + try!(print_type(s, t)); + try!(word(&mut s.s, ";")); + try!(end(s)); // end the head-ibox + try!(end(s)); // end the outer cbox } } Ok(()) } pub fn print_item(s: &mut State, item: &ast::Item) -> io::IoResult<()> { - if_ok!(hardbreak_if_not_bol(s)); - if_ok!(maybe_print_comment(s, item.span.lo)); - if_ok!(print_outer_attributes(s, item.attrs)); + try!(hardbreak_if_not_bol(s)); + try!(maybe_print_comment(s, item.span.lo)); + try!(print_outer_attributes(s, item.attrs)); { let ann_node = NodeItem(s, item); - if_ok!(s.ann.pre(ann_node)); + try!(s.ann.pre(ann_node)); } match item.node { ast::ItemStatic(ty, m, expr) => { - if_ok!(head(s, visibility_qualified(item.vis, "static"))); + try!(head(s, visibility_qualified(item.vis, "static"))); if m == ast::MutMutable { - if_ok!(word_space(s, "mut")); + try!(word_space(s, "mut")); } - if_ok!(print_ident(s, item.ident)); - if_ok!(word_space(s, ":")); - if_ok!(print_type(s, ty)); - if_ok!(space(&mut s.s)); - if_ok!(end(s)); // end the head-ibox + try!(print_ident(s, item.ident)); + try!(word_space(s, ":")); + try!(print_type(s, ty)); + try!(space(&mut s.s)); + try!(end(s)); // end the head-ibox - if_ok!(word_space(s, "=")); - if_ok!(print_expr(s, expr)); - if_ok!(word(&mut s.s, ";")); - if_ok!(end(s)); // end the outer cbox + try!(word_space(s, "=")); + try!(print_expr(s, expr)); + try!(word(&mut s.s, ";")); + try!(end(s)); // end the outer cbox } ast::ItemFn(decl, purity, abi, ref typarams, body) => { - if_ok!(print_fn( + try!(print_fn( s, decl, Some(purity), @@ -579,40 +579,40 @@ pub fn print_item(s: &mut State, item: &ast::Item) -> io::IoResult<()> { None, item.vis )); - if_ok!(word(&mut s.s, " ")); - if_ok!(print_block_with_attrs(s, body, item.attrs)); + try!(word(&mut s.s, " ")); + try!(print_block_with_attrs(s, body, item.attrs)); } ast::ItemMod(ref _mod) => { - if_ok!(head(s, visibility_qualified(item.vis, "mod"))); - if_ok!(print_ident(s, item.ident)); - if_ok!(nbsp(s)); - if_ok!(bopen(s)); - if_ok!(print_mod(s, _mod, item.attrs)); - if_ok!(bclose(s, item.span)); + try!(head(s, visibility_qualified(item.vis, "mod"))); + try!(print_ident(s, item.ident)); + try!(nbsp(s)); + try!(bopen(s)); + try!(print_mod(s, _mod, item.attrs)); + try!(bclose(s, item.span)); } ast::ItemForeignMod(ref nmod) => { - if_ok!(head(s, "extern")); - if_ok!(word_nbsp(s, nmod.abis.to_str())); - if_ok!(bopen(s)); - if_ok!(print_foreign_mod(s, nmod, item.attrs)); - if_ok!(bclose(s, item.span)); + try!(head(s, "extern")); + try!(word_nbsp(s, nmod.abis.to_str())); + try!(bopen(s)); + try!(print_foreign_mod(s, nmod, item.attrs)); + try!(bclose(s, item.span)); } ast::ItemTy(ty, ref params) => { - if_ok!(ibox(s, indent_unit)); - if_ok!(ibox(s, 0u)); - if_ok!(word_nbsp(s, visibility_qualified(item.vis, "type"))); - if_ok!(print_ident(s, item.ident)); - if_ok!(print_generics(s, params)); - if_ok!(end(s)); // end the inner ibox + try!(ibox(s, indent_unit)); + try!(ibox(s, 0u)); + try!(word_nbsp(s, visibility_qualified(item.vis, "type"))); + try!(print_ident(s, item.ident)); + try!(print_generics(s, params)); + try!(end(s)); // end the inner ibox - if_ok!(space(&mut s.s)); - if_ok!(word_space(s, "=")); - if_ok!(print_type(s, ty)); - if_ok!(word(&mut s.s, ";")); - if_ok!(end(s)); // end the outer ibox + try!(space(&mut s.s)); + try!(word_space(s, "=")); + try!(print_type(s, ty)); + try!(word(&mut s.s, ";")); + try!(end(s)); // end the outer ibox } ast::ItemEnum(ref enum_definition, ref params) => { - if_ok!(print_enum_def( + try!(print_enum_def( s, enum_definition, params, @@ -622,74 +622,74 @@ pub fn print_item(s: &mut State, item: &ast::Item) -> io::IoResult<()> { )); } ast::ItemStruct(struct_def, ref generics) => { - if_ok!(head(s, visibility_qualified(item.vis, "struct"))); - if_ok!(print_struct(s, struct_def, generics, item.ident, item.span)); + try!(head(s, visibility_qualified(item.vis, "struct"))); + try!(print_struct(s, struct_def, generics, item.ident, item.span)); } ast::ItemImpl(ref generics, ref opt_trait, ty, ref methods) => { - if_ok!(head(s, visibility_qualified(item.vis, "impl"))); + try!(head(s, visibility_qualified(item.vis, "impl"))); if generics.is_parameterized() { - if_ok!(print_generics(s, generics)); - if_ok!(space(&mut s.s)); + try!(print_generics(s, generics)); + try!(space(&mut s.s)); } match opt_trait { &Some(ref t) => { - if_ok!(print_trait_ref(s, t)); - if_ok!(space(&mut s.s)); - if_ok!(word_space(s, "for")); + try!(print_trait_ref(s, t)); + try!(space(&mut s.s)); + try!(word_space(s, "for")); } &None => () }; - if_ok!(print_type(s, ty)); + try!(print_type(s, ty)); - if_ok!(space(&mut s.s)); - if_ok!(bopen(s)); - if_ok!(print_inner_attributes(s, item.attrs)); + try!(space(&mut s.s)); + try!(bopen(s)); + try!(print_inner_attributes(s, item.attrs)); for meth in methods.iter() { - if_ok!(print_method(s, *meth)); + try!(print_method(s, *meth)); } - if_ok!(bclose(s, item.span)); + try!(bclose(s, item.span)); } ast::ItemTrait(ref generics, ref traits, ref methods) => { - if_ok!(head(s, visibility_qualified(item.vis, "trait"))); - if_ok!(print_ident(s, item.ident)); - if_ok!(print_generics(s, generics)); + try!(head(s, visibility_qualified(item.vis, "trait"))); + try!(print_ident(s, item.ident)); + try!(print_generics(s, generics)); if traits.len() != 0u { - if_ok!(word(&mut s.s, ":")); + try!(word(&mut s.s, ":")); for (i, trait_) in traits.iter().enumerate() { - if_ok!(nbsp(s)); + try!(nbsp(s)); if i != 0 { - if_ok!(word_space(s, "+")); + try!(word_space(s, "+")); } - if_ok!(print_path(s, &trait_.path, false)); + try!(print_path(s, &trait_.path, false)); } } - if_ok!(word(&mut s.s, " ")); - if_ok!(bopen(s)); + try!(word(&mut s.s, " ")); + try!(bopen(s)); for meth in methods.iter() { - if_ok!(print_trait_method(s, meth)); + try!(print_trait_method(s, meth)); } - if_ok!(bclose(s, item.span)); + try!(bclose(s, item.span)); } // I think it's reasonable to hide the context here: ast::ItemMac(codemap::Spanned { node: ast::MacInvocTT(ref pth, ref tts, _), ..}) => { - if_ok!(print_visibility(s, item.vis)); - if_ok!(print_path(s, pth, false)); - if_ok!(word(&mut s.s, "! ")); - if_ok!(print_ident(s, item.ident)); - if_ok!(cbox(s, indent_unit)); - if_ok!(popen(s)); - if_ok!(print_tts(s, &(tts.as_slice()))); - if_ok!(pclose(s)); - if_ok!(end(s)); + try!(print_visibility(s, item.vis)); + try!(print_path(s, pth, false)); + try!(word(&mut s.s, "! ")); + try!(print_ident(s, item.ident)); + try!(cbox(s, indent_unit)); + try!(popen(s)); + try!(print_tts(s, &(tts.as_slice()))); + try!(pclose(s)); + try!(end(s)); } } { let ann_node = NodeItem(s, item); - if_ok!(s.ann.post(ann_node)); + try!(s.ann.post(ann_node)); } Ok(()) } @@ -702,27 +702,27 @@ pub fn print_enum_def(s: &mut State, enum_definition: &ast::EnumDef, generics: &ast::Generics, ident: ast::Ident, span: codemap::Span, visibility: ast::Visibility) -> io::IoResult<()> { - if_ok!(head(s, visibility_qualified(visibility, "enum"))); - if_ok!(print_ident(s, ident)); - if_ok!(print_generics(s, generics)); - if_ok!(space(&mut s.s)); - if_ok!(print_variants(s, enum_definition.variants, span)); + try!(head(s, visibility_qualified(visibility, "enum"))); + try!(print_ident(s, ident)); + try!(print_generics(s, generics)); + try!(space(&mut s.s)); + try!(print_variants(s, enum_definition.variants, span)); Ok(()) } pub fn print_variants(s: &mut State, variants: &[P], span: codemap::Span) -> io::IoResult<()> { - if_ok!(bopen(s)); + try!(bopen(s)); for &v in variants.iter() { - if_ok!(space_if_not_bol(s)); - if_ok!(maybe_print_comment(s, v.span.lo)); - if_ok!(print_outer_attributes(s, v.node.attrs)); - if_ok!(ibox(s, indent_unit)); - if_ok!(print_variant(s, v)); - if_ok!(word(&mut s.s, ",")); - if_ok!(end(s)); - if_ok!(maybe_print_trailing_comment(s, v.span, None)); + try!(space_if_not_bol(s)); + try!(maybe_print_comment(s, v.span.lo)); + try!(print_outer_attributes(s, v.node.attrs)); + try!(ibox(s, indent_unit)); + try!(print_variant(s, v)); + try!(word(&mut s.s, ",")); + try!(end(s)); + try!(maybe_print_trailing_comment(s, v.span, None)); } bclose(s, span) } @@ -745,7 +745,7 @@ pub fn visibility_qualified(vis: ast::Visibility, s: &str) -> ~str { pub fn print_visibility(s: &mut State, vis: ast::Visibility) -> io::IoResult<()> { match vis { ast::Private | ast::Public => - if_ok!(word_nbsp(s, visibility_to_str(vis))), + try!(word_nbsp(s, visibility_to_str(vis))), ast::Inherited => () } Ok(()) @@ -756,43 +756,43 @@ pub fn print_struct(s: &mut State, generics: &ast::Generics, ident: ast::Ident, span: codemap::Span) -> io::IoResult<()> { - if_ok!(print_ident(s, ident)); - if_ok!(print_generics(s, generics)); + try!(print_ident(s, ident)); + try!(print_generics(s, generics)); if ast_util::struct_def_is_tuple_like(struct_def) { if !struct_def.fields.is_empty() { - if_ok!(popen(s)); - if_ok!(commasep(s, Inconsistent, struct_def.fields, |s, field| { + try!(popen(s)); + try!(commasep(s, Inconsistent, struct_def.fields, |s, field| { match field.node.kind { ast::NamedField(..) => fail!("unexpected named field"), ast::UnnamedField => { - if_ok!(maybe_print_comment(s, field.span.lo)); - if_ok!(print_type(s, field.node.ty)); + try!(maybe_print_comment(s, field.span.lo)); + try!(print_type(s, field.node.ty)); } } Ok(()) })); - if_ok!(pclose(s)); + try!(pclose(s)); } - if_ok!(word(&mut s.s, ";")); - if_ok!(end(s)); + try!(word(&mut s.s, ";")); + try!(end(s)); end(s) // close the outer-box } else { - if_ok!(nbsp(s)); - if_ok!(bopen(s)); - if_ok!(hardbreak_if_not_bol(s)); + try!(nbsp(s)); + try!(bopen(s)); + try!(hardbreak_if_not_bol(s)); for field in struct_def.fields.iter() { match field.node.kind { ast::UnnamedField => fail!("unexpected unnamed field"), ast::NamedField(ident, visibility) => { - if_ok!(hardbreak_if_not_bol(s)); - if_ok!(maybe_print_comment(s, field.span.lo)); - if_ok!(print_outer_attributes(s, field.node.attrs)); - if_ok!(print_visibility(s, visibility)); - if_ok!(print_ident(s, ident)); - if_ok!(word_nbsp(s, ":")); - if_ok!(print_type(s, field.node.ty)); - if_ok!(word(&mut s.s, ",")); + try!(hardbreak_if_not_bol(s)); + try!(maybe_print_comment(s, field.span.lo)); + try!(print_outer_attributes(s, field.node.attrs)); + try!(print_visibility(s, visibility)); + try!(print_ident(s, ident)); + try!(word_nbsp(s, ":")); + try!(print_type(s, field.node.ty)); + try!(word(&mut s.s, ",")); } } } @@ -815,63 +815,63 @@ pub fn print_tt(s: &mut State, tt: &ast::TokenTree) -> io::IoResult<()> { word(&mut s.s, parse::token::to_str(tk)) } ast::TTSeq(_, ref tts, ref sep, zerok) => { - if_ok!(word(&mut s.s, "$(")); + try!(word(&mut s.s, "$(")); for tt_elt in (*tts).iter() { - if_ok!(print_tt(s, tt_elt)); + try!(print_tt(s, tt_elt)); } - if_ok!(word(&mut s.s, ")")); + try!(word(&mut s.s, ")")); match *sep { Some(ref tk) => { - if_ok!(word(&mut s.s, parse::token::to_str(tk))); + try!(word(&mut s.s, parse::token::to_str(tk))); } None => () } word(&mut s.s, if zerok { "*" } else { "+" }) } ast::TTNonterminal(_, name) => { - if_ok!(word(&mut s.s, "$")); + try!(word(&mut s.s, "$")); print_ident(s, name) } } } pub fn print_tts(s: &mut State, tts: & &[ast::TokenTree]) -> io::IoResult<()> { - if_ok!(ibox(s, 0)); + try!(ibox(s, 0)); for (i, tt) in tts.iter().enumerate() { if i != 0 { - if_ok!(space(&mut s.s)); + try!(space(&mut s.s)); } - if_ok!(print_tt(s, tt)); + try!(print_tt(s, tt)); } end(s) } pub fn print_variant(s: &mut State, v: &ast::Variant) -> io::IoResult<()> { - if_ok!(print_visibility(s, v.node.vis)); + try!(print_visibility(s, v.node.vis)); match v.node.kind { ast::TupleVariantKind(ref args) => { - if_ok!(print_ident(s, v.node.name)); + try!(print_ident(s, v.node.name)); if !args.is_empty() { - if_ok!(popen(s)); + try!(popen(s)); fn print_variant_arg(s: &mut State, arg: &ast::VariantArg) -> io::IoResult<()> { print_type(s, arg.ty) } - if_ok!(commasep(s, Consistent, *args, print_variant_arg)); - if_ok!(pclose(s)); + try!(commasep(s, Consistent, *args, print_variant_arg)); + try!(pclose(s)); } } ast::StructVariantKind(struct_def) => { - if_ok!(head(s, "")); + try!(head(s, "")); let generics = ast_util::empty_generics(); - if_ok!(print_struct(s, struct_def, &generics, v.node.name, v.span)); + try!(print_struct(s, struct_def, &generics, v.node.name, v.span)); } } match v.node.disr_expr { Some(d) => { - if_ok!(space(&mut s.s)); - if_ok!(word_space(s, "=")); - if_ok!(print_expr(s, d)); + try!(space(&mut s.s)); + try!(word_space(s, "=")); + try!(print_expr(s, d)); } _ => () } @@ -879,10 +879,10 @@ pub fn print_variant(s: &mut State, v: &ast::Variant) -> io::IoResult<()> { } pub fn print_ty_method(s: &mut State, m: &ast::TypeMethod) -> io::IoResult<()> { - if_ok!(hardbreak_if_not_bol(s)); - if_ok!(maybe_print_comment(s, m.span.lo)); - if_ok!(print_outer_attributes(s, m.attrs)); - if_ok!(print_ty_fn(s, + try!(hardbreak_if_not_bol(s)); + try!(maybe_print_comment(s, m.span.lo)); + try!(print_outer_attributes(s, m.attrs)); + try!(print_ty_fn(s, None, None, &None, @@ -905,13 +905,13 @@ pub fn print_trait_method(s: &mut State, } pub fn print_method(s: &mut State, meth: &ast::Method) -> io::IoResult<()> { - if_ok!(hardbreak_if_not_bol(s)); - if_ok!(maybe_print_comment(s, meth.span.lo)); - if_ok!(print_outer_attributes(s, meth.attrs)); - if_ok!(print_fn(s, meth.decl, Some(meth.purity), AbiSet::Rust(), + try!(hardbreak_if_not_bol(s)); + try!(maybe_print_comment(s, meth.span.lo)); + try!(print_outer_attributes(s, meth.attrs)); + try!(print_fn(s, meth.decl, Some(meth.purity), AbiSet::Rust(), meth.ident, &meth.generics, Some(meth.explicit_self.node), meth.vis)); - if_ok!(word(&mut s.s, " ")); + try!(word(&mut s.s, " ")); print_block_with_attrs(s, meth.body, meth.attrs) } @@ -921,14 +921,14 @@ pub fn print_outer_attributes(s: &mut State, for attr in attrs.iter() { match attr.node.style { ast::AttrOuter => { - if_ok!(print_attribute(s, attr)); + try!(print_attribute(s, attr)); count += 1; } _ => {/* fallthrough */ } } } if count > 0 { - if_ok!(hardbreak_if_not_bol(s)); + try!(hardbreak_if_not_bol(s)); } Ok(()) } @@ -939,9 +939,9 @@ pub fn print_inner_attributes(s: &mut State, for attr in attrs.iter() { match attr.node.style { ast::AttrInner => { - if_ok!(print_attribute(s, attr)); + try!(print_attribute(s, attr)); if !attr.node.is_sugared_doc { - if_ok!(word(&mut s.s, ";")); + try!(word(&mut s.s, ";")); } count += 1; } @@ -949,51 +949,51 @@ pub fn print_inner_attributes(s: &mut State, } } if count > 0 { - if_ok!(hardbreak_if_not_bol(s)); + try!(hardbreak_if_not_bol(s)); } Ok(()) } pub fn print_attribute(s: &mut State, attr: &ast::Attribute) -> io::IoResult<()> { - if_ok!(hardbreak_if_not_bol(s)); - if_ok!(maybe_print_comment(s, attr.span.lo)); + try!(hardbreak_if_not_bol(s)); + try!(maybe_print_comment(s, attr.span.lo)); if attr.node.is_sugared_doc { let comment = attr.value_str().unwrap(); - if_ok!(word(&mut s.s, comment.get())); + try!(word(&mut s.s, comment.get())); } else { - if_ok!(word(&mut s.s, "#[")); - if_ok!(print_meta_item(s, attr.meta())); - if_ok!(word(&mut s.s, "]")); + try!(word(&mut s.s, "#[")); + try!(print_meta_item(s, attr.meta())); + try!(word(&mut s.s, "]")); } Ok(()) } pub fn print_stmt(s: &mut State, st: &ast::Stmt) -> io::IoResult<()> { - if_ok!(maybe_print_comment(s, st.span.lo)); + try!(maybe_print_comment(s, st.span.lo)); match st.node { ast::StmtDecl(decl, _) => { - if_ok!(print_decl(s, decl)); + try!(print_decl(s, decl)); } ast::StmtExpr(expr, _) => { - if_ok!(space_if_not_bol(s)); - if_ok!(print_expr(s, expr)); + try!(space_if_not_bol(s)); + try!(print_expr(s, expr)); } ast::StmtSemi(expr, _) => { - if_ok!(space_if_not_bol(s)); - if_ok!(print_expr(s, expr)); - if_ok!(word(&mut s.s, ";")); + try!(space_if_not_bol(s)); + try!(print_expr(s, expr)); + try!(word(&mut s.s, ";")); } ast::StmtMac(ref mac, semi) => { - if_ok!(space_if_not_bol(s)); - if_ok!(print_mac(s, mac)); + try!(space_if_not_bol(s)); + try!(print_mac(s, mac)); if semi { - if_ok!(word(&mut s.s, ";")); + try!(word(&mut s.s, ";")); } } } if parse::classify::stmt_ends_with_semi(st) { - if_ok!(word(&mut s.s, ";")); + try!(word(&mut s.s, ";")); } maybe_print_trailing_comment(s, st.span, None) } @@ -1039,70 +1039,70 @@ pub fn print_possibly_embedded_block_(s: &mut State, attrs: &[ast::Attribute], close_box: bool) -> io::IoResult<()> { match blk.rules { - ast::UnsafeBlock(..) => if_ok!(word_space(s, "unsafe")), + ast::UnsafeBlock(..) => try!(word_space(s, "unsafe")), ast::DefaultBlock => () } - if_ok!(maybe_print_comment(s, blk.span.lo)); + try!(maybe_print_comment(s, blk.span.lo)); { let ann_node = NodeBlock(s, blk); - if_ok!(s.ann.pre(ann_node)); + try!(s.ann.pre(ann_node)); } - if_ok!(match embedded { + try!(match embedded { BlockBlockFn => end(s), BlockNormal => bopen(s) }); - if_ok!(print_inner_attributes(s, attrs)); + try!(print_inner_attributes(s, attrs)); for vi in blk.view_items.iter() { - if_ok!(print_view_item(s, vi)); + try!(print_view_item(s, vi)); } for st in blk.stmts.iter() { - if_ok!(print_stmt(s, *st)); + try!(print_stmt(s, *st)); } match blk.expr { Some(expr) => { - if_ok!(space_if_not_bol(s)); - if_ok!(print_expr(s, expr)); - if_ok!(maybe_print_trailing_comment(s, expr.span, Some(blk.span.hi))); + try!(space_if_not_bol(s)); + try!(print_expr(s, expr)); + try!(maybe_print_trailing_comment(s, expr.span, Some(blk.span.hi))); } _ => () } - if_ok!(bclose_maybe_open(s, blk.span, indented, close_box)); + try!(bclose_maybe_open(s, blk.span, indented, close_box)); { let ann_node = NodeBlock(s, blk); - if_ok!(s.ann.post(ann_node)); + try!(s.ann.post(ann_node)); } Ok(()) } pub fn print_if(s: &mut State, test: &ast::Expr, blk: &ast::Block, elseopt: Option<@ast::Expr>, chk: bool) -> io::IoResult<()> { - if_ok!(head(s, "if")); - if chk { if_ok!(word_nbsp(s, "check")); } - if_ok!(print_expr(s, test)); - if_ok!(space(&mut s.s)); - if_ok!(print_block(s, blk)); + try!(head(s, "if")); + if chk { try!(word_nbsp(s, "check")); } + try!(print_expr(s, test)); + try!(space(&mut s.s)); + try!(print_block(s, blk)); fn do_else(s: &mut State, els: Option<@ast::Expr>) -> io::IoResult<()> { match els { Some(_else) => { match _else.node { // "another else-if" ast::ExprIf(i, t, e) => { - if_ok!(cbox(s, indent_unit - 1u)); - if_ok!(ibox(s, 0u)); - if_ok!(word(&mut s.s, " else if ")); - if_ok!(print_expr(s, i)); - if_ok!(space(&mut s.s)); - if_ok!(print_block(s, t)); - if_ok!(do_else(s, e)); + try!(cbox(s, indent_unit - 1u)); + try!(ibox(s, 0u)); + try!(word(&mut s.s, " else if ")); + try!(print_expr(s, i)); + try!(space(&mut s.s)); + try!(print_block(s, t)); + try!(do_else(s, e)); } // "final else" ast::ExprBlock(b) => { - if_ok!(cbox(s, indent_unit - 1u)); - if_ok!(ibox(s, 0u)); - if_ok!(word(&mut s.s, " else ")); - if_ok!(print_block(s, b)); + try!(cbox(s, indent_unit - 1u)); + try!(ibox(s, 0u)); + try!(word(&mut s.s, " else ")); + try!(print_block(s, b)); } // BLEAH, constraints would be great here _ => { @@ -1121,10 +1121,10 @@ pub fn print_mac(s: &mut State, m: &ast::Mac) -> io::IoResult<()> { match m.node { // I think it's reasonable to hide the ctxt here: ast::MacInvocTT(ref pth, ref tts, _) => { - if_ok!(print_path(s, pth, false)); - if_ok!(word(&mut s.s, "!")); - if_ok!(popen(s)); - if_ok!(print_tts(s, &tts.as_slice())); + try!(print_path(s, pth, false)); + try!(word(&mut s.s, "!")); + try!(popen(s)); + try!(print_tts(s, &tts.as_slice())); pclose(s) } } @@ -1135,210 +1135,210 @@ pub fn print_expr_vstore(s: &mut State, t: ast::ExprVstore) -> io::IoResult<()> ast::ExprVstoreUniq => word(&mut s.s, "~"), ast::ExprVstoreSlice => word(&mut s.s, "&"), ast::ExprVstoreMutSlice => { - if_ok!(word(&mut s.s, "&")); + try!(word(&mut s.s, "&")); word(&mut s.s, "mut") } } } fn print_call_post(s: &mut State, args: &[@ast::Expr]) -> io::IoResult<()> { - if_ok!(popen(s)); - if_ok!(commasep_exprs(s, Inconsistent, args)); - if_ok!(pclose(s)); + try!(popen(s)); + try!(commasep_exprs(s, Inconsistent, args)); + try!(pclose(s)); Ok(()) } pub fn print_expr(s: &mut State, expr: &ast::Expr) -> io::IoResult<()> { fn print_field(s: &mut State, field: &ast::Field) -> io::IoResult<()> { - if_ok!(ibox(s, indent_unit)); - if_ok!(print_ident(s, field.ident.node)); - if_ok!(word_space(s, ":")); - if_ok!(print_expr(s, field.expr)); - if_ok!(end(s)); + try!(ibox(s, indent_unit)); + try!(print_ident(s, field.ident.node)); + try!(word_space(s, ":")); + try!(print_expr(s, field.expr)); + try!(end(s)); Ok(()) } fn get_span(field: &ast::Field) -> codemap::Span { return field.span; } - if_ok!(maybe_print_comment(s, expr.span.lo)); - if_ok!(ibox(s, indent_unit)); + try!(maybe_print_comment(s, expr.span.lo)); + try!(ibox(s, indent_unit)); { let ann_node = NodeExpr(s, expr); - if_ok!(s.ann.pre(ann_node)); + try!(s.ann.pre(ann_node)); } match expr.node { ast::ExprVstore(e, v) => { - if_ok!(print_expr_vstore(s, v)); - if_ok!(print_expr(s, e)); + try!(print_expr_vstore(s, v)); + try!(print_expr(s, e)); }, ast::ExprBox(p, e) => { - if_ok!(word(&mut s.s, "box")); - if_ok!(word(&mut s.s, "(")); - if_ok!(print_expr(s, p)); - if_ok!(word_space(s, ")")); - if_ok!(print_expr(s, e)); + try!(word(&mut s.s, "box")); + try!(word(&mut s.s, "(")); + try!(print_expr(s, p)); + try!(word_space(s, ")")); + try!(print_expr(s, e)); } ast::ExprVec(ref exprs, mutbl) => { - if_ok!(ibox(s, indent_unit)); - if_ok!(word(&mut s.s, "[")); + try!(ibox(s, indent_unit)); + try!(word(&mut s.s, "[")); if mutbl == ast::MutMutable { - if_ok!(word(&mut s.s, "mut")); - if exprs.len() > 0u { if_ok!(nbsp(s)); } + try!(word(&mut s.s, "mut")); + if exprs.len() > 0u { try!(nbsp(s)); } } - if_ok!(commasep_exprs(s, Inconsistent, *exprs)); - if_ok!(word(&mut s.s, "]")); - if_ok!(end(s)); + try!(commasep_exprs(s, Inconsistent, *exprs)); + try!(word(&mut s.s, "]")); + try!(end(s)); } ast::ExprRepeat(element, count, mutbl) => { - if_ok!(ibox(s, indent_unit)); - if_ok!(word(&mut s.s, "[")); + try!(ibox(s, indent_unit)); + try!(word(&mut s.s, "[")); if mutbl == ast::MutMutable { - if_ok!(word(&mut s.s, "mut")); - if_ok!(nbsp(s)); + try!(word(&mut s.s, "mut")); + try!(nbsp(s)); } - if_ok!(print_expr(s, element)); - if_ok!(word(&mut s.s, ",")); - if_ok!(word(&mut s.s, "..")); - if_ok!(print_expr(s, count)); - if_ok!(word(&mut s.s, "]")); - if_ok!(end(s)); + try!(print_expr(s, element)); + try!(word(&mut s.s, ",")); + try!(word(&mut s.s, "..")); + try!(print_expr(s, count)); + try!(word(&mut s.s, "]")); + try!(end(s)); } ast::ExprStruct(ref path, ref fields, wth) => { - if_ok!(print_path(s, path, true)); - if_ok!(word(&mut s.s, "{")); - if_ok!(commasep_cmnt(s, Consistent, (*fields), print_field, get_span)); + try!(print_path(s, path, true)); + try!(word(&mut s.s, "{")); + try!(commasep_cmnt(s, Consistent, (*fields), print_field, get_span)); match wth { Some(expr) => { - if_ok!(ibox(s, indent_unit)); + try!(ibox(s, indent_unit)); if !fields.is_empty() { - if_ok!(word(&mut s.s, ",")); - if_ok!(space(&mut s.s)); + try!(word(&mut s.s, ",")); + try!(space(&mut s.s)); } - if_ok!(word(&mut s.s, "..")); - if_ok!(print_expr(s, expr)); - if_ok!(end(s)); + try!(word(&mut s.s, "..")); + try!(print_expr(s, expr)); + try!(end(s)); } - _ => if_ok!(word(&mut s.s, ",")) + _ => try!(word(&mut s.s, ",")) } - if_ok!(word(&mut s.s, "}")); + try!(word(&mut s.s, "}")); } ast::ExprTup(ref exprs) => { - if_ok!(popen(s)); - if_ok!(commasep_exprs(s, Inconsistent, *exprs)); + try!(popen(s)); + try!(commasep_exprs(s, Inconsistent, *exprs)); if exprs.len() == 1 { - if_ok!(word(&mut s.s, ",")); + try!(word(&mut s.s, ",")); } - if_ok!(pclose(s)); + try!(pclose(s)); } ast::ExprCall(func, ref args) => { - if_ok!(print_expr(s, func)); - if_ok!(print_call_post(s, *args)); + try!(print_expr(s, func)); + try!(print_call_post(s, *args)); } ast::ExprMethodCall(_, ident, ref tys, ref args) => { let base_args = args.slice_from(1); - if_ok!(print_expr(s, args[0])); - if_ok!(word(&mut s.s, ".")); - if_ok!(print_ident(s, ident)); + try!(print_expr(s, args[0])); + try!(word(&mut s.s, ".")); + try!(print_ident(s, ident)); if tys.len() > 0u { - if_ok!(word(&mut s.s, "::<")); - if_ok!(commasep(s, Inconsistent, *tys, print_type_ref)); - if_ok!(word(&mut s.s, ">")); + try!(word(&mut s.s, "::<")); + try!(commasep(s, Inconsistent, *tys, print_type_ref)); + try!(word(&mut s.s, ">")); } - if_ok!(print_call_post(s, base_args)); + try!(print_call_post(s, base_args)); } ast::ExprBinary(_, op, lhs, rhs) => { - if_ok!(print_expr(s, lhs)); - if_ok!(space(&mut s.s)); - if_ok!(word_space(s, ast_util::binop_to_str(op))); - if_ok!(print_expr(s, rhs)); + try!(print_expr(s, lhs)); + try!(space(&mut s.s)); + try!(word_space(s, ast_util::binop_to_str(op))); + try!(print_expr(s, rhs)); } ast::ExprUnary(_, op, expr) => { - if_ok!(word(&mut s.s, ast_util::unop_to_str(op))); - if_ok!(print_expr(s, expr)); + try!(word(&mut s.s, ast_util::unop_to_str(op))); + try!(print_expr(s, expr)); } ast::ExprAddrOf(m, expr) => { - if_ok!(word(&mut s.s, "&")); - if_ok!(print_mutability(s, m)); + try!(word(&mut s.s, "&")); + try!(print_mutability(s, m)); // Avoid `& &e` => `&&e`. match (m, &expr.node) { - (ast::MutImmutable, &ast::ExprAddrOf(..)) => if_ok!(space(&mut s.s)), + (ast::MutImmutable, &ast::ExprAddrOf(..)) => try!(space(&mut s.s)), _ => { } } - if_ok!(print_expr(s, expr)); + try!(print_expr(s, expr)); } - ast::ExprLit(lit) => if_ok!(print_literal(s, lit)), + ast::ExprLit(lit) => try!(print_literal(s, lit)), ast::ExprCast(expr, ty) => { - if_ok!(print_expr(s, expr)); - if_ok!(space(&mut s.s)); - if_ok!(word_space(s, "as")); - if_ok!(print_type(s, ty)); + try!(print_expr(s, expr)); + try!(space(&mut s.s)); + try!(word_space(s, "as")); + try!(print_type(s, ty)); } ast::ExprIf(test, blk, elseopt) => { - if_ok!(print_if(s, test, blk, elseopt, false)); + try!(print_if(s, test, blk, elseopt, false)); } ast::ExprWhile(test, blk) => { - if_ok!(head(s, "while")); - if_ok!(print_expr(s, test)); - if_ok!(space(&mut s.s)); - if_ok!(print_block(s, blk)); + try!(head(s, "while")); + try!(print_expr(s, test)); + try!(space(&mut s.s)); + try!(print_block(s, blk)); } ast::ExprForLoop(pat, iter, blk, opt_ident) => { for ident in opt_ident.iter() { - if_ok!(word(&mut s.s, "'")); - if_ok!(print_ident(s, *ident)); - if_ok!(word_space(s, ":")); + try!(word(&mut s.s, "'")); + try!(print_ident(s, *ident)); + try!(word_space(s, ":")); } - if_ok!(head(s, "for")); - if_ok!(print_pat(s, pat)); - if_ok!(space(&mut s.s)); - if_ok!(word_space(s, "in")); - if_ok!(print_expr(s, iter)); - if_ok!(space(&mut s.s)); - if_ok!(print_block(s, blk)); + try!(head(s, "for")); + try!(print_pat(s, pat)); + try!(space(&mut s.s)); + try!(word_space(s, "in")); + try!(print_expr(s, iter)); + try!(space(&mut s.s)); + try!(print_block(s, blk)); } ast::ExprLoop(blk, opt_ident) => { for ident in opt_ident.iter() { - if_ok!(word(&mut s.s, "'")); - if_ok!(print_ident(s, *ident)); - if_ok!(word_space(s, ":")); + try!(word(&mut s.s, "'")); + try!(print_ident(s, *ident)); + try!(word_space(s, ":")); } - if_ok!(head(s, "loop")); - if_ok!(space(&mut s.s)); - if_ok!(print_block(s, blk)); + try!(head(s, "loop")); + try!(space(&mut s.s)); + try!(print_block(s, blk)); } ast::ExprMatch(expr, ref arms) => { - if_ok!(cbox(s, indent_unit)); - if_ok!(ibox(s, 4)); - if_ok!(word_nbsp(s, "match")); - if_ok!(print_expr(s, expr)); - if_ok!(space(&mut s.s)); - if_ok!(bopen(s)); + try!(cbox(s, indent_unit)); + try!(ibox(s, 4)); + try!(word_nbsp(s, "match")); + try!(print_expr(s, expr)); + try!(space(&mut s.s)); + try!(bopen(s)); let len = arms.len(); for (i, arm) in arms.iter().enumerate() { - if_ok!(space(&mut s.s)); - if_ok!(cbox(s, indent_unit)); - if_ok!(ibox(s, 0u)); + try!(space(&mut s.s)); + try!(cbox(s, indent_unit)); + try!(ibox(s, 0u)); let mut first = true; for p in arm.pats.iter() { if first { first = false; } else { - if_ok!(space(&mut s.s)); - if_ok!(word_space(s, "|")); + try!(space(&mut s.s)); + try!(word_space(s, "|")); } - if_ok!(print_pat(s, *p)); + try!(print_pat(s, *p)); } - if_ok!(space(&mut s.s)); + try!(space(&mut s.s)); match arm.guard { Some(e) => { - if_ok!(word_space(s, "if")); - if_ok!(print_expr(s, e)); - if_ok!(space(&mut s.s)); + try!(word_space(s, "if")); + try!(print_expr(s, e)); + try!(space(&mut s.s)); } None => () } - if_ok!(word_space(s, "=>")); + try!(word_space(s, "=>")); // Extract the expression from the extra block the parser adds // in the case of foo => expr @@ -1352,28 +1352,28 @@ pub fn print_expr(s: &mut State, expr: &ast::Expr) -> io::IoResult<()> { match expr.node { ast::ExprBlock(blk) => { // the block will close the pattern's ibox - if_ok!(print_block_unclosed_indent( + try!(print_block_unclosed_indent( s, blk, indent_unit)); } _ => { - if_ok!(end(s)); // close the ibox for the pattern - if_ok!(print_expr(s, expr)); + try!(end(s)); // close the ibox for the pattern + try!(print_expr(s, expr)); } } if !expr_is_simple_block(expr) && i < len - 1 { - if_ok!(word(&mut s.s, ",")); + try!(word(&mut s.s, ",")); } - if_ok!(end(s)); // close enclosing cbox + try!(end(s)); // close enclosing cbox } None => fail!() } } else { // the block will close the pattern's ibox - if_ok!(print_block_unclosed_indent(s, arm.body, indent_unit)); + try!(print_block_unclosed_indent(s, arm.body, indent_unit)); } } - if_ok!(bclose_(s, expr.span, indent_unit)); + try!(bclose_(s, expr.span, indent_unit)); } ast::ExprFnBlock(decl, body) => { // in do/for blocks we don't want to show an empty @@ -1381,26 +1381,26 @@ pub fn print_expr(s: &mut State, expr: &ast::Expr) -> io::IoResult<()> { // we are inside. // // if !decl.inputs.is_empty() { - if_ok!(print_fn_block_args(s, decl)); - if_ok!(space(&mut s.s)); + try!(print_fn_block_args(s, decl)); + try!(space(&mut s.s)); // } assert!(body.stmts.is_empty()); assert!(body.expr.is_some()); // we extract the block, so as not to create another set of boxes match body.expr.unwrap().node { ast::ExprBlock(blk) => { - if_ok!(print_block_unclosed(s, blk)); + try!(print_block_unclosed(s, blk)); } _ => { // this is a bare expression - if_ok!(print_expr(s, body.expr.unwrap())); - if_ok!(end(s)); // need to close a box + try!(print_expr(s, body.expr.unwrap())); + try!(end(s)); // need to close a box } } // a box will be closed by print_expr, but we didn't want an overall // wrapper so we closed the corresponding opening. so create an // empty box to satisfy the close. - if_ok!(ibox(s, 0)); + try!(ibox(s, 0)); } ast::ExprProc(decl, body) => { // in do/for blocks we don't want to show an empty @@ -1408,175 +1408,175 @@ pub fn print_expr(s: &mut State, expr: &ast::Expr) -> io::IoResult<()> { // we are inside. // // if !decl.inputs.is_empty() { - if_ok!(print_proc_args(s, decl)); - if_ok!(space(&mut s.s)); + try!(print_proc_args(s, decl)); + try!(space(&mut s.s)); // } assert!(body.stmts.is_empty()); assert!(body.expr.is_some()); // we extract the block, so as not to create another set of boxes match body.expr.unwrap().node { ast::ExprBlock(blk) => { - if_ok!(print_block_unclosed(s, blk)); + try!(print_block_unclosed(s, blk)); } _ => { // this is a bare expression - if_ok!(print_expr(s, body.expr.unwrap())); - if_ok!(end(s)); // need to close a box + try!(print_expr(s, body.expr.unwrap())); + try!(end(s)); // need to close a box } } // a box will be closed by print_expr, but we didn't want an overall // wrapper so we closed the corresponding opening. so create an // empty box to satisfy the close. - if_ok!(ibox(s, 0)); + try!(ibox(s, 0)); } ast::ExprBlock(blk) => { // containing cbox, will be closed by print-block at } - if_ok!(cbox(s, indent_unit)); + try!(cbox(s, indent_unit)); // head-box, will be closed by print-block after { - if_ok!(ibox(s, 0u)); - if_ok!(print_block(s, blk)); + try!(ibox(s, 0u)); + try!(print_block(s, blk)); } ast::ExprAssign(lhs, rhs) => { - if_ok!(print_expr(s, lhs)); - if_ok!(space(&mut s.s)); - if_ok!(word_space(s, "=")); - if_ok!(print_expr(s, rhs)); + try!(print_expr(s, lhs)); + try!(space(&mut s.s)); + try!(word_space(s, "=")); + try!(print_expr(s, rhs)); } ast::ExprAssignOp(_, op, lhs, rhs) => { - if_ok!(print_expr(s, lhs)); - if_ok!(space(&mut s.s)); - if_ok!(word(&mut s.s, ast_util::binop_to_str(op))); - if_ok!(word_space(s, "=")); - if_ok!(print_expr(s, rhs)); + try!(print_expr(s, lhs)); + try!(space(&mut s.s)); + try!(word(&mut s.s, ast_util::binop_to_str(op))); + try!(word_space(s, "=")); + try!(print_expr(s, rhs)); } ast::ExprField(expr, id, ref tys) => { - if_ok!(print_expr(s, expr)); - if_ok!(word(&mut s.s, ".")); - if_ok!(print_ident(s, id)); + try!(print_expr(s, expr)); + try!(word(&mut s.s, ".")); + try!(print_ident(s, id)); if tys.len() > 0u { - if_ok!(word(&mut s.s, "::<")); - if_ok!(commasep(s, Inconsistent, *tys, print_type_ref)); - if_ok!(word(&mut s.s, ">")); + try!(word(&mut s.s, "::<")); + try!(commasep(s, Inconsistent, *tys, print_type_ref)); + try!(word(&mut s.s, ">")); } } ast::ExprIndex(_, expr, index) => { - if_ok!(print_expr(s, expr)); - if_ok!(word(&mut s.s, "[")); - if_ok!(print_expr(s, index)); - if_ok!(word(&mut s.s, "]")); + try!(print_expr(s, expr)); + try!(word(&mut s.s, "[")); + try!(print_expr(s, index)); + try!(word(&mut s.s, "]")); } - ast::ExprPath(ref path) => if_ok!(print_path(s, path, true)), + ast::ExprPath(ref path) => try!(print_path(s, path, true)), ast::ExprBreak(opt_ident) => { - if_ok!(word(&mut s.s, "break")); - if_ok!(space(&mut s.s)); + try!(word(&mut s.s, "break")); + try!(space(&mut s.s)); for ident in opt_ident.iter() { - if_ok!(word(&mut s.s, "'")); - if_ok!(print_name(s, *ident)); - if_ok!(space(&mut s.s)); + try!(word(&mut s.s, "'")); + try!(print_name(s, *ident)); + try!(space(&mut s.s)); } } ast::ExprAgain(opt_ident) => { - if_ok!(word(&mut s.s, "continue")); - if_ok!(space(&mut s.s)); + try!(word(&mut s.s, "continue")); + try!(space(&mut s.s)); for ident in opt_ident.iter() { - if_ok!(word(&mut s.s, "'")); - if_ok!(print_name(s, *ident)); - if_ok!(space(&mut s.s)) + try!(word(&mut s.s, "'")); + try!(print_name(s, *ident)); + try!(space(&mut s.s)) } } ast::ExprRet(result) => { - if_ok!(word(&mut s.s, "return")); + try!(word(&mut s.s, "return")); match result { Some(expr) => { - if_ok!(word(&mut s.s, " ")); - if_ok!(print_expr(s, expr)); + try!(word(&mut s.s, " ")); + try!(print_expr(s, expr)); } _ => () } } ast::ExprLogLevel => { - if_ok!(word(&mut s.s, "__log_level")); - if_ok!(popen(s)); - if_ok!(pclose(s)); + try!(word(&mut s.s, "__log_level")); + try!(popen(s)); + try!(pclose(s)); } ast::ExprInlineAsm(ref a) => { if a.volatile { - if_ok!(word(&mut s.s, "__volatile__ asm!")); + try!(word(&mut s.s, "__volatile__ asm!")); } else { - if_ok!(word(&mut s.s, "asm!")); + try!(word(&mut s.s, "asm!")); } - if_ok!(popen(s)); - if_ok!(print_string(s, a.asm.get(), a.asm_str_style)); - if_ok!(word_space(s, ":")); + try!(popen(s)); + try!(print_string(s, a.asm.get(), a.asm_str_style)); + try!(word_space(s, ":")); for &(ref co, o) in a.outputs.iter() { - if_ok!(print_string(s, co.get(), ast::CookedStr)); - if_ok!(popen(s)); - if_ok!(print_expr(s, o)); - if_ok!(pclose(s)); - if_ok!(word_space(s, ",")); + try!(print_string(s, co.get(), ast::CookedStr)); + try!(popen(s)); + try!(print_expr(s, o)); + try!(pclose(s)); + try!(word_space(s, ",")); } - if_ok!(word_space(s, ":")); + try!(word_space(s, ":")); for &(ref co, o) in a.inputs.iter() { - if_ok!(print_string(s, co.get(), ast::CookedStr)); - if_ok!(popen(s)); - if_ok!(print_expr(s, o)); - if_ok!(pclose(s)); - if_ok!(word_space(s, ",")); + try!(print_string(s, co.get(), ast::CookedStr)); + try!(popen(s)); + try!(print_expr(s, o)); + try!(pclose(s)); + try!(word_space(s, ",")); } - if_ok!(word_space(s, ":")); - if_ok!(print_string(s, a.clobbers.get(), ast::CookedStr)); - if_ok!(pclose(s)); + try!(word_space(s, ":")); + try!(print_string(s, a.clobbers.get(), ast::CookedStr)); + try!(pclose(s)); } - ast::ExprMac(ref m) => if_ok!(print_mac(s, m)), + ast::ExprMac(ref m) => try!(print_mac(s, m)), ast::ExprParen(e) => { - if_ok!(popen(s)); - if_ok!(print_expr(s, e)); - if_ok!(pclose(s)); + try!(popen(s)); + try!(print_expr(s, e)); + try!(pclose(s)); } } { let ann_node = NodeExpr(s, expr); - if_ok!(s.ann.post(ann_node)); + try!(s.ann.post(ann_node)); } end(s) } pub fn print_local_decl(s: &mut State, loc: &ast::Local) -> io::IoResult<()> { - if_ok!(print_pat(s, loc.pat)); + try!(print_pat(s, loc.pat)); match loc.ty.node { ast::TyInfer => {} _ => { - if_ok!(word_space(s, ":")); - if_ok!(print_type(s, loc.ty)); + try!(word_space(s, ":")); + try!(print_type(s, loc.ty)); } } Ok(()) } pub fn print_decl(s: &mut State, decl: &ast::Decl) -> io::IoResult<()> { - if_ok!(maybe_print_comment(s, decl.span.lo)); + try!(maybe_print_comment(s, decl.span.lo)); match decl.node { ast::DeclLocal(ref loc) => { - if_ok!(space_if_not_bol(s)); - if_ok!(ibox(s, indent_unit)); - if_ok!(word_nbsp(s, "let")); + try!(space_if_not_bol(s)); + try!(ibox(s, indent_unit)); + try!(word_nbsp(s, "let")); fn print_local(s: &mut State, loc: &ast::Local) -> io::IoResult<()> { - if_ok!(ibox(s, indent_unit)); - if_ok!(print_local_decl(s, loc)); - if_ok!(end(s)); + try!(ibox(s, indent_unit)); + try!(print_local_decl(s, loc)); + try!(end(s)); match loc.init { Some(init) => { - if_ok!(nbsp(s)); - if_ok!(word_space(s, "=")); - if_ok!(print_expr(s, init)); + try!(nbsp(s)); + try!(word_space(s, "=")); + try!(print_expr(s, init)); } _ => () } Ok(()) } - if_ok!(print_local(s, *loc)); + try!(print_local(s, *loc)); end(s) } ast::DeclItem(item) => print_item(s, item) @@ -1593,9 +1593,9 @@ pub fn print_name(s: &mut State, name: ast::Name) -> io::IoResult<()> { pub fn print_for_decl(s: &mut State, loc: &ast::Local, coll: &ast::Expr) -> io::IoResult<()> { - if_ok!(print_local_decl(s, loc)); - if_ok!(space(&mut s.s)); - if_ok!(word_space(s, "in")); + try!(print_local_decl(s, loc)); + try!(space(&mut s.s)); + try!(word_space(s, "in")); print_expr(s, coll) } @@ -1605,9 +1605,9 @@ fn print_path_(s: &mut State, opt_bounds: &Option>) -> io::IoResult<()> { - if_ok!(maybe_print_comment(s, path.span.lo)); + try!(maybe_print_comment(s, path.span.lo)); if path.global { - if_ok!(word(&mut s.s, "::")); + try!(word(&mut s.s, "::")); } let mut first = true; @@ -1615,45 +1615,45 @@ fn print_path_(s: &mut State, if first { first = false } else { - if_ok!(word(&mut s.s, "::")) + try!(word(&mut s.s, "::")) } - if_ok!(print_ident(s, segment.identifier)); + try!(print_ident(s, segment.identifier)); // If this is the last segment, print the bounds. if i == path.segments.len() - 1 { match *opt_bounds { None => {} - Some(ref bounds) => if_ok!(print_bounds(s, bounds, true)), + Some(ref bounds) => try!(print_bounds(s, bounds, true)), } } if !segment.lifetimes.is_empty() || !segment.types.is_empty() { if colons_before_params { - if_ok!(word(&mut s.s, "::")) + try!(word(&mut s.s, "::")) } - if_ok!(word(&mut s.s, "<")); + try!(word(&mut s.s, "<")); let mut comma = false; for lifetime in segment.lifetimes.iter() { if comma { - if_ok!(word_space(s, ",")) + try!(word_space(s, ",")) } - if_ok!(print_lifetime(s, lifetime)); + try!(print_lifetime(s, lifetime)); comma = true; } if !segment.types.is_empty() { if comma { - if_ok!(word_space(s, ",")) + try!(word_space(s, ",")) } - if_ok!(commasep(s, + try!(commasep(s, Inconsistent, segment.types.map_to_vec(|&t| t), print_type_ref)); } - if_ok!(word(&mut s.s, ">")) + try!(word(&mut s.s, ">")) } } Ok(()) @@ -1671,115 +1671,115 @@ fn print_bounded_path(s: &mut State, path: &ast::Path, } pub fn print_pat(s: &mut State, pat: &ast::Pat) -> io::IoResult<()> { - if_ok!(maybe_print_comment(s, pat.span.lo)); + try!(maybe_print_comment(s, pat.span.lo)); { let ann_node = NodePat(s, pat); - if_ok!(s.ann.pre(ann_node)); + try!(s.ann.pre(ann_node)); } /* Pat isn't normalized, but the beauty of it is that it doesn't matter */ match pat.node { - ast::PatWild => if_ok!(word(&mut s.s, "_")), - ast::PatWildMulti => if_ok!(word(&mut s.s, "..")), + ast::PatWild => try!(word(&mut s.s, "_")), + ast::PatWildMulti => try!(word(&mut s.s, "..")), ast::PatIdent(binding_mode, ref path, sub) => { match binding_mode { ast::BindByRef(mutbl) => { - if_ok!(word_nbsp(s, "ref")); - if_ok!(print_mutability(s, mutbl)); + try!(word_nbsp(s, "ref")); + try!(print_mutability(s, mutbl)); } ast::BindByValue(ast::MutImmutable) => {} ast::BindByValue(ast::MutMutable) => { - if_ok!(word_nbsp(s, "mut")); + try!(word_nbsp(s, "mut")); } } - if_ok!(print_path(s, path, true)); + try!(print_path(s, path, true)); match sub { Some(p) => { - if_ok!(word(&mut s.s, "@")); - if_ok!(print_pat(s, p)); + try!(word(&mut s.s, "@")); + try!(print_pat(s, p)); } None => () } } ast::PatEnum(ref path, ref args_) => { - if_ok!(print_path(s, path, true)); + try!(print_path(s, path, true)); match *args_ { - None => if_ok!(word(&mut s.s, "(..)")), + None => try!(word(&mut s.s, "(..)")), Some(ref args) => { if !args.is_empty() { - if_ok!(popen(s)); - if_ok!(commasep(s, Inconsistent, *args, + try!(popen(s)); + try!(commasep(s, Inconsistent, *args, |s, &p| print_pat(s, p))); - if_ok!(pclose(s)); + try!(pclose(s)); } else { } } } } ast::PatStruct(ref path, ref fields, etc) => { - if_ok!(print_path(s, path, true)); - if_ok!(word(&mut s.s, "{")); + try!(print_path(s, path, true)); + try!(word(&mut s.s, "{")); fn print_field(s: &mut State, f: &ast::FieldPat) -> io::IoResult<()> { - if_ok!(cbox(s, indent_unit)); - if_ok!(print_ident(s, f.ident)); - if_ok!(word_space(s, ":")); - if_ok!(print_pat(s, f.pat)); - if_ok!(end(s)); + try!(cbox(s, indent_unit)); + try!(print_ident(s, f.ident)); + try!(word_space(s, ":")); + try!(print_pat(s, f.pat)); + try!(end(s)); Ok(()) } fn get_span(f: &ast::FieldPat) -> codemap::Span { return f.pat.span; } - if_ok!(commasep_cmnt(s, Consistent, *fields, + try!(commasep_cmnt(s, Consistent, *fields, |s, f| print_field(s,f), get_span)); if etc { - if fields.len() != 0u { if_ok!(word_space(s, ",")); } - if_ok!(word(&mut s.s, "..")); + if fields.len() != 0u { try!(word_space(s, ",")); } + try!(word(&mut s.s, "..")); } - if_ok!(word(&mut s.s, "}")); + try!(word(&mut s.s, "}")); } ast::PatTup(ref elts) => { - if_ok!(popen(s)); - if_ok!(commasep(s, Inconsistent, *elts, |s, &p| print_pat(s, p))); + try!(popen(s)); + try!(commasep(s, Inconsistent, *elts, |s, &p| print_pat(s, p))); if elts.len() == 1 { - if_ok!(word(&mut s.s, ",")); + try!(word(&mut s.s, ",")); } - if_ok!(pclose(s)); + try!(pclose(s)); } ast::PatUniq(inner) => { - if_ok!(word(&mut s.s, "~")); - if_ok!(print_pat(s, inner)); + try!(word(&mut s.s, "~")); + try!(print_pat(s, inner)); } ast::PatRegion(inner) => { - if_ok!(word(&mut s.s, "&")); - if_ok!(print_pat(s, inner)); + try!(word(&mut s.s, "&")); + try!(print_pat(s, inner)); } - ast::PatLit(e) => if_ok!(print_expr(s, e)), + ast::PatLit(e) => try!(print_expr(s, e)), ast::PatRange(begin, end) => { - if_ok!(print_expr(s, begin)); - if_ok!(space(&mut s.s)); - if_ok!(word(&mut s.s, "..")); - if_ok!(print_expr(s, end)); + try!(print_expr(s, begin)); + try!(space(&mut s.s)); + try!(word(&mut s.s, "..")); + try!(print_expr(s, end)); } ast::PatVec(ref before, slice, ref after) => { - if_ok!(word(&mut s.s, "[")); - if_ok!(commasep(s, Inconsistent, *before, |s, &p| print_pat(s, p))); + try!(word(&mut s.s, "[")); + try!(commasep(s, Inconsistent, *before, |s, &p| print_pat(s, p))); for &p in slice.iter() { - if !before.is_empty() { if_ok!(word_space(s, ",")); } + if !before.is_empty() { try!(word_space(s, ",")); } match *p { ast::Pat { node: ast::PatWildMulti, .. } => { // this case is handled by print_pat } - _ => if_ok!(word(&mut s.s, "..")), + _ => try!(word(&mut s.s, "..")), } - if_ok!(print_pat(s, p)); - if !after.is_empty() { if_ok!(word_space(s, ",")); } + try!(print_pat(s, p)); + if !after.is_empty() { try!(word_space(s, ",")); } } - if_ok!(commasep(s, Inconsistent, *after, |s, &p| print_pat(s, p))); - if_ok!(word(&mut s.s, "]")); + try!(commasep(s, Inconsistent, *after, |s, &p| print_pat(s, p))); + try!(word(&mut s.s, "]")); } } { let ann_node = NodePat(s, pat); - if_ok!(s.ann.post(ann_node)); + try!(s.ann.post(ann_node)); } Ok(()) } @@ -1794,20 +1794,20 @@ pub fn explicit_self_to_str(explicit_self: &ast::ExplicitSelf_) -> ~str { fn print_explicit_self(s: &mut State, explicit_self: ast::ExplicitSelf_, mutbl: ast::Mutability) -> io::IoResult { - if_ok!(print_mutability(s, mutbl)); + try!(print_mutability(s, mutbl)); match explicit_self { ast::SelfStatic => { return Ok(false); } ast::SelfValue => { - if_ok!(word(&mut s.s, "self")); + try!(word(&mut s.s, "self")); } ast::SelfUniq => { - if_ok!(word(&mut s.s, "~self")); + try!(word(&mut s.s, "~self")); } ast::SelfRegion(ref lt, m) => { - if_ok!(word(&mut s.s, "&")); - if_ok!(print_opt_lifetime(s, lt)); - if_ok!(print_mutability(s, m)); - if_ok!(word(&mut s.s, "self")); + try!(word(&mut s.s, "&")); + try!(print_opt_lifetime(s, lt)); + try!(print_mutability(s, m)); + try!(word(&mut s.s, "self")); } } return Ok(true); @@ -1821,13 +1821,13 @@ pub fn print_fn(s: &mut State, generics: &ast::Generics, opt_explicit_self: Option, vis: ast::Visibility) -> io::IoResult<()> { - if_ok!(head(s, "")); - if_ok!(print_fn_header_info(s, opt_explicit_self, purity, abis, + try!(head(s, "")); + try!(print_fn_header_info(s, opt_explicit_self, purity, abis, ast::Many, None, vis)); - if_ok!(nbsp(s)); - if_ok!(print_ident(s, name)); - if_ok!(print_generics(s, generics)); - if_ok!(print_fn_args_and_ret(s, decl, opt_explicit_self)); + try!(nbsp(s)); + try!(print_ident(s, name)); + try!(print_generics(s, generics)); + try!(print_fn_args_and_ret(s, decl, opt_explicit_self)); Ok(()) } @@ -1837,7 +1837,7 @@ pub fn print_fn_args(s: &mut State, decl: &ast::FnDecl, { // It is unfortunate to duplicate the commasep logic, but we want the // self type and the args all in the same box. - if_ok!(rbox(s, 0u, Inconsistent)); + try!(rbox(s, 0u, Inconsistent)); let mut first = true; for &explicit_self in opt_explicit_self.iter() { let m = match explicit_self { @@ -1847,7 +1847,7 @@ pub fn print_fn_args(s: &mut State, decl: &ast::FnDecl, _ => ast::MutImmutable } }; - first = !if_ok!(print_explicit_self(s, explicit_self, m)); + first = !try!(print_explicit_self(s, explicit_self, m)); } // HACK(eddyb) ignore the separately printed self argument. @@ -1858,8 +1858,8 @@ pub fn print_fn_args(s: &mut State, decl: &ast::FnDecl, }; for arg in args.iter() { - if first { first = false; } else { if_ok!(word_space(s, ",")); } - if_ok!(print_arg(s, arg)); + if first { first = false; } else { try!(word_space(s, ",")); } + try!(print_arg(s, arg)); } end(s) @@ -1869,20 +1869,20 @@ pub fn print_fn_args_and_ret(s: &mut State, decl: &ast::FnDecl, opt_explicit_self: Option) -> io::IoResult<()> { - if_ok!(popen(s)); - if_ok!(print_fn_args(s, decl, opt_explicit_self)); + try!(popen(s)); + try!(print_fn_args(s, decl, opt_explicit_self)); if decl.variadic { - if_ok!(word(&mut s.s, ", ...")); + try!(word(&mut s.s, ", ...")); } - if_ok!(pclose(s)); + try!(pclose(s)); - if_ok!(maybe_print_comment(s, decl.output.span.lo)); + try!(maybe_print_comment(s, decl.output.span.lo)); match decl.output.node { ast::TyNil => {} _ => { - if_ok!(space_if_not_bol(s)); - if_ok!(word_space(s, "->")); - if_ok!(print_type(s, decl.output)); + try!(space_if_not_bol(s)); + try!(word_space(s, "->")); + try!(print_type(s, decl.output)); } } Ok(()) @@ -1890,16 +1890,16 @@ pub fn print_fn_args_and_ret(s: &mut State, decl: &ast::FnDecl, pub fn print_fn_block_args(s: &mut State, decl: &ast::FnDecl) -> io::IoResult<()> { - if_ok!(word(&mut s.s, "|")); - if_ok!(print_fn_args(s, decl, None)); - if_ok!(word(&mut s.s, "|")); + try!(word(&mut s.s, "|")); + try!(print_fn_args(s, decl, None)); + try!(word(&mut s.s, "|")); match decl.output.node { ast::TyInfer => {} _ => { - if_ok!(space_if_not_bol(s)); - if_ok!(word_space(s, "->")); - if_ok!(print_type(s, decl.output)); + try!(space_if_not_bol(s)); + try!(word_space(s, "->")); + try!(print_type(s, decl.output)); } } @@ -1907,17 +1907,17 @@ pub fn print_fn_block_args(s: &mut State, } pub fn print_proc_args(s: &mut State, decl: &ast::FnDecl) -> io::IoResult<()> { - if_ok!(word(&mut s.s, "proc")); - if_ok!(word(&mut s.s, "(")); - if_ok!(print_fn_args(s, decl, None)); - if_ok!(word(&mut s.s, ")")); + try!(word(&mut s.s, "proc")); + try!(word(&mut s.s, "(")); + try!(print_fn_args(s, decl, None)); + try!(word(&mut s.s, ")")); match decl.output.node { ast::TyInfer => {} _ => { - if_ok!(space_if_not_bol(s)); - if_ok!(word_space(s, "->")); - if_ok!(print_type(s, decl.output)); + try!(space_if_not_bol(s)); + try!(word_space(s, "->")); + try!(print_type(s, decl.output)); } } @@ -1927,30 +1927,30 @@ pub fn print_proc_args(s: &mut State, decl: &ast::FnDecl) -> io::IoResult<()> { pub fn print_bounds(s: &mut State, bounds: &OptVec, print_colon_anyway: bool) -> io::IoResult<()> { if !bounds.is_empty() { - if_ok!(word(&mut s.s, ":")); + try!(word(&mut s.s, ":")); let mut first = true; for bound in bounds.iter() { - if_ok!(nbsp(s)); + try!(nbsp(s)); if first { first = false; } else { - if_ok!(word_space(s, "+")); + try!(word_space(s, "+")); } - if_ok!(match *bound { + try!(match *bound { TraitTyParamBound(ref tref) => print_trait_ref(s, tref), RegionTyParamBound => word(&mut s.s, "'static"), }) } } else if print_colon_anyway { - if_ok!(word(&mut s.s, ":")); + try!(word(&mut s.s, ":")); } Ok(()) } pub fn print_lifetime(s: &mut State, lifetime: &ast::Lifetime) -> io::IoResult<()> { - if_ok!(word(&mut s.s, "'")); + try!(word(&mut s.s, "'")); print_ident(s, lifetime.ident) } @@ -1958,7 +1958,7 @@ pub fn print_generics(s: &mut State, generics: &ast::Generics) -> io::IoResult<()> { let total = generics.lifetimes.len() + generics.ty_params.len(); if total > 0 { - if_ok!(word(&mut s.s, "<")); + try!(word(&mut s.s, "<")); fn print_item(s: &mut State, generics: &ast::Generics, idx: uint) -> io::IoResult<()> { if idx < generics.lifetimes.len() { @@ -1967,13 +1967,13 @@ pub fn print_generics(s: &mut State, } else { let idx = idx - generics.lifetimes.len(); let param = generics.ty_params.get(idx); - if_ok!(print_ident(s, param.ident)); - if_ok!(print_bounds(s, ¶m.bounds, false)); + try!(print_ident(s, param.ident)); + try!(print_bounds(s, ¶m.bounds, false)); match param.default { Some(default) => { - if_ok!(space(&mut s.s)); - if_ok!(word_space(s, "=")); - if_ok!(print_type(s, default)); + try!(space(&mut s.s)); + try!(word_space(s, "=")); + try!(print_type(s, default)); } _ => {} } @@ -1986,32 +1986,32 @@ pub fn print_generics(s: &mut State, ints.push(i); } - if_ok!(commasep(s, Inconsistent, ints, + try!(commasep(s, Inconsistent, ints, |s, &i| print_item(s, generics, i))); - if_ok!(word(&mut s.s, ">")); + try!(word(&mut s.s, ">")); } Ok(()) } pub fn print_meta_item(s: &mut State, item: &ast::MetaItem) -> io::IoResult<()> { - if_ok!(ibox(s, indent_unit)); + try!(ibox(s, indent_unit)); match item.node { ast::MetaWord(ref name) => { - if_ok!(word(&mut s.s, name.get())); + try!(word(&mut s.s, name.get())); } ast::MetaNameValue(ref name, ref value) => { - if_ok!(word_space(s, name.get())); - if_ok!(word_space(s, "=")); - if_ok!(print_literal(s, value)); + try!(word_space(s, name.get())); + try!(word_space(s, "=")); + try!(print_literal(s, value)); } ast::MetaList(ref name, ref items) => { - if_ok!(word(&mut s.s, name.get())); - if_ok!(popen(s)); - if_ok!(commasep(s, + try!(word(&mut s.s, name.get())); + try!(popen(s)); + try!(commasep(s, Consistent, items.as_slice(), |p, &i| print_meta_item(p, i))); - if_ok!(pclose(s)); + try!(pclose(s)); } } end(s) @@ -2022,26 +2022,26 @@ pub fn print_view_path(s: &mut State, vp: &ast::ViewPath) -> io::IoResult<()> { ast::ViewPathSimple(ident, ref path, _) => { // FIXME(#6993) can't compare identifiers directly here if path.segments.last().unwrap().identifier.name != ident.name { - if_ok!(print_ident(s, ident)); - if_ok!(space(&mut s.s)); - if_ok!(word_space(s, "=")); + try!(print_ident(s, ident)); + try!(space(&mut s.s)); + try!(word_space(s, "=")); } print_path(s, path, false) } ast::ViewPathGlob(ref path, _) => { - if_ok!(print_path(s, path, false)); + try!(print_path(s, path, false)); word(&mut s.s, "::*") } ast::ViewPathList(ref path, ref idents, _) => { if path.segments.is_empty() { - if_ok!(word(&mut s.s, "{")); + try!(word(&mut s.s, "{")); } else { - if_ok!(print_path(s, path, false)); - if_ok!(word(&mut s.s, "::{")); + try!(print_path(s, path, false)); + try!(word(&mut s.s, "::{")); } - if_ok!(commasep(s, Inconsistent, (*idents), |s, w| { + try!(commasep(s, Inconsistent, (*idents), |s, w| { print_ident(s, w.node.name) })); word(&mut s.s, "}") @@ -2055,30 +2055,30 @@ pub fn print_view_paths(s: &mut State, } pub fn print_view_item(s: &mut State, item: &ast::ViewItem) -> io::IoResult<()> { - if_ok!(hardbreak_if_not_bol(s)); - if_ok!(maybe_print_comment(s, item.span.lo)); - if_ok!(print_outer_attributes(s, item.attrs)); - if_ok!(print_visibility(s, item.vis)); + try!(hardbreak_if_not_bol(s)); + try!(maybe_print_comment(s, item.span.lo)); + try!(print_outer_attributes(s, item.attrs)); + try!(print_visibility(s, item.vis)); match item.node { ast::ViewItemExternMod(id, ref optional_path, _) => { - if_ok!(head(s, "extern crate")); - if_ok!(print_ident(s, id)); + try!(head(s, "extern crate")); + try!(print_ident(s, id)); for &(ref p, style) in optional_path.iter() { - if_ok!(space(&mut s.s)); - if_ok!(word(&mut s.s, "=")); - if_ok!(space(&mut s.s)); - if_ok!(print_string(s, p.get(), style)); + try!(space(&mut s.s)); + try!(word(&mut s.s, "=")); + try!(space(&mut s.s)); + try!(print_string(s, p.get(), style)); } } ast::ViewItemUse(ref vps) => { - if_ok!(head(s, "use")); - if_ok!(print_view_paths(s, *vps)); + try!(head(s, "use")); + try!(print_view_paths(s, *vps)); } } - if_ok!(word(&mut s.s, ";")); - if_ok!(end(s)); // end inner head-block - if_ok!(end(s)); // end outer head-block + try!(word(&mut s.s, ";")); + try!(end(s)); // end inner head-block + try!(end(s)); // end outer head-block Ok(()) } @@ -2091,14 +2091,14 @@ pub fn print_mutability(s: &mut State, } pub fn print_mt(s: &mut State, mt: &ast::MutTy) -> io::IoResult<()> { - if_ok!(print_mutability(s, mt.mutbl)); + try!(print_mutability(s, mt.mutbl)); print_type(s, mt.ty) } pub fn print_arg(s: &mut State, input: &ast::Arg) -> io::IoResult<()> { - if_ok!(ibox(s, indent_unit)); + try!(ibox(s, indent_unit)); match input.ty.node { - ast::TyInfer => if_ok!(print_pat(s, input.pat)), + ast::TyInfer => try!(print_pat(s, input.pat)), _ => { match input.pat.node { ast::PatIdent(_, ref path, _) if @@ -2108,12 +2108,12 @@ pub fn print_arg(s: &mut State, input: &ast::Arg) -> io::IoResult<()> { // Do nothing. } _ => { - if_ok!(print_pat(s, input.pat)); - if_ok!(word(&mut s.s, ":")); - if_ok!(space(&mut s.s)); + try!(print_pat(s, input.pat)); + try!(word(&mut s.s, ":")); + try!(space(&mut s.s)); } } - if_ok!(print_type(s, input.ty)); + try!(print_type(s, input.ty)); } } end(s) @@ -2132,32 +2132,32 @@ pub fn print_ty_fn(s: &mut State, opt_explicit_self: Option) -> io::IoResult<()> { - if_ok!(ibox(s, indent_unit)); + try!(ibox(s, indent_unit)); // Duplicates the logic in `print_fn_header_info()`. This is because that // function prints the sigil in the wrong place. That should be fixed. if opt_sigil == Some(ast::OwnedSigil) && onceness == ast::Once { - if_ok!(word(&mut s.s, "proc")); + try!(word(&mut s.s, "proc")); } else if opt_sigil == Some(ast::BorrowedSigil) { - if_ok!(print_extern_opt_abis(s, opt_abis)); + try!(print_extern_opt_abis(s, opt_abis)); for lifetime in opt_region.iter() { - if_ok!(print_lifetime(s, lifetime)); + try!(print_lifetime(s, lifetime)); } - if_ok!(print_purity(s, purity)); - if_ok!(print_onceness(s, onceness)); + try!(print_purity(s, purity)); + try!(print_onceness(s, onceness)); } else { - if_ok!(print_opt_abis_and_extern_if_nondefault(s, opt_abis)); - if_ok!(print_opt_sigil(s, opt_sigil)); - if_ok!(print_opt_lifetime(s, opt_region)); - if_ok!(print_purity(s, purity)); - if_ok!(print_onceness(s, onceness)); - if_ok!(word(&mut s.s, "fn")); + try!(print_opt_abis_and_extern_if_nondefault(s, opt_abis)); + try!(print_opt_sigil(s, opt_sigil)); + try!(print_opt_lifetime(s, opt_region)); + try!(print_purity(s, purity)); + try!(print_onceness(s, onceness)); + try!(word(&mut s.s, "fn")); } match id { Some(id) => { - if_ok!(word(&mut s.s, " ")); - if_ok!(print_ident(s, id)); + try!(word(&mut s.s, " ")); + try!(print_ident(s, id)); } _ => () } @@ -2166,42 +2166,42 @@ pub fn print_ty_fn(s: &mut State, opt_bounds.as_ref().map(|bounds| print_bounds(s, bounds, true)); } - match generics { Some(g) => if_ok!(print_generics(s, g)), _ => () } - if_ok!(zerobreak(&mut s.s)); + match generics { Some(g) => try!(print_generics(s, g)), _ => () } + try!(zerobreak(&mut s.s)); if opt_sigil == Some(ast::BorrowedSigil) { - if_ok!(word(&mut s.s, "|")); + try!(word(&mut s.s, "|")); } else { - if_ok!(popen(s)); + try!(popen(s)); } - if_ok!(print_fn_args(s, decl, opt_explicit_self)); + try!(print_fn_args(s, decl, opt_explicit_self)); if opt_sigil == Some(ast::BorrowedSigil) { - if_ok!(word(&mut s.s, "|")); + try!(word(&mut s.s, "|")); opt_bounds.as_ref().map(|bounds| print_bounds(s, bounds, true)); } else { if decl.variadic { - if_ok!(word(&mut s.s, ", ...")); + try!(word(&mut s.s, ", ...")); } - if_ok!(pclose(s)); + try!(pclose(s)); } - if_ok!(maybe_print_comment(s, decl.output.span.lo)); + try!(maybe_print_comment(s, decl.output.span.lo)); match decl.output.node { ast::TyNil => {} _ => { - if_ok!(space_if_not_bol(s)); - if_ok!(ibox(s, indent_unit)); - if_ok!(word_space(s, "->")); + try!(space_if_not_bol(s)); + try!(ibox(s, indent_unit)); + try!(word_space(s, "->")); if decl.cf == ast::NoReturn { - if_ok!(word_nbsp(s, "!")); + try!(word_nbsp(s, "!")); } else { - if_ok!(print_type(s, decl.output)); + try!(print_type(s, decl.output)); } - if_ok!(end(s)); + try!(end(s)); } } @@ -2223,7 +2223,7 @@ pub fn maybe_print_trailing_comment(s: &mut State, span: codemap::Span, match next_pos { None => (), Some(p) => next = p } if span.hi < (*cmnt).pos && (*cmnt).pos < next && span_line.line == comment_line.line { - if_ok!(print_comment(s, cmnt)); + try!(print_comment(s, cmnt)); s.cur_cmnt_and_lit.cur_cmnt += 1u; } } @@ -2236,12 +2236,12 @@ pub fn print_remaining_comments(s: &mut State) -> io::IoResult<()> { // If there aren't any remaining comments, then we need to manually // make sure there is a line break at the end. if next_comment(s).is_none() { - if_ok!(hardbreak(&mut s.s)); + try!(hardbreak(&mut s.s)); } loop { match next_comment(s) { Some(ref cmnt) => { - if_ok!(print_comment(s, cmnt)); + try!(print_comment(s, cmnt)); s.cur_cmnt_and_lit.cur_cmnt += 1u; } _ => break @@ -2251,7 +2251,7 @@ pub fn print_remaining_comments(s: &mut State) -> io::IoResult<()> { } pub fn print_literal(s: &mut State, lit: &ast::Lit) -> io::IoResult<()> { - if_ok!(maybe_print_comment(s, lit.span.lo)); + try!(maybe_print_comment(s, lit.span.lo)); match next_lit(s, lit.span.lo) { Some(ref ltrl) => { return word(&mut s.s, (*ltrl).lit); @@ -2299,12 +2299,12 @@ pub fn print_literal(s: &mut State, lit: &ast::Lit) -> io::IoResult<()> { if val { word(&mut s.s, "true") } else { word(&mut s.s, "false") } } ast::LitBinary(ref arr) => { - if_ok!(ibox(s, indent_unit)); - if_ok!(word(&mut s.s, "[")); - if_ok!(commasep_cmnt(s, Inconsistent, *arr.borrow(), + try!(ibox(s, indent_unit)); + try!(word(&mut s.s, "[")); + try!(commasep_cmnt(s, Inconsistent, *arr.borrow(), |s, u| word(&mut s.s, format!("{}", *u)), |_| lit.span)); - if_ok!(word(&mut s.s, "]")); + try!(word(&mut s.s, "]")); end(s) } } @@ -2334,7 +2334,7 @@ pub fn maybe_print_comment(s: &mut State, pos: BytePos) -> io::IoResult<()> { match next_comment(s) { Some(ref cmnt) => { if (*cmnt).pos < pos { - if_ok!(print_comment(s, cmnt)); + try!(print_comment(s, cmnt)); s.cur_cmnt_and_lit.cur_cmnt += 1u; } else { break; } } @@ -2349,35 +2349,35 @@ pub fn print_comment(s: &mut State, match cmnt.style { comments::Mixed => { assert_eq!(cmnt.lines.len(), 1u); - if_ok!(zerobreak(&mut s.s)); - if_ok!(word(&mut s.s, cmnt.lines[0])); - if_ok!(zerobreak(&mut s.s)); + try!(zerobreak(&mut s.s)); + try!(word(&mut s.s, cmnt.lines[0])); + try!(zerobreak(&mut s.s)); } comments::Isolated => { - if_ok!(pprust::hardbreak_if_not_bol(s)); + try!(pprust::hardbreak_if_not_bol(s)); for line in cmnt.lines.iter() { // Don't print empty lines because they will end up as trailing // whitespace if !line.is_empty() { - if_ok!(word(&mut s.s, *line)); + try!(word(&mut s.s, *line)); } - if_ok!(hardbreak(&mut s.s)); + try!(hardbreak(&mut s.s)); } } comments::Trailing => { - if_ok!(word(&mut s.s, " ")); + try!(word(&mut s.s, " ")); if cmnt.lines.len() == 1u { - if_ok!(word(&mut s.s, cmnt.lines[0])); - if_ok!(hardbreak(&mut s.s)); + try!(word(&mut s.s, cmnt.lines[0])); + try!(hardbreak(&mut s.s)); } else { - if_ok!(ibox(s, 0u)); + try!(ibox(s, 0u)); for line in cmnt.lines.iter() { if !line.is_empty() { - if_ok!(word(&mut s.s, *line)); + try!(word(&mut s.s, *line)); } - if_ok!(hardbreak(&mut s.s)); + try!(hardbreak(&mut s.s)); } - if_ok!(end(s)); + try!(end(s)); } } comments::BlankLine => { @@ -2387,9 +2387,9 @@ pub fn print_comment(s: &mut State, _ => false }; if is_semi || is_begin(s) || is_end(s) { - if_ok!(hardbreak(&mut s.s)); + try!(hardbreak(&mut s.s)); } - if_ok!(hardbreak(&mut s.s)); + try!(hardbreak(&mut s.s)); } } Ok(()) @@ -2443,7 +2443,7 @@ pub fn print_opt_purity(s: &mut State, match opt_purity { Some(ast::ImpureFn) => { } Some(purity) => { - if_ok!(word_nbsp(s, purity_to_str(purity))); + try!(word_nbsp(s, purity_to_str(purity))); } None => {} } @@ -2456,8 +2456,8 @@ pub fn print_opt_abis_and_extern_if_nondefault(s: &mut State, { match opt_abis { Some(abis) if !abis.is_rust() => { - if_ok!(word_nbsp(s, "extern")); - if_ok!(word_nbsp(s, abis.to_str())); + try!(word_nbsp(s, "extern")); + try!(word_nbsp(s, abis.to_str())); } Some(_) | None => {} }; @@ -2468,8 +2468,8 @@ pub fn print_extern_opt_abis(s: &mut State, opt_abis: Option) -> io::IoResult<()> { match opt_abis { Some(abis) => { - if_ok!(word_nbsp(s, "extern")); - if_ok!(word_nbsp(s, abis.to_str())); + try!(word_nbsp(s, "extern")); + try!(word_nbsp(s, abis.to_str())); } None => {} } @@ -2493,22 +2493,22 @@ pub fn print_fn_header_info(s: &mut State, onceness: ast::Onceness, opt_sigil: Option, vis: ast::Visibility) -> io::IoResult<()> { - if_ok!(word(&mut s.s, visibility_qualified(vis, ""))); + try!(word(&mut s.s, visibility_qualified(vis, ""))); if abis != AbiSet::Rust() { - if_ok!(word_nbsp(s, "extern")); - if_ok!(word_nbsp(s, abis.to_str())); + try!(word_nbsp(s, "extern")); + try!(word_nbsp(s, abis.to_str())); if opt_purity != Some(ast::ExternFn) { - if_ok!(print_opt_purity(s, opt_purity)); + try!(print_opt_purity(s, opt_purity)); } } else { - if_ok!(print_opt_purity(s, opt_purity)); + try!(print_opt_purity(s, opt_purity)); } - if_ok!(print_onceness(s, onceness)); - if_ok!(word(&mut s.s, "fn")); - if_ok!(print_opt_sigil(s, opt_sigil)); + try!(print_onceness(s, onceness)); + try!(word(&mut s.s, "fn")); + try!(print_opt_sigil(s, opt_sigil)); Ok(()) } diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index c4481a1a07f..1efbd461da8 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -30,10 +30,6 @@ use terminfo::searcher::open; use terminfo::parser::compiled::{parse, msys_terminfo}; use terminfo::parm::{expand, Number, Variables}; -macro_rules! if_ok ( - ($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) }) -) - pub mod terminfo; // FIXME (#2807): Windows support. @@ -155,7 +151,7 @@ impl Terminal { let s = expand(*self.ti.strings.find_equiv(&("setaf")).unwrap(), [Number(color as int)], &mut Variables::new()); if s.is_ok() { - if_ok!(self.out.write(s.unwrap())); + try!(self.out.write(s.unwrap())); return Ok(true) } else { warn!("{}", s.unwrap_err()); @@ -176,7 +172,7 @@ impl Terminal { let s = expand(*self.ti.strings.find_equiv(&("setab")).unwrap(), [Number(color as int)], &mut Variables::new()); if s.is_ok() { - if_ok!(self.out.write(s.unwrap())); + try!(self.out.write(s.unwrap())); return Ok(true) } else { warn!("{}", s.unwrap_err()); @@ -198,7 +194,7 @@ impl Terminal { if parm.is_some() { let s = expand(*parm.unwrap(), [], &mut Variables::new()); if s.is_ok() { - if_ok!(self.out.write(s.unwrap())); + try!(self.out.write(s.unwrap())); return Ok(true) } else { warn!("{}", s.unwrap_err()); diff --git a/src/libterm/terminfo/parser/compiled.rs b/src/libterm/terminfo/parser/compiled.rs index 31f12bd45e6..b2d06d3b7d8 100644 --- a/src/libterm/terminfo/parser/compiled.rs +++ b/src/libterm/terminfo/parser/compiled.rs @@ -162,7 +162,7 @@ pub static stringnames: &'static[&'static str] = &'static[ "cbt", "_", "cr", "cs /// Parse a compiled terminfo entry, using long capability names if `longnames` is true pub fn parse(file: &mut io::Reader, longnames: bool) -> Result<~TermInfo, ~str> { - macro_rules! if_ok( ($e:expr) => ( + macro_rules! try( ($e:expr) => ( match $e { Ok(e) => e, Err(e) => return Err(format!("{}", e)) } ) ) @@ -181,17 +181,17 @@ pub fn parse(file: &mut io::Reader, } // Check magic number - let magic = if_ok!(file.read_le_u16()); + let magic = try!(file.read_le_u16()); if magic != 0x011A { return Err(format!("invalid magic number: expected {:x} but found {:x}", 0x011A, magic as uint)); } - let names_bytes = if_ok!(file.read_le_i16()) as int; - let bools_bytes = if_ok!(file.read_le_i16()) as int; - let numbers_count = if_ok!(file.read_le_i16()) as int; - let string_offsets_count = if_ok!(file.read_le_i16()) as int; - let string_table_bytes = if_ok!(file.read_le_i16()) as int; + let names_bytes = try!(file.read_le_i16()) as int; + let bools_bytes = try!(file.read_le_i16()) as int; + let numbers_count = try!(file.read_le_i16()) as int; + let string_offsets_count = try!(file.read_le_i16()) as int; + let string_table_bytes = try!(file.read_le_i16()) as int; assert!(names_bytes > 0); @@ -220,21 +220,21 @@ pub fn parse(file: &mut io::Reader, } // don't read NUL - let bytes = if_ok!(file.read_bytes(names_bytes as uint - 1)); + let bytes = try!(file.read_bytes(names_bytes as uint - 1)); let names_str = match str::from_utf8_owned(bytes) { Some(s) => s, None => return Err(~"input not utf-8"), }; let term_names: ~[~str] = names_str.split('|').map(|s| s.to_owned()).collect(); - if_ok!(file.read_byte()); // consume NUL + try!(file.read_byte()); // consume NUL debug!("term names: {:?}", term_names); let mut bools_map = HashMap::new(); if bools_bytes != 0 { for i in range(0, bools_bytes) { - let b = if_ok!(file.read_byte()); + let b = try!(file.read_byte()); if b < 0 { error!("EOF reading bools after {} entries", i); return Err(~"error: expected more bools but hit EOF"); @@ -249,13 +249,13 @@ pub fn parse(file: &mut io::Reader, if (bools_bytes + names_bytes) % 2 == 1 { debug!("adjusting for padding between bools and numbers"); - if_ok!(file.read_byte()); // compensate for padding + try!(file.read_byte()); // compensate for padding } let mut numbers_map = HashMap::new(); if numbers_count != 0 { for i in range(0, numbers_count) { - let n = if_ok!(file.read_le_u16()); + let n = try!(file.read_le_u16()); if n != 0xFFFF { debug!("{}\\#{}", nnames[i], n); numbers_map.insert(nnames[i].to_owned(), n); @@ -270,12 +270,12 @@ pub fn parse(file: &mut io::Reader, if string_offsets_count != 0 { let mut string_offsets = vec::with_capacity(10); for _ in range(0, string_offsets_count) { - string_offsets.push(if_ok!(file.read_le_u16())); + string_offsets.push(try!(file.read_le_u16())); } debug!("offsets: {:?}", string_offsets); - let string_table = if_ok!(file.read_bytes(string_table_bytes as uint)); + let string_table = try!(file.read_bytes(string_table_bytes as uint)); if string_table.len() != string_table_bytes as uint { error!("EOF reading string table after {} bytes, wanted {}", string_table.len(), diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 226dd75d740..4a9575c78f4 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -397,7 +397,7 @@ impl ConsoleTestState { pub fn new(opts: &TestOpts, _: Option) -> io::IoResult> { let log_out = match opts.logfile { - Some(ref path) => Some(if_ok!(File::create(path))), + Some(ref path) => Some(try!(File::create(path))), None => None }; let out = match term::Terminal::new(io::stdout()) { @@ -461,11 +461,11 @@ impl ConsoleTestState { match self.out { Pretty(ref mut term) => { if self.use_color { - if_ok!(term.fg(color)); + try!(term.fg(color)); } - if_ok!(term.write(word.as_bytes())); + try!(term.write(word.as_bytes())); if self.use_color { - if_ok!(term.reset()); + try!(term.reset()); } Ok(()) } @@ -493,16 +493,16 @@ impl ConsoleTestState { } pub fn write_result(&mut self, result: &TestResult) -> io::IoResult<()> { - if_ok!(match *result { + try!(match *result { TrOk => self.write_ok(), TrFailed => self.write_failed(), TrIgnored => self.write_ignored(), TrMetrics(ref mm) => { - if_ok!(self.write_metric()); + try!(self.write_metric()); self.write_plain(format!(": {}", fmt_metrics(mm))) } TrBench(ref bs) => { - if_ok!(self.write_bench()); + try!(self.write_bench()); self.write_plain(format!(": {}", fmt_bench_samples(bs))) } }); @@ -527,7 +527,7 @@ impl ConsoleTestState { } pub fn write_failures(&mut self) -> io::IoResult<()> { - if_ok!(self.write_plain("\nfailures:\n")); + try!(self.write_plain("\nfailures:\n")); let mut failures = ~[]; let mut fail_out = ~""; for &(ref f, ref stdout) in self.failures.iter() { @@ -541,14 +541,14 @@ impl ConsoleTestState { } } if fail_out.len() > 0 { - if_ok!(self.write_plain("\n")); - if_ok!(self.write_plain(fail_out)); + try!(self.write_plain("\n")); + try!(self.write_plain(fail_out)); } - if_ok!(self.write_plain("\nfailures:\n")); + try!(self.write_plain("\nfailures:\n")); failures.sort(); for name in failures.iter() { - if_ok!(self.write_plain(format!(" {}\n", name.to_str()))); + try!(self.write_plain(format!(" {}\n", name.to_str()))); } Ok(()) } @@ -565,37 +565,37 @@ impl ConsoleTestState { LikelyNoise => noise += 1, MetricAdded => { added += 1; - if_ok!(self.write_added()); - if_ok!(self.write_plain(format!(": {}\n", *k))); + try!(self.write_added()); + try!(self.write_plain(format!(": {}\n", *k))); } MetricRemoved => { removed += 1; - if_ok!(self.write_removed()); - if_ok!(self.write_plain(format!(": {}\n", *k))); + try!(self.write_removed()); + try!(self.write_plain(format!(": {}\n", *k))); } Improvement(pct) => { improved += 1; - if_ok!(self.write_plain(format!(": {}", *k))); - if_ok!(self.write_improved()); - if_ok!(self.write_plain(format!(" by {:.2f}%\n", pct as f64))); + try!(self.write_plain(format!(": {}", *k))); + try!(self.write_improved()); + try!(self.write_plain(format!(" by {:.2f}%\n", pct as f64))); } Regression(pct) => { regressed += 1; - if_ok!(self.write_plain(format!(": {}", *k))); - if_ok!(self.write_regressed()); - if_ok!(self.write_plain(format!(" by {:.2f}%\n", pct as f64))); + try!(self.write_plain(format!(": {}", *k))); + try!(self.write_regressed()); + try!(self.write_plain(format!(" by {:.2f}%\n", pct as f64))); } } } - if_ok!(self.write_plain(format!("result of ratchet: {} metrics added, \ + try!(self.write_plain(format!("result of ratchet: {} metrics added, \ {} removed, {} improved, {} regressed, \ {} noise\n", added, removed, improved, regressed, noise))); if regressed == 0 { - if_ok!(self.write_plain("updated ratchet file\n")); + try!(self.write_plain("updated ratchet file\n")); } else { - if_ok!(self.write_plain("left ratchet file untouched\n")); + try!(self.write_plain("left ratchet file untouched\n")); } Ok(()) } @@ -608,38 +608,38 @@ impl ConsoleTestState { let ratchet_success = match *ratchet_metrics { None => true, Some(ref pth) => { - if_ok!(self.write_plain(format!("\nusing metrics ratcher: {}\n", + try!(self.write_plain(format!("\nusing metrics ratcher: {}\n", pth.display()))); match ratchet_pct { None => (), Some(pct) => - if_ok!(self.write_plain(format!("with noise-tolerance \ + try!(self.write_plain(format!("with noise-tolerance \ forced to: {}%\n", pct))) } let (diff, ok) = self.metrics.ratchet(pth, ratchet_pct); - if_ok!(self.write_metric_diff(&diff)); + try!(self.write_metric_diff(&diff)); ok } }; let test_success = self.failed == 0u; if !test_success { - if_ok!(self.write_failures()); + try!(self.write_failures()); } let success = ratchet_success && test_success; - if_ok!(self.write_plain("\ntest result: ")); + try!(self.write_plain("\ntest result: ")); if success { // There's no parallelism at this point so it's safe to use color - if_ok!(self.write_ok()); + try!(self.write_ok()); } else { - if_ok!(self.write_failed()); + try!(self.write_failed()); } let s = format!(". {} passed; {} failed; {} ignored; {} measured\n\n", self.passed, self.failed, self.ignored, self.measured); - if_ok!(self.write_plain(s)); + try!(self.write_plain(s)); return Ok(success); } } @@ -678,8 +678,8 @@ pub fn run_tests_console(opts: &TestOpts, TeFiltered(ref filtered_tests) => st.write_run_start(filtered_tests.len()), TeWait(ref test, padding) => st.write_test_start(test, padding), TeResult(test, result, stdout) => { - if_ok!(st.write_log(&test, &result)); - if_ok!(st.write_result(&result)); + try!(st.write_log(&test, &result)); + try!(st.write_result(&result)); match result { TrOk => st.passed += 1, TrIgnored => st.ignored += 1, @@ -707,7 +707,7 @@ pub fn run_tests_console(opts: &TestOpts, } } } - let mut st = if_ok!(ConsoleTestState::new(opts, None::)); + let mut st = try!(ConsoleTestState::new(opts, None::)); fn len_if_padded(t: &TestDescAndFn) -> uint { match t.testfn.padding() { PadNone => 0u, @@ -722,12 +722,12 @@ pub fn run_tests_console(opts: &TestOpts, }, None => {} } - if_ok!(run_tests(opts, tests, |x| callback(&x, &mut st))); + try!(run_tests(opts, tests, |x| callback(&x, &mut st))); match opts.save_metrics { None => (), Some(ref pth) => { - if_ok!(st.metrics.save(pth)); - if_ok!(st.write_plain(format!("\nmetrics saved to: {}", + try!(st.metrics.save(pth)); + try!(st.write_plain(format!("\nmetrics saved to: {}", pth.display()))); } } @@ -793,7 +793,7 @@ fn run_tests(opts: &TestOpts, let filtered_tests = filter_tests(opts, tests); let filtered_descs = filtered_tests.map(|t| t.desc.clone()); - if_ok!(callback(TeFiltered(filtered_descs))); + try!(callback(TeFiltered(filtered_descs))); let (filtered_tests, filtered_benchs_and_metrics) = filtered_tests.partition(|e| { @@ -821,7 +821,7 @@ fn run_tests(opts: &TestOpts, // We are doing one test at a time so we can print the name // of the test before we run it. Useful for debugging tests // that hang forever. - if_ok!(callback(TeWait(test.desc.clone(), test.testfn.padding()))); + try!(callback(TeWait(test.desc.clone(), test.testfn.padding()))); } run_test(!opts.run_tests, test, ch.clone()); pending += 1; @@ -829,19 +829,19 @@ fn run_tests(opts: &TestOpts, let (desc, result, stdout) = p.recv(); if concurrency != 1 { - if_ok!(callback(TeWait(desc.clone(), PadNone))); + try!(callback(TeWait(desc.clone(), PadNone))); } - if_ok!(callback(TeResult(desc, result, stdout))); + try!(callback(TeResult(desc, result, stdout))); pending -= 1; } // All benchmarks run at the end, in serial. // (this includes metric fns) for b in filtered_benchs_and_metrics.move_iter() { - if_ok!(callback(TeWait(b.desc.clone(), b.testfn.padding()))); + try!(callback(TeWait(b.desc.clone(), b.testfn.padding()))); run_test(!opts.run_benchmarks, b, ch.clone()); let (test, result, stdout) = p.recv(); - if_ok!(callback(TeResult(test, result, stdout))); + try!(callback(TeResult(test, result, stdout))); } Ok(()) } @@ -1026,7 +1026,7 @@ impl MetricMap { /// Write MetricDiff to a file. pub fn save(&self, p: &Path) -> io::IoResult<()> { - let mut file = if_ok!(File::create(p)); + let mut file = try!(File::create(p)); let MetricMap(ref map) = *self; map.to_json().to_pretty_writer(&mut file) }