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 } }
) )
}
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); }
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) }
// 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);
}
}
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);
}
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)
}
}
}
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); }
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>|) {
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)));
}
}
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)
}
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)));
}
}
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);
}
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);
}
}
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(())
}
}
fn connect(addr: &CString, ty: libc::c_int) -> IoResult<Inner> {
- 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,
}
fn bind(addr: &CString, ty: libc::c_int) -> IoResult<Inner> {
- 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)
}
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(),
impl rtio::RtioPipe for UnixStream {
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
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;
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;
pub fn native_listen(self) -> IoResult<UnixAcceptor> {
Ok(UnixAcceptor {
listener: self,
- event: if_ok!(Event::new(true, false)),
+ event: try!(Event::new(true, false)),
})
}
}
// 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();
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(()) }
})
.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(())
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(())
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));
}
_ => ()
}
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")
}
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),
dep.vers));
}
- if_ok!(write!(out, "\n"));
+ try!(write!(out, "\n"));
Ok(())
}
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)
}
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(())
}
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(())
}
}
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(())
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 {
'>' => ">",
'<' => "<",
'"' => """,
_ => unreachable!()
};
- if_ok!(fmt.buf.write(s.as_bytes()));
+ try!(fmt.buf.write(s.as_bytes()));
last = i + 1;
}
_ => {}
}
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(())
}
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(())
}
}
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(())
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, "<a class='mod'
+ try!(write!(w, "<a class='mod'
href='{}index.html'>{}</a>::",
root,
seg.name));
}
None => {
for seg in path.segments.slice_to(amt).iter() {
- if_ok!(write!(w, "{}::", seg.name));
+ try!(write!(w, "{}::", seg.name));
}
}
}
}
}
- if_ok!(write!(w, "<a class='{}' href='{}' title='{}'>{}</a>",
+ try!(write!(w, "<a class='{}' href='{}' title='{}'>{}</a>",
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(())
})
})
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(())
})
}
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)
}
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())
}
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(())
}
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, "\\};")
}
_ => {
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(())
}
},
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) => {
// 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
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(),
});
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 {
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(());
}
}
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,
// 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()
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,
// 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)
}
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,
"<a class='stability {lvl}' title='{reason}'>{lvl}</a>",
lvl = stability.level.to_str(),
reason = match stability.text {
} else {
format!("{}-{}", self.item.source.loline, self.item.source.hiline)
};
- if_ok!(write!(fmt.buf,
+ try!(write!(fmt.buf,
"<a class='source'
href='{root}src/{krate}/{path}.html\\#{href}'>\
[src]</a>",
}
// Write the breadcrumb trail header for the top
- if_ok!(write!(fmt.buf, "<h1 class='fqn'>"));
+ try!(write!(fmt.buf, "<h1 class='fqn'>"));
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();
for _ in range(0, cur.len() - i - 1) {
trail.push_str("../");
}
- if_ok!(write!(fmt.buf, "<a href='{}index.html'>{}</a>::",
+ try!(write!(fmt.buf, "<a href='{}index.html'>{}</a>::",
trail, component.as_slice()));
}
- if_ok!(write!(fmt.buf, "<a class='{}' href=''>{}</a></h1>",
+ try!(write!(fmt.buf, "<a class='{}' href=''>{}</a></h1>",
shortty(self.item), self.item.name.get_ref().as_slice()));
match self.item.inner {
fn document(w: &mut Writer, item: &clean::Item) -> fmt::Result {
match item.doc_value() {
Some(s) => {
- if_ok!(write!(w, "<div class='docblock'>{}</div>", Markdown(s)));
+ try!(write!(w, "<div class='docblock'>{}</div>", Markdown(s)));
}
None => {}
}
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);
let myty = shortty(myitem);
if myty != curty {
if curty != "" {
- if_ok!(write!(w, "</table>"));
+ try!(write!(w, "</table>"));
}
curty = myty;
- if_ok!(write!(w, "<h2>{}</h2>\n<table>", match myitem.inner {
+ try!(write!(w, "<h2>{}</h2>\n<table>", match myitem.inner {
clean::ModuleItem(..) => "Modules",
clean::StructItem(..) => "Structs",
clean::EnumItem(..) => "Enums",
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let Initializer(s) = *self;
if s.len() == 0 { return Ok(()); }
- if_ok!(write!(f.buf, "<code> = </code>"));
+ try!(write!(f.buf, "<code> = </code>"));
let tag = if s.contains("\n") { "pre" } else { "code" };
- if_ok!(write!(f.buf, "<{tag}>{}</{tag}>",
+ try!(write!(f.buf, "<{tag}>{}</{tag}>",
s.as_slice(), tag=tag));
Ok(())
}
}
- if_ok!(write!(w, "
+ try!(write!(w, "
<tr>
<td><code>{}static {}: {}</code>{}</td>
<td class='docblock'>{} </td>
clean::ViewItemItem(ref item) => {
match item.inner {
clean::ExternMod(ref name, ref src, _) => {
- if_ok!(write!(w, "<tr><td><code>extern crate {}",
+ try!(write!(w, "<tr><td><code>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, ";</code></td></tr>"));
+ try!(write!(w, ";</code></td></tr>"));
}
clean::Import(ref imports) => {
for import in imports.iter() {
- if_ok!(write!(w, "<tr><td><code>{}{}</code></td></tr>",
+ try!(write!(w, "<tr><td><code>{}{}</code></td></tr>",
VisSpace(myitem.visibility),
*import));
}
_ => {
if myitem.name.is_none() { continue }
- if_ok!(write!(w, "
+ try!(write!(w, "
<tr>
<td><a class='{class}' href='{href}'
title='{title}'>{}</a></td>
fn item_function(w: &mut Writer, it: &clean::Item,
f: &clean::Function) -> fmt::Result {
- if_ok!(write!(w, "<pre class='fn'>{vis}{purity}fn {name}{generics}{decl}</pre>",
+ try!(write!(w, "<pre class='fn'>{vis}{purity}fn {name}{generics}{decl}</pre>",
vis = VisSpace(it.visibility),
purity = PuritySpace(f.purity),
name = it.name.get_ref().as_slice(),
}
// Output the trait definition
- if_ok!(write!(w, "<pre class='trait'>{}trait {}{}{} ",
+ try!(write!(w, "<pre class='trait'>{}trait {}{}{} ",
VisSpace(it.visibility),
it.name.get_ref().as_slice(),
t.generics,
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, "</pre>"));
+ try!(write!(w, "</pre>"));
// 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, "<h3 id='{}.{}' class='method'><code>",
+ try!(write!(w, "<h3 id='{}.{}' class='method'><code>",
shortty(m.item()),
*m.item().name.get_ref()));
- if_ok!(render_method(w, m.item()));
- if_ok!(write!(w, "</code></h3>"));
- if_ok!(document(w, m.item()));
+ try!(render_method(w, m.item()));
+ try!(write!(w, "</code></h3>"));
+ try!(document(w, m.item()));
Ok(())
}
// Output the documentation for each function individually
if required.len() > 0 {
- if_ok!(write!(w, "
+ try!(write!(w, "
<h2 id='required-methods'>Required Methods</h2>
<div class='methods'>
"));
for m in required.iter() {
- if_ok!(meth(w, *m));
+ try!(meth(w, *m));
}
- if_ok!(write!(w, "</div>"));
+ try!(write!(w, "</div>"));
}
if provided.len() > 0 {
- if_ok!(write!(w, "
+ try!(write!(w, "
<h2 id='provided-methods'>Provided Methods</h2>
<div class='methods'>
"));
for m in provided.iter() {
- if_ok!(meth(w, *m));
+ try!(meth(w, *m));
}
- if_ok!(write!(w, "</div>"));
+ try!(write!(w, "</div>"));
}
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, "
<h2 id='implementors'>Implementors</h2>
<ul class='item-list'>
"));
for i in implementors.iter() {
match *i {
PathType(ref ty) => {
- if_ok!(write!(w, "<li><code>{}</code></li>", *ty));
+ try!(write!(w, "<li><code>{}</code></li>", *ty));
}
OtherType(ref generics, ref trait_, ref for_) => {
- if_ok!(write!(w, "<li><code>impl{} {} for {}</code></li>",
+ try!(write!(w, "<li><code>impl{} {} for {}</code></li>",
*generics, *trait_, *for_));
}
}
}
- if_ok!(write!(w, "</ul>"));
+ try!(write!(w, "</ul>"));
}
None => {}
}
fn item_struct(w: &mut Writer, it: &clean::Item,
s: &clean::Struct) -> fmt::Result {
- if_ok!(write!(w, "<pre class='struct'>"));
- if_ok!(render_struct(w, it, Some(&s.generics), s.struct_type, s.fields,
+ try!(write!(w, "<pre class='struct'>"));
+ try!(render_struct(w, it, Some(&s.generics), s.struct_type, s.fields,
s.fields_stripped, "", true));
- if_ok!(write!(w, "</pre>"));
+ try!(write!(w, "</pre>"));
- if_ok!(document(w, it));
+ try!(document(w, it));
match s.struct_type {
doctree::Plain if s.fields.len() > 0 => {
- if_ok!(write!(w, "<h2 class='fields'>Fields</h2>\n<table>"));
+ try!(write!(w, "<h2 class='fields'>Fields</h2>\n<table>"));
for field in s.fields.iter() {
- if_ok!(write!(w, "<tr><td id='structfield.{name}'>\
+ try!(write!(w, "<tr><td id='structfield.{name}'>\
<code>{name}</code></td><td>",
name = field.name.get_ref().as_slice()));
- if_ok!(document(w, field));
- if_ok!(write!(w, "</td></tr>"));
+ try!(document(w, field));
+ try!(write!(w, "</td></tr>"));
}
- if_ok!(write!(w, "</table>"));
+ try!(write!(w, "</table>"));
}
_ => {}
}
}
fn item_enum(w: &mut Writer, it: &clean::Item, e: &clean::Enum) -> fmt::Result {
- if_ok!(write!(w, "<pre class='enum'>{}enum {}{}",
+ try!(write!(w, "<pre class='enum'>{}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));
}
}
_ => 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, "</pre>"));
+ try!(write!(w, "</pre>"));
- if_ok!(document(w, it));
+ try!(document(w, it));
if e.variants.len() > 0 {
- if_ok!(write!(w, "<h2 class='variants'>Variants</h2>\n<table>"));
+ try!(write!(w, "<h2 class='variants'>Variants</h2>\n<table>"));
for variant in e.variants.iter() {
- if_ok!(write!(w, "<tr><td id='variant.{name}'><code>{name}</code></td><td>",
+ try!(write!(w, "<tr><td id='variant.{name}'><code>{name}</code></td><td>",
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, "<h3 class='fields'>Fields</h3>\n
+ try!(write!(w, "<h3 class='fields'>Fields</h3>\n
<table>"));
for field in s.fields.iter() {
- if_ok!(write!(w, "<tr><td \
+ try!(write!(w, "<tr><td \
id='variant.{v}.field.{f}'>\
<code>{f}</code></td><td>",
v = variant.name.get_ref().as_slice(),
f = field.name.get_ref().as_slice()));
- if_ok!(document(w, field));
- if_ok!(write!(w, "</td></tr>"));
+ try!(document(w, field));
+ try!(write!(w, "</td></tr>"));
}
- if_ok!(write!(w, "</table>"));
+ try!(write!(w, "</table>"));
}
_ => ()
}
}
_ => ()
}
- if_ok!(write!(w, "</td></tr>"));
+ try!(write!(w, "</td></tr>"));
}
- if_ok!(write!(w, "</table>"));
+ try!(write!(w, "</table>"));
}
- if_ok!(render_methods(w, it));
+ try!(render_methods(w, it));
Ok(())
}
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_,
}
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(())
let traits = traits.to_owned_vec();
if non_trait.len() > 0 {
- if_ok!(write!(w, "<h2 id='methods'>Methods</h2>"));
+ try!(write!(w, "<h2 id='methods'>Methods</h2>"));
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, "<h2 id='implementations'>Trait \
+ try!(write!(w, "<h2 id='implementations'>Trait \
Implementations</h2>"));
for &(ref i, ref dox) in traits.move_iter() {
- if_ok!(render_impl(w, i, dox));
+ try!(render_impl(w, i, dox));
}
}
}
fn render_impl(w: &mut Writer, i: &clean::Impl,
dox: &Option<~str>) -> fmt::Result {
- if_ok!(write!(w, "<h3 class='impl'><code>impl{} ", i.generics));
+ try!(write!(w, "<h3 class='impl'><code>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,
}
None => None
};
- if_ok!(write!(w, "{}</code></h3>", i.for_));
+ try!(write!(w, "{}</code></h3>", i.for_));
match *dox {
Some(ref dox) => {
- if_ok!(write!(w, "<div class='docblock'>{}</div>",
+ try!(write!(w, "<div class='docblock'>{}</div>",
Markdown(dox.as_slice())));
}
None => {}
}
fn docmeth(w: &mut Writer, item: &clean::Item) -> io::IoResult<bool> {
- if_ok!(write!(w, "<h4 id='method.{}' class='method'><code>",
+ try!(write!(w, "<h4 id='method.{}' class='method'><code>",
*item.name.get_ref()));
- if_ok!(render_method(w, item));
- if_ok!(write!(w, "</code></h4>\n"));
+ try!(render_method(w, item));
+ try!(write!(w, "</code></h4>\n"));
match item.doc_value() {
Some(s) => {
- if_ok!(write!(w, "<div class='docblock'>{}</div>", Markdown(s)));
+ try!(write!(w, "<div class='docblock'>{}</div>", Markdown(s)));
Ok(true)
}
None => Ok(false)
}
}
- if_ok!(write!(w, "<div class='methods'>"));
+ try!(write!(w, "<div class='methods'>"));
for meth in i.methods.iter() {
- if if_ok!(docmeth(w, meth)) {
+ if try!(docmeth(w, meth)) {
continue
}
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) => {
Some(method) => {
match method.item().doc_value() {
Some(s) => {
- if_ok!(write!(w,
+ try!(write!(w,
"<div class='docblock'>{}</div>",
Markdown(s)));
}
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) => {
None => {}
}
- if_ok!(docmeth(w, method.item()));
+ try!(docmeth(w, method.item()));
}
}
None => {}
}))
}
}
- if_ok!(write!(w, "</div>"));
+ try!(write!(w, "</div>"));
Ok(())
}
fn item_typedef(w: &mut Writer, it: &clean::Item,
t: &clean::Typedef) -> fmt::Result {
- if_ok!(write!(w, "<pre class='typedef'>type {}{} = {};</pre>",
+ try!(write!(w, "<pre class='typedef'>type {}{} = {};</pre>",
it.name.get_ref().as_slice(),
t.generics,
t.type_));
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let cx = self.cx;
let it = self.item;
- if_ok!(write!(fmt.buf, "<p class='location'>"));
+ try!(write!(fmt.buf, "<p class='location'>"));
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, "<a href='{}index.html'>{}</a>",
+ try!(write!(fmt.buf, "<a href='{}index.html'>{}</a>",
cx.root_path.slice_to((cx.current.len() - i - 1) * 3),
*name));
}
- if_ok!(write!(fmt.buf, "</p>"));
+ try!(write!(fmt.buf, "</p>"));
fn block(w: &mut Writer, short: &str, longty: &str,
cur: &clean::Item, cx: &Context) -> fmt::Result {
Some(items) => items.as_slice(),
None => return Ok(())
};
- if_ok!(write!(w, "<div class='block {}'><h2>{}</h2>", short, longty));
+ try!(write!(w, "<div class='block {}'><h2>{}</h2>", short, longty));
for item in items.iter() {
let class = if cur.name.get_ref() == item &&
short == shortty(cur) { "current" } else { "" };
- if_ok!(write!(w, "<a class='{ty} {class}' href='{curty, select,
+ try!(write!(w, "<a class='{ty} {class}' href='{curty, select,
mod{../}
other{}
}{tysel, select,
curty = shortty(cur),
name = item.as_slice()));
}
- if_ok!(write!(w, "</div>"));
+ try!(write!(w, "</div>"));
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(())
}
}
cols += 1;
tmp /= 10;
}
- if_ok!(write!(fmt.buf, "<pre class='line-numbers'>"));
+ try!(write!(fmt.buf, "<pre class='line-numbers'>"));
for i in range(1, lines + 1) {
- if_ok!(write!(fmt.buf, "<span id='{0:u}'>{0:1$u}</span>\n", i, cols));
+ try!(write!(fmt.buf, "<span id='{0:u}'>{0:1$u}</span>\n", i, cols));
}
- if_ok!(write!(fmt.buf, "</pre>"));
- if_ok!(write!(fmt.buf, "<pre class='rust'>"));
- if_ok!(write!(fmt.buf, "{}", Escape(s.as_slice())));
- if_ok!(write!(fmt.buf, "</pre>"));
+ try!(write!(fmt.buf, "</pre>"));
+ try!(write!(fmt.buf, "<pre class='rust'>"));
+ try!(write!(fmt.buf, "{}", Escape(s.as_slice())));
+ try!(write!(fmt.buf, "</pre>"));
Ok(())
}
}
fn item_macro(w: &mut Writer, it: &clean::Item,
t: &clean::Macro) -> fmt::Result {
- if_ok!(write!(w, "<pre class='macro'>{}</pre>", t.source));
+ try!(write!(w, "<pre class='macro'>{}</pre>", t.source));
document(w, it)
}
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(())
}
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(())
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 } }
) )
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);
}
curarg: args.iter(),
};
for piece in fmt.iter() {
- if_ok!(formatter.run(piece, None));
+ try!(formatter.run(piece, None));
}
Ok(())
}
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(())
}
::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(())
})
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;
}
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)
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(())
}
impl<A: fmt::Show + Hash + Eq, B: fmt::Show> fmt::Show for HashMap<A, B> {
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"\}")
}
impl<A: fmt::Show + Hash + Eq> fmt::Show for HashSet<A> {
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"\}")
}
impl<R: Reader> Buffer for BufferedReader<R> {
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))
impl<R: Reader> Reader for BufferedReader<R> {
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
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
impl<W: Writer> Writer for BufferedWriter<W> {
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() {
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),
})
}
- 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 {
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
/// // 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);
/// }
/// 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<Directories> {
- Ok(Directories { stack: if_ok!(readdir(path)) })
+ Ok(Directories { stack: try!(readdir(path)) })
}
/// An iterator which walks over a directory
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)
}
/// 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
impl Seek for MemWriter {
fn tell(&self) -> IoResult<u64> { 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(())
}
impl Seek for MemReader {
fn tell(&self) -> IoResult<u64> { 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(())
}
impl<'a> Seek for BufWriter<'a> {
fn tell(&self) -> IoResult<u64> { 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(())
}
impl<'a> Seek for BufReader<'a> {
fn tell(&self) -> IoResult<u64> { 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(())
}
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(())
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;
}
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)
}
/// 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<char> {
- 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
{
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)),
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)));
}
}
/// 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) })
)
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; }
#[inline]
pub fn write<T:Repr>(&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 {
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.
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
}
}
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()),
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::<()>() }
fn visit_char(&mut self) -> bool {
self.get::<char>(|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
})
}
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)
})
}
_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;
}
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)
})
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)
fn visit_evec_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
self.get::<&raw::Box<raw::Vec<()>>>(|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)
})
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::<raw::Slice<()>>(|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 }
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
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
_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
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
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
}
}
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
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;
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]));
}
}
_ => ()
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
}
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
}
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, ")")
});
}
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, "]")
}
}
fn write_pretty<T: Writer>(term: &mut term::Terminal<T>, 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(())
}
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(())
}
// 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)
}
}
// 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)
_ => 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 {
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(())
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)));
}
}
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(())
}
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(())
}
}
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(())
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 {
}
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)
}
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(())
}
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)
}
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(())
}
}
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(())
}
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
// 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(())
}
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)
}
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)
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(())
}
pub fn print_opt_lifetime(s: &mut State,
lifetime: &Option<ast::Lifetime>) -> 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));
}
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");
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),
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
-
- 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!(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
+
+ 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,
));
}
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(())
}
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<ast::Variant>],
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)
}
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(())
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, ","));
}
}
}
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));
}
_ => ()
}
}
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,
}
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)
}
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(())
}
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;
}
}
}
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)
}
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
_ => {
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)
}
}
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, ":"));
- }
- 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!(word(&mut s.s, "'"));
+ try!(print_ident(s, *ident));
+ try!(word_space(s, ":"));
+ }
+ 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
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
// 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
// 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)
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)
}
opt_bounds: &Option<OptVec<ast::TyParamBound>>)
-> 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;
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(())
}
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(())
}
fn print_explicit_self(s: &mut State,
explicit_self: ast::ExplicitSelf_,
mutbl: ast::Mutability) -> io::IoResult<bool> {
- 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);
generics: &ast::Generics,
opt_explicit_self: Option<ast::ExplicitSelf_>,
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(())
}
{
// 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 {
_ => 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.
};
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)
opt_explicit_self: Option<ast::ExplicitSelf_>)
-> 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(())
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));
}
}
}
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));
}
}
pub fn print_bounds(s: &mut State, bounds: &OptVec<ast::TyParamBound>,
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)
}
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() {
} 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));
}
_ => {}
}
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)
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, "}")
}
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(())
}
}
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
// 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)
opt_explicit_self: Option<ast::ExplicitSelf_>)
-> 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));
}
_ => ()
}
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));
}
}
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;
}
}
// 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
}
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);
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)
}
}
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; }
}
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 => {
_ => 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(())
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 => {}
}
{
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 => {}
};
opt_abis: Option<AbiSet>) -> 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 => {}
}
onceness: ast::Onceness,
opt_sigil: Option<ast::Sigil>,
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(())
}
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.
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());
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());
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());
/// 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)) }
) )
}
// 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);
}
// 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");
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);
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(),
pub fn new(opts: &TestOpts,
_: Option<T>) -> io::IoResult<ConsoleTestState<StdWriter>> {
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()) {
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(())
}
}
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)))
}
});
}
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() {
}
}
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(())
}
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(())
}
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);
}
}
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,
}
}
}
- let mut st = if_ok!(ConsoleTestState::new(opts, None::<StdWriter>));
+ let mut st = try!(ConsoleTestState::new(opts, None::<StdWriter>));
fn len_if_padded(t: &TestDescAndFn) -> uint {
match t.testfn.padding() {
PadNone => 0u,
},
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())));
}
}
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| {
// 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;
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(())
}
/// 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)
}