Mass rename if_ok! to try!
This "bubble up an error" macro was originally named if_ok! in order to get it landed, but after the fact it was discovered that this name is not exactly desirable. The name `if_ok!` isn't immediately clear that is has much to do with error handling, and it doesn't look fantastic in all contexts (if if_ok!(...) {}). In general, the agreed opinion about `if_ok!` is that is came in as subpar. The name `try!` is more invocative of error handling, it's shorter by 2 letters, and it looks fitting in almost all circumstances. One concern about the word `try!` is that it's too invocative of exceptions, but the belief is that this will be overcome with documentation and examples. Close #12037
This commit is contained in:
parent
06e1281198
commit
7bb498bd7a
32 changed files with 1222 additions and 1226 deletions
|
@ -246,7 +246,7 @@ use serialize::Encodable;
|
|||
use serialize;
|
||||
use collections::TreeMap;
|
||||
|
||||
macro_rules! if_ok( ($e:expr) => (
|
||||
macro_rules! try( ($e:expr) => (
|
||||
match $e { Ok(e) => e, Err(e) => { self.error = Err(e); return } }
|
||||
) )
|
||||
|
||||
|
@ -342,7 +342,7 @@ impl<'a> Encoder<'a> {
|
|||
}
|
||||
|
||||
impl<'a> serialize::Encoder for Encoder<'a> {
|
||||
fn emit_nil(&mut self) { if_ok!(write!(self.wr, "null")) }
|
||||
fn emit_nil(&mut self) { try!(write!(self.wr, "null")) }
|
||||
|
||||
fn emit_uint(&mut self, v: uint) { self.emit_f64(v as f64); }
|
||||
fn emit_u64(&mut self, v: u64) { self.emit_f64(v as f64); }
|
||||
|
@ -358,20 +358,20 @@ impl<'a> serialize::Encoder for Encoder<'a> {
|
|||
|
||||
fn emit_bool(&mut self, v: bool) {
|
||||
if v {
|
||||
if_ok!(write!(self.wr, "true"));
|
||||
try!(write!(self.wr, "true"));
|
||||
} else {
|
||||
if_ok!(write!(self.wr, "false"));
|
||||
try!(write!(self.wr, "false"));
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_f64(&mut self, v: f64) {
|
||||
if_ok!(write!(self.wr, "{}", f64::to_str_digits(v, 6u)))
|
||||
try!(write!(self.wr, "{}", f64::to_str_digits(v, 6u)))
|
||||
}
|
||||
fn emit_f32(&mut self, v: f32) { self.emit_f64(v as f64); }
|
||||
|
||||
fn emit_char(&mut self, v: char) { self.emit_str(str::from_char(v)) }
|
||||
fn emit_str(&mut self, v: &str) {
|
||||
if_ok!(write!(self.wr, "{}", escape_str(v)))
|
||||
try!(write!(self.wr, "{}", escape_str(v)))
|
||||
}
|
||||
|
||||
fn emit_enum(&mut self, _name: &str, f: |&mut Encoder<'a>|) { f(self) }
|
||||
|
@ -385,19 +385,19 @@ impl<'a> serialize::Encoder for Encoder<'a> {
|
|||
// Bunny => "Bunny"
|
||||
// Kangaroo(34,"William") => {"variant": "Kangaroo", "fields": [34,"William"]}
|
||||
if cnt == 0 {
|
||||
if_ok!(write!(self.wr, "{}", escape_str(name)));
|
||||
try!(write!(self.wr, "{}", escape_str(name)));
|
||||
} else {
|
||||
if_ok!(write!(self.wr, "\\{\"variant\":"));
|
||||
if_ok!(write!(self.wr, "{}", escape_str(name)));
|
||||
if_ok!(write!(self.wr, ",\"fields\":["));
|
||||
try!(write!(self.wr, "\\{\"variant\":"));
|
||||
try!(write!(self.wr, "{}", escape_str(name)));
|
||||
try!(write!(self.wr, ",\"fields\":["));
|
||||
f(self);
|
||||
if_ok!(write!(self.wr, "]\\}"));
|
||||
try!(write!(self.wr, "]\\}"));
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_enum_variant_arg(&mut self, idx: uint, f: |&mut Encoder<'a>|) {
|
||||
if idx != 0 {
|
||||
if_ok!(write!(self.wr, ","));
|
||||
try!(write!(self.wr, ","));
|
||||
}
|
||||
f(self);
|
||||
}
|
||||
|
@ -418,17 +418,17 @@ impl<'a> serialize::Encoder for Encoder<'a> {
|
|||
}
|
||||
|
||||
fn emit_struct(&mut self, _: &str, _: uint, f: |&mut Encoder<'a>|) {
|
||||
if_ok!(write!(self.wr, r"\{"));
|
||||
try!(write!(self.wr, r"\{"));
|
||||
f(self);
|
||||
if_ok!(write!(self.wr, r"\}"));
|
||||
try!(write!(self.wr, r"\}"));
|
||||
}
|
||||
|
||||
fn emit_struct_field(&mut self,
|
||||
name: &str,
|
||||
idx: uint,
|
||||
f: |&mut Encoder<'a>|) {
|
||||
if idx != 0 { if_ok!(write!(self.wr, ",")) }
|
||||
if_ok!(write!(self.wr, "{}:", escape_str(name)));
|
||||
if idx != 0 { try!(write!(self.wr, ",")) }
|
||||
try!(write!(self.wr, "{}:", escape_str(name)));
|
||||
f(self);
|
||||
}
|
||||
|
||||
|
@ -454,31 +454,31 @@ impl<'a> serialize::Encoder for Encoder<'a> {
|
|||
fn emit_option_some(&mut self, f: |&mut Encoder<'a>|) { f(self); }
|
||||
|
||||
fn emit_seq(&mut self, _len: uint, f: |&mut Encoder<'a>|) {
|
||||
if_ok!(write!(self.wr, "["));
|
||||
try!(write!(self.wr, "["));
|
||||
f(self);
|
||||
if_ok!(write!(self.wr, "]"));
|
||||
try!(write!(self.wr, "]"));
|
||||
}
|
||||
|
||||
fn emit_seq_elt(&mut self, idx: uint, f: |&mut Encoder<'a>|) {
|
||||
if idx != 0 {
|
||||
if_ok!(write!(self.wr, ","));
|
||||
try!(write!(self.wr, ","));
|
||||
}
|
||||
f(self)
|
||||
}
|
||||
|
||||
fn emit_map(&mut self, _len: uint, f: |&mut Encoder<'a>|) {
|
||||
if_ok!(write!(self.wr, r"\{"));
|
||||
try!(write!(self.wr, r"\{"));
|
||||
f(self);
|
||||
if_ok!(write!(self.wr, r"\}"));
|
||||
try!(write!(self.wr, r"\}"));
|
||||
}
|
||||
|
||||
fn emit_map_elt_key(&mut self, idx: uint, f: |&mut Encoder<'a>|) {
|
||||
if idx != 0 { if_ok!(write!(self.wr, ",")) }
|
||||
if idx != 0 { try!(write!(self.wr, ",")) }
|
||||
f(self)
|
||||
}
|
||||
|
||||
fn emit_map_elt_val(&mut self, _idx: uint, f: |&mut Encoder<'a>|) {
|
||||
if_ok!(write!(self.wr, ":"));
|
||||
try!(write!(self.wr, ":"));
|
||||
f(self)
|
||||
}
|
||||
}
|
||||
|
@ -503,7 +503,7 @@ impl<'a> PrettyEncoder<'a> {
|
|||
}
|
||||
|
||||
impl<'a> serialize::Encoder for PrettyEncoder<'a> {
|
||||
fn emit_nil(&mut self) { if_ok!(write!(self.wr, "null")); }
|
||||
fn emit_nil(&mut self) { try!(write!(self.wr, "null")); }
|
||||
|
||||
fn emit_uint(&mut self, v: uint) { self.emit_f64(v as f64); }
|
||||
fn emit_u64(&mut self, v: u64) { self.emit_f64(v as f64); }
|
||||
|
@ -519,20 +519,20 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> {
|
|||
|
||||
fn emit_bool(&mut self, v: bool) {
|
||||
if v {
|
||||
if_ok!(write!(self.wr, "true"));
|
||||
try!(write!(self.wr, "true"));
|
||||
} else {
|
||||
if_ok!(write!(self.wr, "false"));
|
||||
try!(write!(self.wr, "false"));
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_f64(&mut self, v: f64) {
|
||||
if_ok!(write!(self.wr, "{}", f64::to_str_digits(v, 6u)));
|
||||
try!(write!(self.wr, "{}", f64::to_str_digits(v, 6u)));
|
||||
}
|
||||
fn emit_f32(&mut self, v: f32) { self.emit_f64(v as f64); }
|
||||
|
||||
fn emit_char(&mut self, v: char) { self.emit_str(str::from_char(v)) }
|
||||
fn emit_str(&mut self, v: &str) {
|
||||
if_ok!(write!(self.wr, "{}", escape_str(v)));
|
||||
try!(write!(self.wr, "{}", escape_str(v)));
|
||||
}
|
||||
|
||||
fn emit_enum(&mut self, _name: &str, f: |&mut PrettyEncoder<'a>|) {
|
||||
|
@ -545,14 +545,14 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> {
|
|||
cnt: uint,
|
||||
f: |&mut PrettyEncoder<'a>|) {
|
||||
if cnt == 0 {
|
||||
if_ok!(write!(self.wr, "{}", escape_str(name)));
|
||||
try!(write!(self.wr, "{}", escape_str(name)));
|
||||
} else {
|
||||
self.indent += 2;
|
||||
if_ok!(write!(self.wr, "[\n{}{},\n", spaces(self.indent),
|
||||
try!(write!(self.wr, "[\n{}{},\n", spaces(self.indent),
|
||||
escape_str(name)));
|
||||
f(self);
|
||||
self.indent -= 2;
|
||||
if_ok!(write!(self.wr, "\n{}]", spaces(self.indent)));
|
||||
try!(write!(self.wr, "\n{}]", spaces(self.indent)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -560,9 +560,9 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> {
|
|||
idx: uint,
|
||||
f: |&mut PrettyEncoder<'a>|) {
|
||||
if idx != 0 {
|
||||
if_ok!(write!(self.wr, ",\n"));
|
||||
try!(write!(self.wr, ",\n"));
|
||||
}
|
||||
if_ok!(write!(self.wr, "{}", spaces(self.indent)));
|
||||
try!(write!(self.wr, "{}", spaces(self.indent)));
|
||||
f(self)
|
||||
}
|
||||
|
||||
|
@ -587,13 +587,13 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> {
|
|||
len: uint,
|
||||
f: |&mut PrettyEncoder<'a>|) {
|
||||
if len == 0 {
|
||||
if_ok!(write!(self.wr, "\\{\\}"));
|
||||
try!(write!(self.wr, "\\{\\}"));
|
||||
} else {
|
||||
if_ok!(write!(self.wr, "\\{"));
|
||||
try!(write!(self.wr, "\\{"));
|
||||
self.indent += 2;
|
||||
f(self);
|
||||
self.indent -= 2;
|
||||
if_ok!(write!(self.wr, "\n{}\\}", spaces(self.indent)));
|
||||
try!(write!(self.wr, "\n{}\\}", spaces(self.indent)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -602,11 +602,11 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> {
|
|||
idx: uint,
|
||||
f: |&mut PrettyEncoder<'a>|) {
|
||||
if idx == 0 {
|
||||
if_ok!(write!(self.wr, "\n"));
|
||||
try!(write!(self.wr, "\n"));
|
||||
} else {
|
||||
if_ok!(write!(self.wr, ",\n"));
|
||||
try!(write!(self.wr, ",\n"));
|
||||
}
|
||||
if_ok!(write!(self.wr, "{}{}: ", spaces(self.indent), escape_str(name)));
|
||||
try!(write!(self.wr, "{}{}: ", spaces(self.indent), escape_str(name)));
|
||||
f(self);
|
||||
}
|
||||
|
||||
|
@ -635,50 +635,50 @@ impl<'a> serialize::Encoder for PrettyEncoder<'a> {
|
|||
|
||||
fn emit_seq(&mut self, len: uint, f: |&mut PrettyEncoder<'a>|) {
|
||||
if len == 0 {
|
||||
if_ok!(write!(self.wr, "[]"));
|
||||
try!(write!(self.wr, "[]"));
|
||||
} else {
|
||||
if_ok!(write!(self.wr, "["));
|
||||
try!(write!(self.wr, "["));
|
||||
self.indent += 2;
|
||||
f(self);
|
||||
self.indent -= 2;
|
||||
if_ok!(write!(self.wr, "\n{}]", spaces(self.indent)));
|
||||
try!(write!(self.wr, "\n{}]", spaces(self.indent)));
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_seq_elt(&mut self, idx: uint, f: |&mut PrettyEncoder<'a>|) {
|
||||
if idx == 0 {
|
||||
if_ok!(write!(self.wr, "\n"));
|
||||
try!(write!(self.wr, "\n"));
|
||||
} else {
|
||||
if_ok!(write!(self.wr, ",\n"));
|
||||
try!(write!(self.wr, ",\n"));
|
||||
}
|
||||
if_ok!(write!(self.wr, "{}", spaces(self.indent)));
|
||||
try!(write!(self.wr, "{}", spaces(self.indent)));
|
||||
f(self)
|
||||
}
|
||||
|
||||
fn emit_map(&mut self, len: uint, f: |&mut PrettyEncoder<'a>|) {
|
||||
if len == 0 {
|
||||
if_ok!(write!(self.wr, "\\{\\}"));
|
||||
try!(write!(self.wr, "\\{\\}"));
|
||||
} else {
|
||||
if_ok!(write!(self.wr, "\\{"));
|
||||
try!(write!(self.wr, "\\{"));
|
||||
self.indent += 2;
|
||||
f(self);
|
||||
self.indent -= 2;
|
||||
if_ok!(write!(self.wr, "\n{}\\}", spaces(self.indent)));
|
||||
try!(write!(self.wr, "\n{}\\}", spaces(self.indent)));
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_map_elt_key(&mut self, idx: uint, f: |&mut PrettyEncoder<'a>|) {
|
||||
if idx == 0 {
|
||||
if_ok!(write!(self.wr, "\n"));
|
||||
try!(write!(self.wr, "\n"));
|
||||
} else {
|
||||
if_ok!(write!(self.wr, ",\n"));
|
||||
try!(write!(self.wr, ",\n"));
|
||||
}
|
||||
if_ok!(write!(self.wr, "{}", spaces(self.indent)));
|
||||
try!(write!(self.wr, "{}", spaces(self.indent)));
|
||||
f(self);
|
||||
}
|
||||
|
||||
fn emit_map_elt_val(&mut self, _idx: uint, f: |&mut PrettyEncoder<'a>|) {
|
||||
if_ok!(write!(self.wr, ": "));
|
||||
try!(write!(self.wr, ": "));
|
||||
f(self);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -376,48 +376,48 @@ pub fn write_boxplot(w: &mut io::Writer, s: &Summary,
|
|||
let range_width = width_hint - overhead_width;;
|
||||
let char_step = range / (range_width as f64);
|
||||
|
||||
if_ok!(write!(w, "{} |", lostr));
|
||||
try!(write!(w, "{} |", lostr));
|
||||
|
||||
let mut c = 0;
|
||||
let mut v = lo;
|
||||
|
||||
while c < range_width && v < s.min {
|
||||
if_ok!(write!(w, " "));
|
||||
try!(write!(w, " "));
|
||||
v += char_step;
|
||||
c += 1;
|
||||
}
|
||||
if_ok!(write!(w, "["));
|
||||
try!(write!(w, "["));
|
||||
c += 1;
|
||||
while c < range_width && v < q1 {
|
||||
if_ok!(write!(w, "-"));
|
||||
try!(write!(w, "-"));
|
||||
v += char_step;
|
||||
c += 1;
|
||||
}
|
||||
while c < range_width && v < q2 {
|
||||
if_ok!(write!(w, "*"));
|
||||
try!(write!(w, "*"));
|
||||
v += char_step;
|
||||
c += 1;
|
||||
}
|
||||
if_ok!(write!(w, r"\#"));
|
||||
try!(write!(w, r"\#"));
|
||||
c += 1;
|
||||
while c < range_width && v < q3 {
|
||||
if_ok!(write!(w, "*"));
|
||||
try!(write!(w, "*"));
|
||||
v += char_step;
|
||||
c += 1;
|
||||
}
|
||||
while c < range_width && v < s.max {
|
||||
if_ok!(write!(w, "-"));
|
||||
try!(write!(w, "-"));
|
||||
v += char_step;
|
||||
c += 1;
|
||||
}
|
||||
if_ok!(write!(w, "]"));
|
||||
try!(write!(w, "]"));
|
||||
while c < range_width {
|
||||
if_ok!(write!(w, " "));
|
||||
try!(write!(w, " "));
|
||||
v += char_step;
|
||||
c += 1;
|
||||
}
|
||||
|
||||
if_ok!(write!(w, "| {}", histr));
|
||||
try!(write!(w, "| {}", histr));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -77,8 +77,8 @@ impl Drop for Inner {
|
|||
}
|
||||
|
||||
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,
|
||||
|
@ -90,8 +90,8 @@ fn connect(addr: &CString, ty: libc::c_int) -> IoResult<Inner> {
|
|||
}
|
||||
|
||||
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)
|
||||
|
@ -198,7 +198,7 @@ impl UnixDatagram {
|
|||
}
|
||||
|
||||
pub fn sendto(&mut self, buf: &[u8], dst: &CString) -> IoResult<()> {
|
||||
let (dst, len) = if_ok!(addr_to_sockaddr_un(dst));
|
||||
let (dst, len) = try!(addr_to_sockaddr_un(dst));
|
||||
let dstp = &dst as *libc::sockaddr_storage;
|
||||
let ret = retry(|| unsafe {
|
||||
libc::sendto(self.fd(),
|
||||
|
|
|
@ -262,7 +262,7 @@ impl UnixStream {
|
|||
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;
|
||||
|
@ -298,7 +298,7 @@ impl rtio::RtioPipe for UnixStream {
|
|||
|
||||
fn write(&mut self, buf: &[u8]) -> IoResult<()> {
|
||||
if self.write.is_none() {
|
||||
self.write = Some(if_ok!(Event::new(true, false)));
|
||||
self.write = Some(try!(Event::new(true, false)));
|
||||
}
|
||||
|
||||
let mut offset = 0;
|
||||
|
@ -371,7 +371,7 @@ impl UnixListener {
|
|||
pub fn native_listen(self) -> IoResult<UnixAcceptor> {
|
||||
Ok(UnixAcceptor {
|
||||
listener: self,
|
||||
event: if_ok!(Event::new(true, false)),
|
||||
event: try!(Event::new(true, false)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -161,7 +161,7 @@ impl Archive {
|
|||
// We skip any files explicitly desired for skipping, and we also skip
|
||||
// all SYMDEF files as these are just magical placeholders which get
|
||||
// re-created when we make a new archive anyway.
|
||||
let files = if_ok!(fs::readdir(loc.path()));
|
||||
let files = try!(fs::readdir(loc.path()));
|
||||
let mut inputs = ~[];
|
||||
for file in files.iter() {
|
||||
let filename = file.filename_str().unwrap();
|
||||
|
@ -170,7 +170,7 @@ impl Archive {
|
|||
|
||||
let filename = format!("r-{}-{}", name, filename);
|
||||
let new_filename = file.with_filename(filename);
|
||||
if_ok!(fs::rename(file, &new_filename));
|
||||
try!(fs::rename(file, &new_filename));
|
||||
inputs.push(new_filename);
|
||||
}
|
||||
if inputs.len() == 0 { return Ok(()) }
|
||||
|
|
|
@ -521,9 +521,9 @@ fn write_out_deps(sess: Session,
|
|||
})
|
||||
.collect()
|
||||
};
|
||||
let mut file = if_ok!(io::File::create(&deps_filename));
|
||||
let mut file = try!(io::File::create(&deps_filename));
|
||||
for path in out_filenames.iter() {
|
||||
if_ok!(write!(&mut file as &mut Writer,
|
||||
try!(write!(&mut file as &mut Writer,
|
||||
"{}: {}\n\n", path.display(), files.connect(" ")));
|
||||
}
|
||||
Ok(())
|
||||
|
@ -575,21 +575,21 @@ impl pprust::PpAnn for IdentifiedAnnotation {
|
|||
fn post(&self, node: pprust::AnnNode) -> io::IoResult<()> {
|
||||
match node {
|
||||
pprust::NodeItem(s, item) => {
|
||||
if_ok!(pp::space(&mut s.s));
|
||||
if_ok!(pprust::synth_comment(s, item.id.to_str()));
|
||||
try!(pp::space(&mut s.s));
|
||||
try!(pprust::synth_comment(s, item.id.to_str()));
|
||||
}
|
||||
pprust::NodeBlock(s, blk) => {
|
||||
if_ok!(pp::space(&mut s.s));
|
||||
if_ok!(pprust::synth_comment(s, ~"block " + blk.id.to_str()));
|
||||
try!(pp::space(&mut s.s));
|
||||
try!(pprust::synth_comment(s, ~"block " + blk.id.to_str()));
|
||||
}
|
||||
pprust::NodeExpr(s, expr) => {
|
||||
if_ok!(pp::space(&mut s.s));
|
||||
if_ok!(pprust::synth_comment(s, expr.id.to_str()));
|
||||
if_ok!(pprust::pclose(s));
|
||||
try!(pp::space(&mut s.s));
|
||||
try!(pprust::synth_comment(s, expr.id.to_str()));
|
||||
try!(pprust::pclose(s));
|
||||
}
|
||||
pprust::NodePat(s, pat) => {
|
||||
if_ok!(pp::space(&mut s.s));
|
||||
if_ok!(pprust::synth_comment(s, ~"pat " + pat.id.to_str()));
|
||||
try!(pp::space(&mut s.s));
|
||||
try!(pprust::synth_comment(s, ~"pat " + pat.id.to_str()));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -611,12 +611,12 @@ impl pprust::PpAnn for TypedAnnotation {
|
|||
let tcx = self.analysis.ty_cx;
|
||||
match node {
|
||||
pprust::NodeExpr(s, expr) => {
|
||||
if_ok!(pp::space(&mut s.s));
|
||||
if_ok!(pp::word(&mut s.s, "as"));
|
||||
if_ok!(pp::space(&mut s.s));
|
||||
if_ok!(pp::word(&mut s.s,
|
||||
try!(pp::space(&mut s.s));
|
||||
try!(pp::word(&mut s.s, "as"));
|
||||
try!(pp::space(&mut s.s));
|
||||
try!(pp::word(&mut s.s,
|
||||
ppaux::ty_to_str(tcx, ty::expr_ty(tcx, expr))));
|
||||
if_ok!(pprust::pclose(s));
|
||||
try!(pprust::pclose(s));
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
|
|
|
@ -1088,11 +1088,11 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::Attribute] {
|
|||
|
||||
fn list_crate_attributes(md: ebml::Doc, hash: &str,
|
||||
out: &mut io::Writer) -> io::IoResult<()> {
|
||||
if_ok!(write!(out, "=Crate Attributes ({})=\n", hash));
|
||||
try!(write!(out, "=Crate Attributes ({})=\n", hash));
|
||||
|
||||
let r = get_attributes(md);
|
||||
for attr in r.iter() {
|
||||
if_ok!(write!(out, "{}\n", pprust::attribute_to_str(attr)));
|
||||
try!(write!(out, "{}\n", pprust::attribute_to_str(attr)));
|
||||
}
|
||||
|
||||
write!(out, "\n\n")
|
||||
|
@ -1131,11 +1131,11 @@ pub fn get_crate_deps(data: &[u8]) -> ~[CrateDep] {
|
|||
}
|
||||
|
||||
fn list_crate_deps(data: &[u8], out: &mut io::Writer) -> io::IoResult<()> {
|
||||
if_ok!(write!(out, "=External Dependencies=\n"));
|
||||
try!(write!(out, "=External Dependencies=\n"));
|
||||
|
||||
let r = get_crate_deps(data);
|
||||
for dep in r.iter() {
|
||||
if_ok!(write!(out,
|
||||
try!(write!(out,
|
||||
"{} {}-{}-{}\n",
|
||||
dep.cnum,
|
||||
token::get_ident(dep.name),
|
||||
|
@ -1143,7 +1143,7 @@ fn list_crate_deps(data: &[u8], out: &mut io::Writer) -> io::IoResult<()> {
|
|||
dep.vers));
|
||||
}
|
||||
|
||||
if_ok!(write!(out, "\n"));
|
||||
try!(write!(out, "\n"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1164,7 +1164,7 @@ pub fn get_crate_vers(data: &[u8]) -> ~str {
|
|||
pub fn list_crate_metadata(bytes: &[u8], out: &mut io::Writer) -> io::IoResult<()> {
|
||||
let hash = get_crate_hash(bytes);
|
||||
let md = reader::Doc(bytes);
|
||||
if_ok!(list_crate_attributes(md, hash, out));
|
||||
try!(list_crate_attributes(md, hash, out));
|
||||
list_crate_deps(bytes, out)
|
||||
}
|
||||
|
||||
|
|
|
@ -113,8 +113,8 @@ impl<O:DataFlowOperator> pprust::PpAnn for DataFlowContext<O> {
|
|||
|
||||
let comment_str = format!("id {}: {}{}{}",
|
||||
id, entry_str, gens_str, kills_str);
|
||||
if_ok!(pprust::synth_comment(ps, comment_str));
|
||||
if_ok!(pp::space(&mut ps.s));
|
||||
try!(pprust::synth_comment(ps, comment_str));
|
||||
try!(pp::space(&mut ps.s));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -351,10 +351,10 @@ impl<O:DataFlowOperator+Clone+'static> DataFlowContext<O> {
|
|||
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(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -740,7 +740,7 @@ impl Liveness {
|
|||
for var_idx in range(0u, self.ir.num_vars.get()) {
|
||||
let idx = node_base_idx + var_idx;
|
||||
if test(idx).is_valid() {
|
||||
if_ok!(write!(wr, " {}", Variable(var_idx).to_str()));
|
||||
try!(write!(wr, " {}", Variable(var_idx).to_str()));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -29,7 +29,7 @@ impl<'a> fmt::Show for Escape<'a> {
|
|||
for (i, ch) in s.bytes().enumerate() {
|
||||
match ch as char {
|
||||
'<' | '>' | '&' | '\'' | '"' => {
|
||||
if_ok!(fmt.buf.write(pile_o_bits.slice(last, i).as_bytes()));
|
||||
try!(fmt.buf.write(pile_o_bits.slice(last, i).as_bytes()));
|
||||
let s = match ch as char {
|
||||
'>' => ">",
|
||||
'<' => "<",
|
||||
|
@ -38,7 +38,7 @@ impl<'a> fmt::Show for Escape<'a> {
|
|||
'"' => """,
|
||||
_ => unreachable!()
|
||||
};
|
||||
if_ok!(fmt.buf.write(s.as_bytes()));
|
||||
try!(fmt.buf.write(s.as_bytes()));
|
||||
last = i + 1;
|
||||
}
|
||||
_ => {}
|
||||
|
@ -46,7 +46,7 @@ impl<'a> fmt::Show for Escape<'a> {
|
|||
}
|
||||
|
||||
if last < s.len() {
|
||||
if_ok!(fmt.buf.write(pile_o_bits.slice_from(last).as_bytes()));
|
||||
try!(fmt.buf.write(pile_o_bits.slice_from(last).as_bytes()));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -50,46 +50,46 @@ impl PuritySpace {
|
|||
impl fmt::Show for clean::Generics {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if self.lifetimes.len() == 0 && self.type_params.len() == 0 { return Ok(()) }
|
||||
if_ok!(f.buf.write("<".as_bytes()));
|
||||
try!(f.buf.write("<".as_bytes()));
|
||||
|
||||
for (i, life) in self.lifetimes.iter().enumerate() {
|
||||
if i > 0 {
|
||||
if_ok!(f.buf.write(", ".as_bytes()));
|
||||
try!(f.buf.write(", ".as_bytes()));
|
||||
}
|
||||
if_ok!(write!(f.buf, "{}", *life));
|
||||
try!(write!(f.buf, "{}", *life));
|
||||
}
|
||||
|
||||
if self.type_params.len() > 0 {
|
||||
if self.lifetimes.len() > 0 {
|
||||
if_ok!(f.buf.write(", ".as_bytes()));
|
||||
try!(f.buf.write(", ".as_bytes()));
|
||||
}
|
||||
|
||||
for (i, tp) in self.type_params.iter().enumerate() {
|
||||
if i > 0 {
|
||||
if_ok!(f.buf.write(", ".as_bytes()))
|
||||
try!(f.buf.write(", ".as_bytes()))
|
||||
}
|
||||
if_ok!(f.buf.write(tp.name.as_bytes()));
|
||||
try!(f.buf.write(tp.name.as_bytes()));
|
||||
|
||||
if tp.bounds.len() > 0 {
|
||||
if_ok!(f.buf.write(": ".as_bytes()));
|
||||
try!(f.buf.write(": ".as_bytes()));
|
||||
for (i, bound) in tp.bounds.iter().enumerate() {
|
||||
if i > 0 {
|
||||
if_ok!(f.buf.write(" + ".as_bytes()));
|
||||
try!(f.buf.write(" + ".as_bytes()));
|
||||
}
|
||||
if_ok!(write!(f.buf, "{}", *bound));
|
||||
try!(write!(f.buf, "{}", *bound));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if_ok!(f.buf.write(">".as_bytes()));
|
||||
try!(f.buf.write(">".as_bytes()));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Show for clean::Lifetime {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if_ok!(f.buf.write("'".as_bytes()));
|
||||
if_ok!(f.buf.write(self.get_ref().as_bytes()));
|
||||
try!(f.buf.write("'".as_bytes()));
|
||||
try!(f.buf.write(self.get_ref().as_bytes()));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -110,32 +110,32 @@ impl fmt::Show for clean::TyParamBound {
|
|||
impl fmt::Show for clean::Path {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if self.global {
|
||||
if_ok!(f.buf.write("::".as_bytes()))
|
||||
try!(f.buf.write("::".as_bytes()))
|
||||
}
|
||||
for (i, seg) in self.segments.iter().enumerate() {
|
||||
if i > 0 {
|
||||
if_ok!(f.buf.write("::".as_bytes()))
|
||||
try!(f.buf.write("::".as_bytes()))
|
||||
}
|
||||
if_ok!(f.buf.write(seg.name.as_bytes()));
|
||||
try!(f.buf.write(seg.name.as_bytes()));
|
||||
|
||||
if seg.lifetimes.len() > 0 || seg.types.len() > 0 {
|
||||
if_ok!(f.buf.write("<".as_bytes()));
|
||||
try!(f.buf.write("<".as_bytes()));
|
||||
let mut comma = false;
|
||||
for lifetime in seg.lifetimes.iter() {
|
||||
if comma {
|
||||
if_ok!(f.buf.write(", ".as_bytes()));
|
||||
try!(f.buf.write(", ".as_bytes()));
|
||||
}
|
||||
comma = true;
|
||||
if_ok!(write!(f.buf, "{}", *lifetime));
|
||||
try!(write!(f.buf, "{}", *lifetime));
|
||||
}
|
||||
for ty in seg.types.iter() {
|
||||
if comma {
|
||||
if_ok!(f.buf.write(", ".as_bytes()));
|
||||
try!(f.buf.write(", ".as_bytes()));
|
||||
}
|
||||
comma = true;
|
||||
if_ok!(write!(f.buf, "{}", *ty));
|
||||
try!(write!(f.buf, "{}", *ty));
|
||||
}
|
||||
if_ok!(f.buf.write(">".as_bytes()));
|
||||
try!(f.buf.write(">".as_bytes()));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -222,11 +222,11 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
|
|||
let mut root = root;
|
||||
for seg in path.segments.slice_to(amt).iter() {
|
||||
if "super" == seg.name || "self" == seg.name {
|
||||
if_ok!(write!(w, "{}::", seg.name));
|
||||
try!(write!(w, "{}::", seg.name));
|
||||
} else {
|
||||
root.push_str(seg.name);
|
||||
root.push_str("/");
|
||||
if_ok!(write!(w, "<a class='mod'
|
||||
try!(write!(w, "<a class='mod'
|
||||
href='{}index.html'>{}</a>::",
|
||||
root,
|
||||
seg.name));
|
||||
|
@ -235,7 +235,7 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
|
|||
}
|
||||
None => {
|
||||
for seg in path.segments.slice_to(amt).iter() {
|
||||
if_ok!(write!(w, "{}::", seg.name));
|
||||
try!(write!(w, "{}::", seg.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -263,15 +263,15 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
|
|||
}
|
||||
}
|
||||
|
||||
if_ok!(write!(w, "<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(())
|
||||
})
|
||||
})
|
||||
|
@ -282,14 +282,14 @@ fn typarams(w: &mut io::Writer,
|
|||
typarams: &Option<~[clean::TyParamBound]>) -> fmt::Result {
|
||||
match *typarams {
|
||||
Some(ref params) => {
|
||||
if_ok!(write!(w, "<"));
|
||||
try!(write!(w, "<"));
|
||||
for (i, param) in params.iter().enumerate() {
|
||||
if i > 0 {
|
||||
if_ok!(write!(w, ", "));
|
||||
try!(write!(w, ", "));
|
||||
}
|
||||
if_ok!(write!(w, "{}", *param));
|
||||
try!(write!(w, "{}", *param));
|
||||
}
|
||||
if_ok!(write!(w, ">"));
|
||||
try!(write!(w, ">"));
|
||||
Ok(())
|
||||
}
|
||||
None => Ok(())
|
||||
|
@ -306,12 +306,12 @@ impl fmt::Show for clean::Type {
|
|||
})
|
||||
}
|
||||
clean::ResolvedPath{id, typarams: ref tp, path: ref path} => {
|
||||
if_ok!(resolved_path(f.buf, id, path, false));
|
||||
try!(resolved_path(f.buf, id, path, false));
|
||||
typarams(f.buf, tp)
|
||||
}
|
||||
clean::ExternalPath{path: ref path, typarams: ref tp,
|
||||
fqn: ref fqn, kind, krate} => {
|
||||
if_ok!(external_path(f.buf, path, false, fqn.as_slice(), kind,
|
||||
try!(external_path(f.buf, path, false, fqn.as_slice(), kind,
|
||||
krate))
|
||||
typarams(f.buf, tp)
|
||||
}
|
||||
|
@ -364,12 +364,12 @@ impl fmt::Show for clean::Type {
|
|||
decl.decl)
|
||||
}
|
||||
clean::Tuple(ref typs) => {
|
||||
if_ok!(f.buf.write("(".as_bytes()));
|
||||
try!(f.buf.write("(".as_bytes()));
|
||||
for (i, typ) in typs.iter().enumerate() {
|
||||
if i > 0 {
|
||||
if_ok!(f.buf.write(", ".as_bytes()))
|
||||
try!(f.buf.write(", ".as_bytes()))
|
||||
}
|
||||
if_ok!(write!(f.buf, "{}", *typ));
|
||||
try!(write!(f.buf, "{}", *typ));
|
||||
}
|
||||
f.buf.write(")".as_bytes())
|
||||
}
|
||||
|
@ -407,11 +407,11 @@ impl fmt::Show for clean::Type {
|
|||
impl fmt::Show for clean::Arguments {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
for (i, input) in self.values.iter().enumerate() {
|
||||
if i > 0 { if_ok!(write!(f.buf, ", ")); }
|
||||
if i > 0 { try!(write!(f.buf, ", ")); }
|
||||
if input.name.len() > 0 {
|
||||
if_ok!(write!(f.buf, "{}: ", input.name));
|
||||
try!(write!(f.buf, "{}: ", input.name));
|
||||
}
|
||||
if_ok!(write!(f.buf, "{}", input.type_));
|
||||
try!(write!(f.buf, "{}", input.type_));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -495,12 +495,12 @@ impl fmt::Show for clean::ViewPath {
|
|||
write!(f.buf, "use {}::*;", *src)
|
||||
}
|
||||
clean::ImportList(ref src, ref names) => {
|
||||
if_ok!(write!(f.buf, "use {}::\\{", *src));
|
||||
try!(write!(f.buf, "use {}::\\{", *src));
|
||||
for (i, n) in names.iter().enumerate() {
|
||||
if i > 0 {
|
||||
if_ok!(write!(f.buf, ", "));
|
||||
try!(write!(f.buf, ", "));
|
||||
}
|
||||
if_ok!(write!(f.buf, "{}", *n));
|
||||
try!(write!(f.buf, "{}", *n));
|
||||
}
|
||||
write!(f.buf, "\\};")
|
||||
}
|
||||
|
@ -518,9 +518,9 @@ impl fmt::Show for clean::ImportSource {
|
|||
_ => {
|
||||
for (i, seg) in self.path.segments.iter().enumerate() {
|
||||
if i > 0 {
|
||||
if_ok!(write!(f.buf, "::"))
|
||||
try!(write!(f.buf, "::"))
|
||||
}
|
||||
if_ok!(write!(f.buf, "{}", seg.name));
|
||||
try!(write!(f.buf, "{}", seg.name));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -209,7 +209,7 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
|
|||
},
|
||||
include_sources: true,
|
||||
};
|
||||
if_ok!(mkdir(&cx.dst));
|
||||
try!(mkdir(&cx.dst));
|
||||
|
||||
match krate.module.as_ref().map(|m| m.doc_list().unwrap_or(&[])) {
|
||||
Some(attrs) => {
|
||||
|
@ -254,12 +254,12 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
|
|||
|
||||
// Add all the static files
|
||||
let mut dst = cx.dst.join(krate.name.as_slice());
|
||||
if_ok!(mkdir(&dst));
|
||||
if_ok!(write(dst.join("jquery.js"),
|
||||
try!(mkdir(&dst));
|
||||
try!(write(dst.join("jquery.js"),
|
||||
include_str!("static/jquery-2.1.0.min.js")));
|
||||
if_ok!(write(dst.join("main.js"), include_str!("static/main.js")));
|
||||
if_ok!(write(dst.join("main.css"), include_str!("static/main.css")));
|
||||
if_ok!(write(dst.join("normalize.css"),
|
||||
try!(write(dst.join("main.js"), include_str!("static/main.js")));
|
||||
try!(write(dst.join("main.css"), include_str!("static/main.css")));
|
||||
try!(write(dst.join("normalize.css"),
|
||||
include_str!("static/normalize.css")));
|
||||
|
||||
// Publish the search index
|
||||
|
@ -267,42 +267,42 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
|
|||
dst.push("search-index.js");
|
||||
let mut w = BufferedWriter::new(File::create(&dst).unwrap());
|
||||
let w = &mut w as &mut Writer;
|
||||
if_ok!(write!(w, "var searchIndex = ["));
|
||||
try!(write!(w, "var searchIndex = ["));
|
||||
for (i, item) in cache.search_index.iter().enumerate() {
|
||||
if i > 0 {
|
||||
if_ok!(write!(w, ","));
|
||||
try!(write!(w, ","));
|
||||
}
|
||||
if_ok!(write!(w, "\\{ty:\"{}\",name:\"{}\",path:\"{}\",desc:{}",
|
||||
try!(write!(w, "\\{ty:\"{}\",name:\"{}\",path:\"{}\",desc:{}",
|
||||
item.ty, item.name, item.path,
|
||||
item.desc.to_json().to_str()));
|
||||
match item.parent {
|
||||
Some(id) => {
|
||||
if_ok!(write!(w, ",parent:'{}'", id));
|
||||
try!(write!(w, ",parent:'{}'", id));
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
if_ok!(write!(w, "\\}"));
|
||||
try!(write!(w, "\\}"));
|
||||
}
|
||||
if_ok!(write!(w, "];"));
|
||||
if_ok!(write!(w, "var allPaths = \\{"));
|
||||
try!(write!(w, "];"));
|
||||
try!(write!(w, "var allPaths = \\{"));
|
||||
for (i, (&id, &(ref fqp, short))) in cache.paths.iter().enumerate() {
|
||||
if i > 0 {
|
||||
if_ok!(write!(w, ","));
|
||||
try!(write!(w, ","));
|
||||
}
|
||||
if_ok!(write!(w, "'{}':\\{type:'{}',name:'{}'\\}",
|
||||
try!(write!(w, "'{}':\\{type:'{}',name:'{}'\\}",
|
||||
id, short, *fqp.last().unwrap()));
|
||||
}
|
||||
if_ok!(write!(w, "\\};"));
|
||||
if_ok!(w.flush());
|
||||
try!(write!(w, "\\};"));
|
||||
try!(w.flush());
|
||||
}
|
||||
|
||||
// Render all source files (this may turn into a giant no-op)
|
||||
{
|
||||
info!("emitting source files");
|
||||
let dst = cx.dst.join("src");
|
||||
if_ok!(mkdir(&dst));
|
||||
try!(mkdir(&dst));
|
||||
let dst = dst.join(krate.name.as_slice());
|
||||
if_ok!(mkdir(&dst));
|
||||
try!(mkdir(&dst));
|
||||
let mut folder = SourceCollector {
|
||||
dst: dst,
|
||||
seen: HashSet::new(),
|
||||
|
@ -442,7 +442,7 @@ impl<'a> SourceCollector<'a> {
|
|||
});
|
||||
|
||||
cur.push(p.filename().expect("source has no filename") + bytes!(".html"));
|
||||
let mut w = BufferedWriter::new(if_ok!(File::create(&cur)));
|
||||
let mut w = BufferedWriter::new(try!(File::create(&cur)));
|
||||
|
||||
let title = format!("{} -- source", cur.filename_display());
|
||||
let page = layout::Page {
|
||||
|
@ -450,9 +450,9 @@ impl<'a> SourceCollector<'a> {
|
|||
ty: "source",
|
||||
root_path: root_path,
|
||||
};
|
||||
if_ok!(layout::render(&mut w as &mut Writer, &self.cx.layout,
|
||||
try!(layout::render(&mut w as &mut Writer, &self.cx.layout,
|
||||
&page, &(""), &Source(contents.as_slice())));
|
||||
if_ok!(w.flush());
|
||||
try!(w.flush());
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
@ -714,7 +714,7 @@ impl Context {
|
|||
let mut work = ~[(self, item)];
|
||||
loop {
|
||||
match work.pop() {
|
||||
Some((mut cx, item)) => if_ok!(cx.item(item, |cx, item| {
|
||||
Some((mut cx, item)) => try!(cx.item(item, |cx, item| {
|
||||
work.push((cx.clone(), item));
|
||||
})),
|
||||
None => break,
|
||||
|
@ -753,7 +753,7 @@ impl Context {
|
|||
// of the pain by using a buffered writer instead of invoking the
|
||||
// write sycall all the time.
|
||||
let mut writer = BufferedWriter::new(w);
|
||||
if_ok!(layout::render(&mut writer as &mut Writer, &cx.layout, &page,
|
||||
try!(layout::render(&mut writer as &mut Writer, &cx.layout, &page,
|
||||
&Sidebar{ cx: cx, item: it },
|
||||
&Item{ cx: cx, item: it }));
|
||||
writer.flush()
|
||||
|
@ -768,8 +768,8 @@ impl Context {
|
|||
self.recurse(name, |this| {
|
||||
let item = item.take_unwrap();
|
||||
let dst = this.dst.join("index.html");
|
||||
let dst = if_ok!(File::create(&dst));
|
||||
if_ok!(render(dst, this, &item, false));
|
||||
let dst = try!(File::create(&dst));
|
||||
try!(render(dst, this, &item, false));
|
||||
|
||||
let m = match item.inner {
|
||||
clean::ModuleItem(m) => m,
|
||||
|
@ -787,7 +787,7 @@ impl Context {
|
|||
// pages dedicated to them.
|
||||
_ if item.name.is_some() => {
|
||||
let dst = self.dst.join(item_path(&item));
|
||||
let dst = if_ok!(File::create(&dst));
|
||||
let dst = try!(File::create(&dst));
|
||||
render(dst, self, &item, true)
|
||||
}
|
||||
|
||||
|
@ -829,7 +829,7 @@ impl<'a> fmt::Show for Item<'a> {
|
|||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
match attr::find_stability(self.item.attrs.iter()) {
|
||||
Some(ref stability) => {
|
||||
if_ok!(write!(fmt.buf,
|
||||
try!(write!(fmt.buf,
|
||||
"<a class='stability {lvl}' title='{reason}'>{lvl}</a>",
|
||||
lvl = stability.level.to_str(),
|
||||
reason = match stability.text {
|
||||
|
@ -850,7 +850,7 @@ impl<'a> fmt::Show for Item<'a> {
|
|||
} else {
|
||||
format!("{}-{}", self.item.source.loline, self.item.source.hiline)
|
||||
};
|
||||
if_ok!(write!(fmt.buf,
|
||||
try!(write!(fmt.buf,
|
||||
"<a class='source'
|
||||
href='{root}src/{krate}/{path}.html\\#{href}'>\
|
||||
[src]</a>",
|
||||
|
@ -861,13 +861,13 @@ impl<'a> fmt::Show for Item<'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();
|
||||
|
@ -877,10 +877,10 @@ impl<'a> fmt::Show for Item<'a> {
|
|||
for _ in range(0, cur.len() - i - 1) {
|
||||
trail.push_str("../");
|
||||
}
|
||||
if_ok!(write!(fmt.buf, "<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 {
|
||||
|
@ -932,7 +932,7 @@ fn shorter<'a>(s: Option<&'a str>) -> &'a str {
|
|||
fn document(w: &mut Writer, item: &clean::Item) -> fmt::Result {
|
||||
match item.doc_value() {
|
||||
Some(s) => {
|
||||
if_ok!(write!(w, "<div class='docblock'>{}</div>", Markdown(s)));
|
||||
try!(write!(w, "<div class='docblock'>{}</div>", Markdown(s)));
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
@ -941,7 +941,7 @@ fn document(w: &mut Writer, item: &clean::Item) -> fmt::Result {
|
|||
|
||||
fn item_module(w: &mut Writer, cx: &Context,
|
||||
item: &clean::Item, items: &[clean::Item]) -> fmt::Result {
|
||||
if_ok!(document(w, item));
|
||||
try!(document(w, item));
|
||||
debug!("{:?}", items);
|
||||
let mut indices = vec::from_fn(items.len(), |i| i);
|
||||
|
||||
|
@ -994,10 +994,10 @@ fn item_module(w: &mut Writer, cx: &Context,
|
|||
let myty = shortty(myitem);
|
||||
if myty != curty {
|
||||
if curty != "" {
|
||||
if_ok!(write!(w, "</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",
|
||||
|
@ -1024,15 +1024,15 @@ fn item_module(w: &mut Writer, cx: &Context,
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let Initializer(s) = *self;
|
||||
if s.len() == 0 { return Ok(()); }
|
||||
if_ok!(write!(f.buf, "<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>
|
||||
|
@ -1048,19 +1048,19 @@ fn item_module(w: &mut Writer, cx: &Context,
|
|||
clean::ViewItemItem(ref item) => {
|
||||
match item.inner {
|
||||
clean::ExternMod(ref name, ref src, _) => {
|
||||
if_ok!(write!(w, "<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));
|
||||
}
|
||||
|
@ -1071,7 +1071,7 @@ fn item_module(w: &mut Writer, cx: &Context,
|
|||
|
||||
_ => {
|
||||
if myitem.name.is_none() { continue }
|
||||
if_ok!(write!(w, "
|
||||
try!(write!(w, "
|
||||
<tr>
|
||||
<td><a class='{class}' href='{href}'
|
||||
title='{title}'>{}</a></td>
|
||||
|
@ -1091,7 +1091,7 @@ fn item_module(w: &mut Writer, cx: &Context,
|
|||
|
||||
fn item_function(w: &mut Writer, it: &clean::Item,
|
||||
f: &clean::Function) -> fmt::Result {
|
||||
if_ok!(write!(w, "<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(),
|
||||
|
@ -1112,7 +1112,7 @@ fn item_trait(w: &mut Writer, it: &clean::Item,
|
|||
}
|
||||
|
||||
// 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,
|
||||
|
@ -1121,81 +1121,81 @@ fn item_trait(w: &mut Writer, it: &clean::Item,
|
|||
let provided = t.methods.iter().filter(|m| !m.is_req()).to_owned_vec();
|
||||
|
||||
if t.methods.len() == 0 {
|
||||
if_ok!(write!(w, "\\{ \\}"));
|
||||
try!(write!(w, "\\{ \\}"));
|
||||
} else {
|
||||
if_ok!(write!(w, "\\{\n"));
|
||||
try!(write!(w, "\\{\n"));
|
||||
for m in required.iter() {
|
||||
if_ok!(write!(w, " "));
|
||||
if_ok!(render_method(w, m.item()));
|
||||
if_ok!(write!(w, ";\n"));
|
||||
try!(write!(w, " "));
|
||||
try!(render_method(w, m.item()));
|
||||
try!(write!(w, ";\n"));
|
||||
}
|
||||
if required.len() > 0 && provided.len() > 0 {
|
||||
if_ok!(w.write("\n".as_bytes()));
|
||||
try!(w.write("\n".as_bytes()));
|
||||
}
|
||||
for m in provided.iter() {
|
||||
if_ok!(write!(w, " "));
|
||||
if_ok!(render_method(w, m.item()));
|
||||
if_ok!(write!(w, " \\{ ... \\}\n"));
|
||||
try!(write!(w, " "));
|
||||
try!(render_method(w, m.item()));
|
||||
try!(write!(w, " \\{ ... \\}\n"));
|
||||
}
|
||||
if_ok!(write!(w, "\\}"));
|
||||
try!(write!(w, "\\}"));
|
||||
}
|
||||
if_ok!(write!(w, "</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 => {}
|
||||
}
|
||||
|
@ -1231,23 +1231,23 @@ fn render_method(w: &mut Writer, meth: &clean::Item) -> fmt::Result {
|
|||
|
||||
fn item_struct(w: &mut Writer, it: &clean::Item,
|
||||
s: &clean::Struct) -> fmt::Result {
|
||||
if_ok!(write!(w, "<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>"));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
@ -1255,33 +1255,33 @@ fn item_struct(w: &mut Writer, it: &clean::Item,
|
|||
}
|
||||
|
||||
fn item_enum(w: &mut Writer, it: &clean::Item, e: &clean::Enum) -> fmt::Result {
|
||||
if_ok!(write!(w, "<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));
|
||||
}
|
||||
|
@ -1289,51 +1289,51 @@ fn item_enum(w: &mut Writer, it: &clean::Item, e: &clean::Enum) -> fmt::Result {
|
|||
}
|
||||
_ => unreachable!()
|
||||
}
|
||||
if_ok!(write!(w, ",\n"));
|
||||
try!(write!(w, ",\n"));
|
||||
}
|
||||
|
||||
if e.variants_stripped {
|
||||
if_ok!(write!(w, " // some variants omitted\n"));
|
||||
try!(write!(w, " // some variants omitted\n"));
|
||||
}
|
||||
if_ok!(write!(w, "\\}"));
|
||||
try!(write!(w, "\\}"));
|
||||
}
|
||||
if_ok!(write!(w, "</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(())
|
||||
}
|
||||
|
||||
|
@ -1344,21 +1344,21 @@ fn render_struct(w: &mut Writer, it: &clean::Item,
|
|||
fields_stripped: bool,
|
||||
tab: &str,
|
||||
structhead: bool) -> fmt::Result {
|
||||
if_ok!(write!(w, "{}{}{}",
|
||||
try!(write!(w, "{}{}{}",
|
||||
VisSpace(it.visibility),
|
||||
if structhead {"struct "} else {""},
|
||||
it.name.get_ref().as_slice()));
|
||||
match g {
|
||||
Some(g) => if_ok!(write!(w, "{}", *g)),
|
||||
Some(g) => try!(write!(w, "{}", *g)),
|
||||
None => {}
|
||||
}
|
||||
match ty {
|
||||
doctree::Plain => {
|
||||
if_ok!(write!(w, " \\{\n{}", tab));
|
||||
try!(write!(w, " \\{\n{}", tab));
|
||||
for field in fields.iter() {
|
||||
match field.inner {
|
||||
clean::StructFieldItem(ref ty) => {
|
||||
if_ok!(write!(w, " {}{}: {},\n{}",
|
||||
try!(write!(w, " {}{}: {},\n{}",
|
||||
VisSpace(field.visibility),
|
||||
field.name.get_ref().as_slice(),
|
||||
ty.type_,
|
||||
|
@ -1369,27 +1369,27 @@ fn render_struct(w: &mut Writer, it: &clean::Item,
|
|||
}
|
||||
|
||||
if fields_stripped {
|
||||
if_ok!(write!(w, " // some fields omitted\n{}", tab));
|
||||
try!(write!(w, " // some fields omitted\n{}", tab));
|
||||
}
|
||||
if_ok!(write!(w, "\\}"));
|
||||
try!(write!(w, "\\}"));
|
||||
}
|
||||
doctree::Tuple | doctree::Newtype => {
|
||||
if_ok!(write!(w, "("));
|
||||
try!(write!(w, "("));
|
||||
for (i, field) in fields.iter().enumerate() {
|
||||
if i > 0 {
|
||||
if_ok!(write!(w, ", "));
|
||||
try!(write!(w, ", "));
|
||||
}
|
||||
match field.inner {
|
||||
clean::StructFieldItem(ref field) => {
|
||||
if_ok!(write!(w, "{}", field.type_));
|
||||
try!(write!(w, "{}", field.type_));
|
||||
}
|
||||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
if_ok!(write!(w, ");"));
|
||||
try!(write!(w, ");"));
|
||||
}
|
||||
doctree::Unit => {
|
||||
if_ok!(write!(w, ";"));
|
||||
try!(write!(w, ";"));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -1410,16 +1410,16 @@ fn render_methods(w: &mut Writer, it: &clean::Item) -> fmt::Result {
|
|||
let traits = traits.to_owned_vec();
|
||||
|
||||
if non_trait.len() > 0 {
|
||||
if_ok!(write!(w, "<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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1431,10 +1431,10 @@ fn render_methods(w: &mut Writer, it: &clean::Item) -> fmt::Result {
|
|||
|
||||
fn render_impl(w: &mut Writer, i: &clean::Impl,
|
||||
dox: &Option<~str>) -> fmt::Result {
|
||||
if_ok!(write!(w, "<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,
|
||||
|
@ -1442,32 +1442,32 @@ fn render_impl(w: &mut Writer, i: &clean::Impl,
|
|||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -1476,7 +1476,7 @@ fn render_impl(w: &mut Writer, i: &clean::Impl,
|
|||
None => continue,
|
||||
Some(id) => id,
|
||||
};
|
||||
if_ok!(local_data::get(cache_key, |cache| {
|
||||
try!(local_data::get(cache_key, |cache| {
|
||||
let cache = cache.unwrap().get();
|
||||
match cache.traits.find(&trait_id) {
|
||||
Some(t) => {
|
||||
|
@ -1485,7 +1485,7 @@ fn render_impl(w: &mut Writer, i: &clean::Impl,
|
|||
Some(method) => {
|
||||
match method.item().doc_value() {
|
||||
Some(s) => {
|
||||
if_ok!(write!(w,
|
||||
try!(write!(w,
|
||||
"<div class='docblock'>{}</div>",
|
||||
Markdown(s)));
|
||||
}
|
||||
|
@ -1506,7 +1506,7 @@ fn render_impl(w: &mut Writer, i: &clean::Impl,
|
|||
match trait_id {
|
||||
None => {}
|
||||
Some(id) => {
|
||||
if_ok!(local_data::get(cache_key, |cache| {
|
||||
try!(local_data::get(cache_key, |cache| {
|
||||
let cache = cache.unwrap().get();
|
||||
match cache.traits.find(&id) {
|
||||
Some(t) => {
|
||||
|
@ -1517,7 +1517,7 @@ fn render_impl(w: &mut Writer, i: &clean::Impl,
|
|||
None => {}
|
||||
}
|
||||
|
||||
if_ok!(docmeth(w, method.item()));
|
||||
try!(docmeth(w, method.item()));
|
||||
}
|
||||
}
|
||||
None => {}
|
||||
|
@ -1526,13 +1526,13 @@ fn render_impl(w: &mut Writer, i: &clean::Impl,
|
|||
}))
|
||||
}
|
||||
}
|
||||
if_ok!(write!(w, "</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_));
|
||||
|
@ -1544,17 +1544,17 @@ impl<'a> fmt::Show for Sidebar<'a> {
|
|||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
let cx = self.cx;
|
||||
let it = self.item;
|
||||
if_ok!(write!(fmt.buf, "<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 {
|
||||
|
@ -1562,11 +1562,11 @@ impl<'a> fmt::Show for Sidebar<'a> {
|
|||
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,
|
||||
|
@ -1579,15 +1579,15 @@ impl<'a> fmt::Show for Sidebar<'a> {
|
|||
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(())
|
||||
}
|
||||
}
|
||||
|
@ -1620,20 +1620,20 @@ impl<'a> fmt::Show for Source<'a> {
|
|||
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)
|
||||
}
|
||||
|
|
|
@ -351,7 +351,7 @@ fn json_output(krate: clean::Crate, res: ~[plugins::PluginJson],
|
|||
json.insert(~"crate", crate_json);
|
||||
json.insert(~"plugins", json::Object(plugins_json));
|
||||
|
||||
let mut file = if_ok!(File::create(&dst));
|
||||
if_ok!(json::Object(json).to_writer(&mut file));
|
||||
let mut file = try!(File::create(&dst));
|
||||
try!(json::Object(json).to_writer(&mut file));
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -99,19 +99,19 @@ pub struct Version {
|
|||
impl fmt::Show for Version {
|
||||
#[inline]
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if_ok!(write!(f.buf, "{}.{}.{}", self.major, self.minor, self.patch))
|
||||
try!(write!(f.buf, "{}.{}.{}", self.major, self.minor, self.patch))
|
||||
if !self.pre.is_empty() {
|
||||
if_ok!(write!(f.buf, "-"));
|
||||
try!(write!(f.buf, "-"));
|
||||
for (i, x) in self.pre.iter().enumerate() {
|
||||
if i != 0 { if_ok!(write!(f.buf, ".")) };
|
||||
if_ok!(x.fmt(f));
|
||||
if i != 0 { try!(write!(f.buf, ".")) };
|
||||
try!(x.fmt(f));
|
||||
}
|
||||
}
|
||||
if !self.build.is_empty() {
|
||||
if_ok!(write!(f.buf, "+"));
|
||||
try!(write!(f.buf, "+"));
|
||||
for (i, x) in self.build.iter().enumerate() {
|
||||
if i != 0 { if_ok!(write!(f.buf, ".")) };
|
||||
if_ok!(x.fmt(f));
|
||||
if i != 0 { try!(write!(f.buf, ".")) };
|
||||
try!(x.fmt(f));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
use std::str;
|
||||
|
||||
macro_rules! if_ok( ($e:expr) => (
|
||||
macro_rules! try( ($e:expr) => (
|
||||
match $e { Ok(e) => e, Err(e) => { self.last_error = Err(e); return } }
|
||||
) )
|
||||
|
||||
|
@ -665,18 +665,18 @@ pub mod writer {
|
|||
write_vuint(self.writer, tag_id);
|
||||
|
||||
// Write a placeholder four-byte size.
|
||||
self.size_positions.push(if_ok!(self.writer.tell()) as uint);
|
||||
self.size_positions.push(try!(self.writer.tell()) as uint);
|
||||
let zeroes: &[u8] = &[0u8, 0u8, 0u8, 0u8];
|
||||
if_ok!(self.writer.write(zeroes));
|
||||
try!(self.writer.write(zeroes));
|
||||
}
|
||||
|
||||
pub fn end_tag(&mut self) {
|
||||
let last_size_pos = self.size_positions.pop().unwrap();
|
||||
let cur_pos = if_ok!(self.writer.tell());
|
||||
if_ok!(self.writer.seek(last_size_pos as i64, io::SeekSet));
|
||||
let cur_pos = try!(self.writer.tell());
|
||||
try!(self.writer.seek(last_size_pos as i64, io::SeekSet));
|
||||
let size = (cur_pos as uint - last_size_pos - 4);
|
||||
write_sized_vuint(self.writer, size, 4u);
|
||||
if_ok!(self.writer.seek(cur_pos as i64, io::SeekSet));
|
||||
try!(self.writer.seek(cur_pos as i64, io::SeekSet));
|
||||
|
||||
debug!("End tag (size = {})", size);
|
||||
}
|
||||
|
|
|
@ -702,7 +702,7 @@ pub unsafe fn write_unsafe(output: &mut io::Writer,
|
|||
curarg: args.iter(),
|
||||
};
|
||||
for piece in fmt.iter() {
|
||||
if_ok!(formatter.run(piece, None));
|
||||
try!(formatter.run(piece, None));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -859,13 +859,13 @@ impl<'a> Formatter<'a> {
|
|||
for s in selectors.iter() {
|
||||
if s.selector == value {
|
||||
for piece in s.result.iter() {
|
||||
if_ok!(self.run(piece, Some(value)));
|
||||
try!(self.run(piece, Some(value)));
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
for piece in default.iter() {
|
||||
if_ok!(self.run(piece, Some(value)));
|
||||
try!(self.run(piece, Some(value)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -876,7 +876,7 @@ impl<'a> Formatter<'a> {
|
|||
::uint::to_str_bytes(value, 10, |buf| {
|
||||
let valuestr = str::from_utf8(buf).unwrap();
|
||||
for piece in pieces.iter() {
|
||||
if_ok!(self.run(piece, Some(valuestr)));
|
||||
try!(self.run(piece, Some(valuestr)));
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
|
@ -917,12 +917,12 @@ impl<'a> Formatter<'a> {
|
|||
let sign = |this: &mut Formatter| {
|
||||
if !signprinted {
|
||||
if this.flags & 1 << (FlagSignPlus as uint) != 0 && positive {
|
||||
if_ok!(this.buf.write(['+' as u8]));
|
||||
try!(this.buf.write(['+' as u8]));
|
||||
} else if !positive {
|
||||
if_ok!(this.buf.write(['-' as u8]));
|
||||
try!(this.buf.write(['-' as u8]));
|
||||
}
|
||||
if this.flags & 1 << (FlagAlternate as uint) != 0 {
|
||||
if_ok!(this.buf.write(alternate_prefix.as_bytes()));
|
||||
try!(this.buf.write(alternate_prefix.as_bytes()));
|
||||
}
|
||||
signprinted = true;
|
||||
}
|
||||
|
@ -939,7 +939,7 @@ impl<'a> Formatter<'a> {
|
|||
Some(min) => {
|
||||
if self.flags & 1 << (FlagSignAwareZeroPad as uint) != 0 {
|
||||
self.fill = '0';
|
||||
if_ok!(sign(self));
|
||||
try!(sign(self));
|
||||
}
|
||||
self.with_padding(min - actual_len, parse::AlignRight, |me| {
|
||||
emit(me)
|
||||
|
@ -1011,15 +1011,15 @@ impl<'a> Formatter<'a> {
|
|||
parse::AlignLeft | parse::AlignRight => self.align
|
||||
};
|
||||
if align == parse::AlignLeft {
|
||||
if_ok!(f(self));
|
||||
try!(f(self));
|
||||
}
|
||||
let mut fill = [0u8, ..4];
|
||||
let len = self.fill.encode_utf8(fill);
|
||||
for _ in range(0, padding) {
|
||||
if_ok!(self.buf.write(fill.slice_to(len)));
|
||||
try!(self.buf.write(fill.slice_to(len)));
|
||||
}
|
||||
if align == parse::AlignRight {
|
||||
if_ok!(f(self));
|
||||
try!(f(self));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -599,15 +599,15 @@ impl<K:Hash + Eq + Clone,V:Clone> Clone for HashMap<K,V> {
|
|||
|
||||
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"\}")
|
||||
}
|
||||
|
@ -877,15 +877,15 @@ impl<T:Hash + Eq + Clone> Clone for HashSet<T> {
|
|||
|
||||
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"\}")
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ impl<R: Reader> BufferedReader<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))
|
||||
|
@ -103,7 +103,7 @@ impl<R: Reader> Buffer for BufferedReader<R> {
|
|||
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
|
||||
|
@ -182,7 +182,7 @@ impl<W: Writer> BufferedWriter<W> {
|
|||
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() {
|
||||
|
@ -233,9 +233,9 @@ impl<W: Writer> Writer for LineBufferedWriter<W> {
|
|||
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),
|
||||
|
|
|
@ -339,8 +339,8 @@ pub fn copy(from: &Path, to: &Path) -> IoResult<()> {
|
|||
})
|
||||
}
|
||||
|
||||
let mut reader = if_ok!(File::open(from));
|
||||
let mut writer = if_ok!(File::create(to));
|
||||
let mut reader = try!(File::open(from));
|
||||
let mut writer = try!(File::create(to));
|
||||
let mut buf = [0, ..io::DEFAULT_BUF_SIZE];
|
||||
|
||||
loop {
|
||||
|
@ -349,10 +349,10 @@ pub fn copy(from: &Path, to: &Path) -> IoResult<()> {
|
|||
Err(ref e) if e.kind == io::EndOfFile => { break }
|
||||
Err(e) => return Err(e)
|
||||
};
|
||||
if_ok!(writer.write(buf.slice_to(amt)));
|
||||
try!(writer.write(buf.slice_to(amt)));
|
||||
}
|
||||
|
||||
chmod(to, if_ok!(from.stat()).perm)
|
||||
chmod(to, try!(from.stat()).perm)
|
||||
}
|
||||
|
||||
/// Changes the permission mode bits found on a file or a directory. This
|
||||
|
@ -460,10 +460,10 @@ pub fn rmdir(path: &Path) -> IoResult<()> {
|
|||
/// // one possible implementation of fs::walk_dir only visiting files
|
||||
/// fn visit_dirs(dir: &Path, cb: |&Path|) -> io::IoResult<()> {
|
||||
/// if dir.is_dir() {
|
||||
/// let contents = if_ok!(fs::readdir(dir));
|
||||
/// let contents = try!(fs::readdir(dir));
|
||||
/// for entry in contents.iter() {
|
||||
/// if entry.is_dir() {
|
||||
/// if_ok!(visit_dirs(entry, |p| cb(p)));
|
||||
/// try!(visit_dirs(entry, |p| cb(p)));
|
||||
/// } else {
|
||||
/// cb(entry);
|
||||
/// }
|
||||
|
@ -490,7 +490,7 @@ pub fn readdir(path: &Path) -> IoResult<~[Path]> {
|
|||
/// rooted at `path`. The path given will not be iterated over, and this will
|
||||
/// perform iteration in a top-down order.
|
||||
pub fn walk_dir(path: &Path) -> IoResult<Directories> {
|
||||
Ok(Directories { stack: if_ok!(readdir(path)) })
|
||||
Ok(Directories { stack: try!(readdir(path)) })
|
||||
}
|
||||
|
||||
/// An iterator which walks over a directory
|
||||
|
@ -529,7 +529,7 @@ pub fn mkdir_recursive(path: &Path, mode: FilePermission) -> IoResult<()> {
|
|||
return Ok(())
|
||||
}
|
||||
if path.filename().is_some() {
|
||||
if_ok!(mkdir_recursive(&path.dir_path(), mode));
|
||||
try!(mkdir_recursive(&path.dir_path(), mode));
|
||||
}
|
||||
mkdir(path, mode)
|
||||
}
|
||||
|
@ -542,12 +542,12 @@ pub fn mkdir_recursive(path: &Path, mode: FilePermission) -> IoResult<()> {
|
|||
/// This function will return an `Err` value if an error happens. See
|
||||
/// `file::unlink` and `fs::readdir` for possible error conditions.
|
||||
pub fn rmdir_recursive(path: &Path) -> IoResult<()> {
|
||||
let children = if_ok!(readdir(path));
|
||||
let children = try!(readdir(path));
|
||||
for child in children.iter() {
|
||||
if child.is_dir() {
|
||||
if_ok!(rmdir_recursive(child));
|
||||
try!(rmdir_recursive(child));
|
||||
} else {
|
||||
if_ok!(unlink(child));
|
||||
try!(unlink(child));
|
||||
}
|
||||
}
|
||||
// Directory should now be empty
|
||||
|
|
|
@ -113,7 +113,7 @@ impl Writer for MemWriter {
|
|||
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(())
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ impl Reader for MemReader {
|
|||
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(())
|
||||
}
|
||||
|
@ -253,7 +253,7 @@ impl<'a> Writer for BufWriter<'a> {
|
|||
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(())
|
||||
}
|
||||
|
@ -313,7 +313,7 @@ impl<'a> Reader for BufReader<'a> {
|
|||
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(())
|
||||
}
|
||||
|
|
|
@ -365,7 +365,7 @@ pub struct IoError {
|
|||
|
||||
impl fmt::Show for IoError {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
if_ok!(fmt.buf.write_str(self.desc));
|
||||
try!(fmt.buf.write_str(self.desc));
|
||||
match self.detail {
|
||||
Some(ref s) => write!(fmt.buf, " ({})", *s),
|
||||
None => Ok(())
|
||||
|
@ -581,7 +581,7 @@ pub trait Reader {
|
|||
let mut pos = 0;
|
||||
let mut i = nbytes;
|
||||
while i > 0 {
|
||||
val += (if_ok!(self.read_u8()) as u64) << pos;
|
||||
val += (try!(self.read_u8()) as u64) << pos;
|
||||
pos += 8;
|
||||
i -= 1;
|
||||
}
|
||||
|
@ -605,7 +605,7 @@ pub trait Reader {
|
|||
let mut i = nbytes;
|
||||
while i > 0 {
|
||||
i -= 1;
|
||||
val += (if_ok!(self.read_u8()) as u64) << i * 8;
|
||||
val += (try!(self.read_u8()) as u64) << i * 8;
|
||||
}
|
||||
Ok(val)
|
||||
}
|
||||
|
@ -1191,7 +1191,7 @@ pub trait Buffer: Reader {
|
|||
/// This function will also return error if the stream does not contain a
|
||||
/// valid utf-8 encoded codepoint as the next few bytes in the stream.
|
||||
fn read_char(&mut self) -> IoResult<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
|
||||
|
@ -1199,7 +1199,7 @@ pub trait Buffer: Reader {
|
|||
{
|
||||
let mut start = 1;
|
||||
while start < width {
|
||||
match if_ok!(self.read(buf.mut_slice(start, width))) {
|
||||
match try!(self.read(buf.mut_slice(start, width))) {
|
||||
n if n == width - start => break,
|
||||
n if n < width - start => { start += n; }
|
||||
_ => return Err(standard_error(InvalidInput)),
|
||||
|
|
|
@ -189,7 +189,7 @@ pub fn copy<R: Reader, W: Writer>(r: &mut R, w: &mut W) -> io::IoResult<()> {
|
|||
Err(ref e) if e.kind == io::EndOfFile => return Ok(()),
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
if_ok!(w.write(buf.slice_to(len)));
|
||||
try!(w.write(buf.slice_to(len)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -355,6 +355,6 @@ macro_rules! local_data_key(
|
|||
/// error if the value of the expression is `Err`. For more information, see
|
||||
/// `std::io`.
|
||||
#[macro_export]
|
||||
macro_rules! if_ok(
|
||||
macro_rules! try(
|
||||
($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
|
||||
)
|
||||
|
|
|
@ -32,7 +32,7 @@ use vec::OwnedVector;
|
|||
use unstable::intrinsics::{Disr, Opaque, TyDesc, TyVisitor, get_tydesc, visit_tydesc};
|
||||
use unstable::raw;
|
||||
|
||||
macro_rules! if_ok( ($me:expr, $e:expr) => (
|
||||
macro_rules! try( ($me:expr, $e:expr) => (
|
||||
match $e {
|
||||
Ok(()) => {},
|
||||
Err(e) => { $me.last_err = Some(e); return false; }
|
||||
|
@ -181,23 +181,23 @@ impl<'a> ReprVisitor<'a> {
|
|||
#[inline]
|
||||
pub fn write<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 {
|
||||
|
@ -209,7 +209,7 @@ impl<'a> ReprVisitor<'a> {
|
|||
pub fn write_vec_range(&mut self, ptr: *(), len: uint, inner: *TyDesc) -> bool {
|
||||
let mut p = ptr as *u8;
|
||||
let (sz, al) = unsafe { ((*inner).size, (*inner).align) };
|
||||
if_ok!(self, self.writer.write(['[' as u8]));
|
||||
try!(self, self.writer.write(['[' as u8]));
|
||||
let mut first = true;
|
||||
let mut left = len;
|
||||
// unit structs have 0 size, and don't loop forever.
|
||||
|
@ -218,13 +218,13 @@ impl<'a> ReprVisitor<'a> {
|
|||
if first {
|
||||
first = false;
|
||||
} else {
|
||||
if_ok!(self, self.writer.write(", ".as_bytes()));
|
||||
try!(self, self.writer.write(", ".as_bytes()));
|
||||
}
|
||||
self.visit_ptr_inner(p as *u8, inner);
|
||||
p = align(unsafe { p.offset(sz as int) as uint }, al) as *u8;
|
||||
left -= dec;
|
||||
}
|
||||
if_ok!(self, self.writer.write([']' as u8]));
|
||||
try!(self, self.writer.write([']' as u8]));
|
||||
true
|
||||
}
|
||||
|
||||
|
@ -233,7 +233,7 @@ impl<'a> ReprVisitor<'a> {
|
|||
}
|
||||
|
||||
fn write_escaped_char(&mut self, ch: char, is_str: bool) -> bool {
|
||||
if_ok!(self, match ch {
|
||||
try!(self, match ch {
|
||||
'\t' => self.writer.write("\\t".as_bytes()),
|
||||
'\r' => self.writer.write("\\r".as_bytes()),
|
||||
'\n' => self.writer.write("\\n".as_bytes()),
|
||||
|
@ -266,7 +266,7 @@ impl<'a> ReprVisitor<'a> {
|
|||
|
||||
impl<'a> TyVisitor for ReprVisitor<'a> {
|
||||
fn visit_bot(&mut self) -> bool {
|
||||
if_ok!(self, self.writer.write("!".as_bytes()));
|
||||
try!(self, self.writer.write("!".as_bytes()));
|
||||
true
|
||||
}
|
||||
fn visit_nil(&mut self) -> bool { self.write::<()>() }
|
||||
|
@ -288,9 +288,9 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
|
|||
|
||||
fn visit_char(&mut self) -> bool {
|
||||
self.get::<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
|
||||
})
|
||||
}
|
||||
|
@ -301,7 +301,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
|
|||
|
||||
fn visit_estr_uniq(&mut self) -> bool {
|
||||
self.get::<~str>(|this, s| {
|
||||
if_ok!(this, this.writer.write(['~' as u8]));
|
||||
try!(this, this.writer.write(['~' as u8]));
|
||||
this.write_escaped_slice(*s)
|
||||
})
|
||||
}
|
||||
|
@ -315,7 +315,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
|
|||
_align: uint) -> bool { fail!(); }
|
||||
|
||||
fn visit_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
|
||||
if_ok!(self, self.writer.write(['@' as u8]));
|
||||
try!(self, self.writer.write(['@' as u8]));
|
||||
self.write_mut_qualifier(mtbl);
|
||||
self.get::<&raw::Box<()>>(|this, b| {
|
||||
let p = &b.data as *() as *u8;
|
||||
|
@ -324,7 +324,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
|
|||
}
|
||||
|
||||
fn visit_uniq(&mut self, _mtbl: uint, inner: *TyDesc) -> bool {
|
||||
if_ok!(self, self.writer.write(['~' as u8]));
|
||||
try!(self, self.writer.write(['~' as u8]));
|
||||
self.get::<*u8>(|this, b| {
|
||||
this.visit_ptr_inner(*b, inner)
|
||||
})
|
||||
|
@ -332,15 +332,15 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
|
|||
|
||||
fn visit_ptr(&mut self, mtbl: uint, _inner: *TyDesc) -> bool {
|
||||
self.get::<*u8>(|this, p| {
|
||||
if_ok!(this, write!(this.writer, "({} as *", *p));
|
||||
try!(this, write!(this.writer, "({} as *", *p));
|
||||
this.write_mut_qualifier(mtbl);
|
||||
if_ok!(this, this.writer.write("())".as_bytes()));
|
||||
try!(this, this.writer.write("())".as_bytes()));
|
||||
true
|
||||
})
|
||||
}
|
||||
|
||||
fn visit_rptr(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
|
||||
if_ok!(self, self.writer.write(['&' as u8]));
|
||||
try!(self, self.writer.write(['&' as u8]));
|
||||
self.write_mut_qualifier(mtbl);
|
||||
self.get::<*u8>(|this, p| {
|
||||
this.visit_ptr_inner(*p, inner)
|
||||
|
@ -358,7 +358,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
|
|||
|
||||
fn visit_evec_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
|
||||
self.get::<&raw::Box<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)
|
||||
})
|
||||
|
@ -366,14 +366,14 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
|
|||
|
||||
fn visit_evec_uniq(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
|
||||
self.get::<&raw::Vec<()>>(|this, b| {
|
||||
if_ok!(this, this.writer.write(['~' as u8]));
|
||||
try!(this, this.writer.write(['~' as u8]));
|
||||
this.write_unboxed_vec_repr(mtbl, *b, inner)
|
||||
})
|
||||
}
|
||||
|
||||
fn visit_evec_slice(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
|
||||
self.get::<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 }
|
||||
|
@ -392,36 +392,36 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
|
|||
|
||||
fn visit_enter_rec(&mut self, _n_fields: uint,
|
||||
_sz: uint, _align: uint) -> bool {
|
||||
if_ok!(self, self.writer.write(['{' as u8]));
|
||||
try!(self, self.writer.write(['{' as u8]));
|
||||
true
|
||||
}
|
||||
|
||||
fn visit_rec_field(&mut self, i: uint, name: &str,
|
||||
mtbl: uint, inner: *TyDesc) -> bool {
|
||||
if i != 0 {
|
||||
if_ok!(self, self.writer.write(", ".as_bytes()));
|
||||
try!(self, self.writer.write(", ".as_bytes()));
|
||||
}
|
||||
self.write_mut_qualifier(mtbl);
|
||||
if_ok!(self, self.writer.write(name.as_bytes()));
|
||||
if_ok!(self, self.writer.write(": ".as_bytes()));
|
||||
try!(self, self.writer.write(name.as_bytes()));
|
||||
try!(self, self.writer.write(": ".as_bytes()));
|
||||
self.visit_inner(inner);
|
||||
true
|
||||
}
|
||||
|
||||
fn visit_leave_rec(&mut self, _n_fields: uint,
|
||||
_sz: uint, _align: uint) -> bool {
|
||||
if_ok!(self, self.writer.write(['}' as u8]));
|
||||
try!(self, self.writer.write(['}' as u8]));
|
||||
true
|
||||
}
|
||||
|
||||
fn visit_enter_class(&mut self, name: &str, named_fields: bool, n_fields: uint,
|
||||
_sz: uint, _align: uint) -> bool {
|
||||
if_ok!(self, self.writer.write(name.as_bytes()));
|
||||
try!(self, self.writer.write(name.as_bytes()));
|
||||
if n_fields != 0 {
|
||||
if named_fields {
|
||||
if_ok!(self, self.writer.write(['{' as u8]));
|
||||
try!(self, self.writer.write(['{' as u8]));
|
||||
} else {
|
||||
if_ok!(self, self.writer.write(['(' as u8]));
|
||||
try!(self, self.writer.write(['(' as u8]));
|
||||
}
|
||||
}
|
||||
true
|
||||
|
@ -430,11 +430,11 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
|
|||
fn visit_class_field(&mut self, i: uint, name: &str, named: bool,
|
||||
_mtbl: uint, inner: *TyDesc) -> bool {
|
||||
if i != 0 {
|
||||
if_ok!(self, self.writer.write(", ".as_bytes()));
|
||||
try!(self, self.writer.write(", ".as_bytes()));
|
||||
}
|
||||
if named {
|
||||
if_ok!(self, self.writer.write(name.as_bytes()));
|
||||
if_ok!(self, self.writer.write(": ".as_bytes()));
|
||||
try!(self, self.writer.write(name.as_bytes()));
|
||||
try!(self, self.writer.write(": ".as_bytes()));
|
||||
}
|
||||
self.visit_inner(inner);
|
||||
true
|
||||
|
@ -444,9 +444,9 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
|
|||
_sz: uint, _align: uint) -> bool {
|
||||
if n_fields != 0 {
|
||||
if named_fields {
|
||||
if_ok!(self, self.writer.write(['}' as u8]));
|
||||
try!(self, self.writer.write(['}' as u8]));
|
||||
} else {
|
||||
if_ok!(self, self.writer.write([')' as u8]));
|
||||
try!(self, self.writer.write([')' as u8]));
|
||||
}
|
||||
}
|
||||
true
|
||||
|
@ -454,13 +454,13 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
|
|||
|
||||
fn visit_enter_tup(&mut self, _n_fields: uint,
|
||||
_sz: uint, _align: uint) -> bool {
|
||||
if_ok!(self, self.writer.write(['(' as u8]));
|
||||
try!(self, self.writer.write(['(' as u8]));
|
||||
true
|
||||
}
|
||||
|
||||
fn visit_tup_field(&mut self, i: uint, inner: *TyDesc) -> bool {
|
||||
if i != 0 {
|
||||
if_ok!(self, self.writer.write(", ".as_bytes()));
|
||||
try!(self, self.writer.write(", ".as_bytes()));
|
||||
}
|
||||
self.visit_inner(inner);
|
||||
true
|
||||
|
@ -469,9 +469,9 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
|
|||
fn visit_leave_tup(&mut self, _n_fields: uint,
|
||||
_sz: uint, _align: uint) -> bool {
|
||||
if _n_fields == 1 {
|
||||
if_ok!(self, self.writer.write([',' as u8]));
|
||||
try!(self, self.writer.write([',' as u8]));
|
||||
}
|
||||
if_ok!(self, self.writer.write([')' as u8]));
|
||||
try!(self, self.writer.write([')' as u8]));
|
||||
true
|
||||
}
|
||||
|
||||
|
@ -507,9 +507,9 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
|
|||
}
|
||||
|
||||
if write {
|
||||
if_ok!(self, self.writer.write(name.as_bytes()));
|
||||
try!(self, self.writer.write(name.as_bytes()));
|
||||
if n_fields > 0 {
|
||||
if_ok!(self, self.writer.write(['(' as u8]));
|
||||
try!(self, self.writer.write(['(' as u8]));
|
||||
}
|
||||
}
|
||||
true
|
||||
|
@ -523,7 +523,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
|
|||
match self.var_stk[self.var_stk.len() - 1] {
|
||||
Matched => {
|
||||
if i != 0 {
|
||||
if_ok!(self, self.writer.write(", ".as_bytes()));
|
||||
try!(self, self.writer.write(", ".as_bytes()));
|
||||
}
|
||||
if ! self.visit_inner(inner) {
|
||||
return false;
|
||||
|
@ -541,7 +541,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
|
|||
match self.var_stk[self.var_stk.len() - 1] {
|
||||
Matched => {
|
||||
if n_fields > 0 {
|
||||
if_ok!(self, self.writer.write([')' as u8]));
|
||||
try!(self, self.writer.write([')' as u8]));
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
|
@ -563,29 +563,29 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
|
|||
|
||||
fn visit_enter_fn(&mut self, _purity: uint, _proto: uint,
|
||||
_n_inputs: uint, _retstyle: uint) -> bool {
|
||||
if_ok!(self, self.writer.write("fn(".as_bytes()));
|
||||
try!(self, self.writer.write("fn(".as_bytes()));
|
||||
true
|
||||
}
|
||||
|
||||
fn visit_fn_input(&mut self, i: uint, _mode: uint, inner: *TyDesc) -> bool {
|
||||
if i != 0 {
|
||||
if_ok!(self, self.writer.write(", ".as_bytes()));
|
||||
try!(self, self.writer.write(", ".as_bytes()));
|
||||
}
|
||||
let name = unsafe { (*inner).name };
|
||||
if_ok!(self, self.writer.write(name.as_bytes()));
|
||||
try!(self, self.writer.write(name.as_bytes()));
|
||||
true
|
||||
}
|
||||
|
||||
fn visit_fn_output(&mut self, _retstyle: uint, variadic: bool,
|
||||
inner: *TyDesc) -> bool {
|
||||
if variadic {
|
||||
if_ok!(self, self.writer.write(", ...".as_bytes()));
|
||||
try!(self, self.writer.write(", ...".as_bytes()));
|
||||
}
|
||||
if_ok!(self, self.writer.write(")".as_bytes()));
|
||||
try!(self, self.writer.write(")".as_bytes()));
|
||||
let name = unsafe { (*inner).name };
|
||||
if name != "()" {
|
||||
if_ok!(self, self.writer.write(" -> ".as_bytes()));
|
||||
if_ok!(self, self.writer.write(name.as_bytes()));
|
||||
try!(self, self.writer.write(" -> ".as_bytes()));
|
||||
try!(self, self.writer.write(name.as_bytes()));
|
||||
}
|
||||
true
|
||||
}
|
||||
|
@ -595,7 +595,7 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
|
|||
|
||||
|
||||
fn visit_trait(&mut self, name: &str) -> bool {
|
||||
if_ok!(self, self.writer.write(name.as_bytes()));
|
||||
try!(self, self.writer.write(name.as_bytes()));
|
||||
true
|
||||
}
|
||||
|
||||
|
|
|
@ -161,9 +161,9 @@ macro_rules! write_tuple {
|
|||
write!($buf, "({},)", *$x)
|
||||
);
|
||||
($buf:expr, $hd:expr, $($tl:expr),+) => ({
|
||||
if_ok!(write!($buf, "("));
|
||||
if_ok!(write!($buf, "{}", *$hd));
|
||||
$(if_ok!(write!($buf, ", {}", *$tl));)+
|
||||
try!(write!($buf, "("));
|
||||
try!(write!($buf, "{}", *$hd));
|
||||
$(try!(write!($buf, ", {}", *$tl));)+
|
||||
write!($buf, ")")
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2645,15 +2645,15 @@ impl<A: DeepClone> DeepClone for ~[A] {
|
|||
|
||||
impl<'a, T: fmt::Show> fmt::Show for &'a [T] {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if_ok!(write!(f.buf, "["));
|
||||
try!(write!(f.buf, "["));
|
||||
let mut is_first = true;
|
||||
for x in self.iter() {
|
||||
if is_first {
|
||||
is_first = false;
|
||||
} else {
|
||||
if_ok!(write!(f.buf, ", "));
|
||||
try!(write!(f.buf, ", "));
|
||||
}
|
||||
if_ok!(write!(f.buf, "{}", *x))
|
||||
try!(write!(f.buf, "{}", *x))
|
||||
}
|
||||
write!(f.buf, "]")
|
||||
}
|
||||
|
|
|
@ -192,9 +192,9 @@ fn print_maybe_styled(msg: &str, color: term::attr::Attr) -> io::IoResult<()> {
|
|||
}
|
||||
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(())
|
||||
}
|
||||
|
||||
|
@ -230,12 +230,12 @@ fn print_maybe_styled(msg: &str, color: term::attr::Attr) -> io::IoResult<()> {
|
|||
fn print_diagnostic(topic: &str, lvl: Level, msg: &str) -> io::IoResult<()> {
|
||||
if !topic.is_empty() {
|
||||
let mut stderr = io::stderr();
|
||||
if_ok!(write!(&mut stderr as &mut io::Writer, "{} ", topic));
|
||||
try!(write!(&mut stderr as &mut io::Writer, "{} ", topic));
|
||||
}
|
||||
|
||||
if_ok!(print_maybe_styled(format!("{}: ", lvl.to_str()),
|
||||
try!(print_maybe_styled(format!("{}: ", lvl.to_str()),
|
||||
term::attr::ForegroundColor(lvl.color())));
|
||||
if_ok!(print_maybe_styled(format!("{}\n", msg), term::attr::Bold));
|
||||
try!(print_maybe_styled(format!("{}\n", msg), term::attr::Bold));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -276,11 +276,11 @@ fn emit(cm: &codemap::CodeMap, sp: Span,
|
|||
// the span)
|
||||
let span_end = Span { lo: sp.hi, hi: sp.hi, expn_info: sp.expn_info};
|
||||
let ses = cm.span_to_str(span_end);
|
||||
if_ok!(print_diagnostic(ses, lvl, msg));
|
||||
if_ok!(custom_highlight_lines(cm, sp, lvl, lines));
|
||||
try!(print_diagnostic(ses, lvl, msg));
|
||||
try!(custom_highlight_lines(cm, sp, lvl, lines));
|
||||
} else {
|
||||
if_ok!(print_diagnostic(ss, lvl, msg));
|
||||
if_ok!(highlight_lines(cm, sp, lvl, lines));
|
||||
try!(print_diagnostic(ss, lvl, msg));
|
||||
try!(highlight_lines(cm, sp, lvl, lines));
|
||||
}
|
||||
print_macro_backtrace(cm, sp)
|
||||
}
|
||||
|
@ -301,13 +301,13 @@ fn highlight_lines(cm: &codemap::CodeMap,
|
|||
}
|
||||
// Print the offending lines
|
||||
for line in display_lines.iter() {
|
||||
if_ok!(write!(err, "{}:{} {}\n", fm.name, *line + 1,
|
||||
try!(write!(err, "{}:{} {}\n", fm.name, *line + 1,
|
||||
fm.get_line(*line as int)));
|
||||
}
|
||||
if elided {
|
||||
let last_line = display_lines[display_lines.len() - 1u];
|
||||
let s = format!("{}:{} ", fm.name, last_line + 1u);
|
||||
if_ok!(write!(err, "{0:1$}...\n", "", s.len()));
|
||||
try!(write!(err, "{0:1$}...\n", "", s.len()));
|
||||
}
|
||||
|
||||
// FIXME (#3260)
|
||||
|
@ -339,7 +339,7 @@ fn highlight_lines(cm: &codemap::CodeMap,
|
|||
_ => s.push_char(' '),
|
||||
};
|
||||
}
|
||||
if_ok!(write!(err, "{}", s));
|
||||
try!(write!(err, "{}", s));
|
||||
let mut s = ~"^";
|
||||
let hi = cm.lookup_char_pos(sp.hi);
|
||||
if hi.col != lo.col {
|
||||
|
@ -347,7 +347,7 @@ fn highlight_lines(cm: &codemap::CodeMap,
|
|||
let num_squigglies = hi.col.to_uint()-lo.col.to_uint()-1u;
|
||||
for _ in range(0, num_squigglies) { s.push_char('~'); }
|
||||
}
|
||||
if_ok!(print_maybe_styled(s + "\n",
|
||||
try!(print_maybe_styled(s + "\n",
|
||||
term::attr::ForegroundColor(lvl.color())));
|
||||
}
|
||||
Ok(())
|
||||
|
@ -369,15 +369,15 @@ fn custom_highlight_lines(cm: &codemap::CodeMap,
|
|||
|
||||
let lines = lines.lines.as_slice();
|
||||
if lines.len() > MAX_LINES {
|
||||
if_ok!(write!(err, "{}:{} {}\n", fm.name,
|
||||
try!(write!(err, "{}:{} {}\n", fm.name,
|
||||
lines[0] + 1, fm.get_line(lines[0] as int)));
|
||||
if_ok!(write!(err, "...\n"));
|
||||
try!(write!(err, "...\n"));
|
||||
let last_line = lines[lines.len()-1];
|
||||
if_ok!(write!(err, "{}:{} {}\n", fm.name,
|
||||
try!(write!(err, "{}:{} {}\n", fm.name,
|
||||
last_line + 1, fm.get_line(last_line as int)));
|
||||
} else {
|
||||
for line in lines.iter() {
|
||||
if_ok!(write!(err, "{}:{} {}\n", fm.name,
|
||||
try!(write!(err, "{}:{} {}\n", fm.name,
|
||||
*line + 1, fm.get_line(*line as int)));
|
||||
}
|
||||
}
|
||||
|
@ -398,12 +398,12 @@ fn print_macro_backtrace(cm: &codemap::CodeMap, sp: Span) -> io::IoResult<()> {
|
|||
codemap::MacroAttribute => ("#[", "]"),
|
||||
codemap::MacroBang => ("", "!")
|
||||
};
|
||||
if_ok!(print_diagnostic(ss, Note,
|
||||
try!(print_diagnostic(ss, Note,
|
||||
format!("in expansion of {}{}{}", pre,
|
||||
ei.callee.name, post)));
|
||||
let ss = cm.span_to_str(ei.call_site);
|
||||
if_ok!(print_diagnostic(ss, Note, "expansion site"));
|
||||
if_ok!(print_macro_backtrace(cm, ei.call_site));
|
||||
try!(print_diagnostic(ss, Note, "expansion site"));
|
||||
try!(print_macro_backtrace(cm, ei.call_site));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -299,7 +299,7 @@ impl Printer {
|
|||
if !self.scan_stack_empty {
|
||||
self.check_stack(0);
|
||||
let left = self.token[self.left].clone();
|
||||
if_ok!(self.advance_left(left, self.size[self.left]));
|
||||
try!(self.advance_left(left, self.size[self.left]));
|
||||
}
|
||||
self.indent(0);
|
||||
Ok(())
|
||||
|
@ -377,9 +377,9 @@ impl Printer {
|
|||
}
|
||||
}
|
||||
let left = self.token[self.left].clone();
|
||||
if_ok!(self.advance_left(left, self.size[self.left]));
|
||||
try!(self.advance_left(left, self.size[self.left]));
|
||||
if self.left != self.right {
|
||||
if_ok!(self.check_stream());
|
||||
try!(self.check_stream());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -436,7 +436,7 @@ impl Printer {
|
|||
self.left += 1u;
|
||||
self.left %= self.buf_len;
|
||||
let left = self.token[self.left].clone();
|
||||
if_ok!(self.advance_left(left, self.size[self.left]));
|
||||
try!(self.advance_left(left, self.size[self.left]));
|
||||
}
|
||||
ret
|
||||
} else {
|
||||
|
@ -491,7 +491,7 @@ impl Printer {
|
|||
}
|
||||
pub fn print_str(&mut self, s: &str) -> io::IoResult<()> {
|
||||
while self.pending_indentation > 0 {
|
||||
if_ok!(write!(self.out, " "));
|
||||
try!(write!(self.out, " "));
|
||||
self.pending_indentation -= 1;
|
||||
}
|
||||
write!(self.out, "{}", s)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -30,10 +30,6 @@ use terminfo::searcher::open;
|
|||
use terminfo::parser::compiled::{parse, msys_terminfo};
|
||||
use terminfo::parm::{expand, Number, Variables};
|
||||
|
||||
macro_rules! if_ok (
|
||||
($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
|
||||
)
|
||||
|
||||
pub mod terminfo;
|
||||
|
||||
// FIXME (#2807): Windows support.
|
||||
|
@ -155,7 +151,7 @@ impl<T: Writer> Terminal<T> {
|
|||
let s = expand(*self.ti.strings.find_equiv(&("setaf")).unwrap(),
|
||||
[Number(color as int)], &mut Variables::new());
|
||||
if s.is_ok() {
|
||||
if_ok!(self.out.write(s.unwrap()));
|
||||
try!(self.out.write(s.unwrap()));
|
||||
return Ok(true)
|
||||
} else {
|
||||
warn!("{}", s.unwrap_err());
|
||||
|
@ -176,7 +172,7 @@ impl<T: Writer> Terminal<T> {
|
|||
let s = expand(*self.ti.strings.find_equiv(&("setab")).unwrap(),
|
||||
[Number(color as int)], &mut Variables::new());
|
||||
if s.is_ok() {
|
||||
if_ok!(self.out.write(s.unwrap()));
|
||||
try!(self.out.write(s.unwrap()));
|
||||
return Ok(true)
|
||||
} else {
|
||||
warn!("{}", s.unwrap_err());
|
||||
|
@ -198,7 +194,7 @@ impl<T: Writer> Terminal<T> {
|
|||
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());
|
||||
|
|
|
@ -162,7 +162,7 @@ pub static stringnames: &'static[&'static str] = &'static[ "cbt", "_", "cr", "cs
|
|||
/// Parse a compiled terminfo entry, using long capability names if `longnames` is true
|
||||
pub fn parse(file: &mut io::Reader,
|
||||
longnames: bool) -> Result<~TermInfo, ~str> {
|
||||
macro_rules! if_ok( ($e:expr) => (
|
||||
macro_rules! try( ($e:expr) => (
|
||||
match $e { Ok(e) => e, Err(e) => return Err(format!("{}", e)) }
|
||||
) )
|
||||
|
||||
|
@ -181,17 +181,17 @@ pub fn parse(file: &mut io::Reader,
|
|||
}
|
||||
|
||||
// Check magic number
|
||||
let magic = if_ok!(file.read_le_u16());
|
||||
let magic = try!(file.read_le_u16());
|
||||
if magic != 0x011A {
|
||||
return Err(format!("invalid magic number: expected {:x} but found {:x}",
|
||||
0x011A, magic as uint));
|
||||
}
|
||||
|
||||
let names_bytes = if_ok!(file.read_le_i16()) as int;
|
||||
let bools_bytes = if_ok!(file.read_le_i16()) as int;
|
||||
let numbers_count = if_ok!(file.read_le_i16()) as int;
|
||||
let string_offsets_count = if_ok!(file.read_le_i16()) as int;
|
||||
let string_table_bytes = if_ok!(file.read_le_i16()) as int;
|
||||
let names_bytes = try!(file.read_le_i16()) as int;
|
||||
let bools_bytes = try!(file.read_le_i16()) as int;
|
||||
let numbers_count = try!(file.read_le_i16()) as int;
|
||||
let string_offsets_count = try!(file.read_le_i16()) as int;
|
||||
let string_table_bytes = try!(file.read_le_i16()) as int;
|
||||
|
||||
assert!(names_bytes > 0);
|
||||
|
||||
|
@ -220,21 +220,21 @@ pub fn parse(file: &mut io::Reader,
|
|||
}
|
||||
|
||||
// don't read NUL
|
||||
let bytes = if_ok!(file.read_bytes(names_bytes as uint - 1));
|
||||
let bytes = try!(file.read_bytes(names_bytes as uint - 1));
|
||||
let names_str = match str::from_utf8_owned(bytes) {
|
||||
Some(s) => s, None => return Err(~"input not utf-8"),
|
||||
};
|
||||
|
||||
let term_names: ~[~str] = names_str.split('|').map(|s| s.to_owned()).collect();
|
||||
|
||||
if_ok!(file.read_byte()); // consume NUL
|
||||
try!(file.read_byte()); // consume NUL
|
||||
|
||||
debug!("term names: {:?}", term_names);
|
||||
|
||||
let mut bools_map = HashMap::new();
|
||||
if bools_bytes != 0 {
|
||||
for i in range(0, bools_bytes) {
|
||||
let b = if_ok!(file.read_byte());
|
||||
let b = try!(file.read_byte());
|
||||
if b < 0 {
|
||||
error!("EOF reading bools after {} entries", i);
|
||||
return Err(~"error: expected more bools but hit EOF");
|
||||
|
@ -249,13 +249,13 @@ pub fn parse(file: &mut io::Reader,
|
|||
|
||||
if (bools_bytes + names_bytes) % 2 == 1 {
|
||||
debug!("adjusting for padding between bools and numbers");
|
||||
if_ok!(file.read_byte()); // compensate for padding
|
||||
try!(file.read_byte()); // compensate for padding
|
||||
}
|
||||
|
||||
let mut numbers_map = HashMap::new();
|
||||
if numbers_count != 0 {
|
||||
for i in range(0, numbers_count) {
|
||||
let n = if_ok!(file.read_le_u16());
|
||||
let n = try!(file.read_le_u16());
|
||||
if n != 0xFFFF {
|
||||
debug!("{}\\#{}", nnames[i], n);
|
||||
numbers_map.insert(nnames[i].to_owned(), n);
|
||||
|
@ -270,12 +270,12 @@ pub fn parse(file: &mut io::Reader,
|
|||
if string_offsets_count != 0 {
|
||||
let mut string_offsets = vec::with_capacity(10);
|
||||
for _ in range(0, string_offsets_count) {
|
||||
string_offsets.push(if_ok!(file.read_le_u16()));
|
||||
string_offsets.push(try!(file.read_le_u16()));
|
||||
}
|
||||
|
||||
debug!("offsets: {:?}", string_offsets);
|
||||
|
||||
let string_table = if_ok!(file.read_bytes(string_table_bytes as uint));
|
||||
let string_table = try!(file.read_bytes(string_table_bytes as uint));
|
||||
|
||||
if string_table.len() != string_table_bytes as uint {
|
||||
error!("EOF reading string table after {} bytes, wanted {}", string_table.len(),
|
||||
|
|
|
@ -397,7 +397,7 @@ impl<T: Writer> ConsoleTestState<T> {
|
|||
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()) {
|
||||
|
@ -461,11 +461,11 @@ impl<T: Writer> ConsoleTestState<T> {
|
|||
match self.out {
|
||||
Pretty(ref mut term) => {
|
||||
if self.use_color {
|
||||
if_ok!(term.fg(color));
|
||||
try!(term.fg(color));
|
||||
}
|
||||
if_ok!(term.write(word.as_bytes()));
|
||||
try!(term.write(word.as_bytes()));
|
||||
if self.use_color {
|
||||
if_ok!(term.reset());
|
||||
try!(term.reset());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -493,16 +493,16 @@ impl<T: Writer> ConsoleTestState<T> {
|
|||
}
|
||||
|
||||
pub fn write_result(&mut self, result: &TestResult) -> io::IoResult<()> {
|
||||
if_ok!(match *result {
|
||||
try!(match *result {
|
||||
TrOk => self.write_ok(),
|
||||
TrFailed => self.write_failed(),
|
||||
TrIgnored => self.write_ignored(),
|
||||
TrMetrics(ref mm) => {
|
||||
if_ok!(self.write_metric());
|
||||
try!(self.write_metric());
|
||||
self.write_plain(format!(": {}", fmt_metrics(mm)))
|
||||
}
|
||||
TrBench(ref bs) => {
|
||||
if_ok!(self.write_bench());
|
||||
try!(self.write_bench());
|
||||
self.write_plain(format!(": {}", fmt_bench_samples(bs)))
|
||||
}
|
||||
});
|
||||
|
@ -527,7 +527,7 @@ impl<T: Writer> ConsoleTestState<T> {
|
|||
}
|
||||
|
||||
pub fn write_failures(&mut self) -> io::IoResult<()> {
|
||||
if_ok!(self.write_plain("\nfailures:\n"));
|
||||
try!(self.write_plain("\nfailures:\n"));
|
||||
let mut failures = ~[];
|
||||
let mut fail_out = ~"";
|
||||
for &(ref f, ref stdout) in self.failures.iter() {
|
||||
|
@ -541,14 +541,14 @@ impl<T: Writer> ConsoleTestState<T> {
|
|||
}
|
||||
}
|
||||
if fail_out.len() > 0 {
|
||||
if_ok!(self.write_plain("\n"));
|
||||
if_ok!(self.write_plain(fail_out));
|
||||
try!(self.write_plain("\n"));
|
||||
try!(self.write_plain(fail_out));
|
||||
}
|
||||
|
||||
if_ok!(self.write_plain("\nfailures:\n"));
|
||||
try!(self.write_plain("\nfailures:\n"));
|
||||
failures.sort();
|
||||
for name in failures.iter() {
|
||||
if_ok!(self.write_plain(format!(" {}\n", name.to_str())));
|
||||
try!(self.write_plain(format!(" {}\n", name.to_str())));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -565,37 +565,37 @@ impl<T: Writer> ConsoleTestState<T> {
|
|||
LikelyNoise => noise += 1,
|
||||
MetricAdded => {
|
||||
added += 1;
|
||||
if_ok!(self.write_added());
|
||||
if_ok!(self.write_plain(format!(": {}\n", *k)));
|
||||
try!(self.write_added());
|
||||
try!(self.write_plain(format!(": {}\n", *k)));
|
||||
}
|
||||
MetricRemoved => {
|
||||
removed += 1;
|
||||
if_ok!(self.write_removed());
|
||||
if_ok!(self.write_plain(format!(": {}\n", *k)));
|
||||
try!(self.write_removed());
|
||||
try!(self.write_plain(format!(": {}\n", *k)));
|
||||
}
|
||||
Improvement(pct) => {
|
||||
improved += 1;
|
||||
if_ok!(self.write_plain(format!(": {}", *k)));
|
||||
if_ok!(self.write_improved());
|
||||
if_ok!(self.write_plain(format!(" by {:.2f}%\n", pct as f64)));
|
||||
try!(self.write_plain(format!(": {}", *k)));
|
||||
try!(self.write_improved());
|
||||
try!(self.write_plain(format!(" by {:.2f}%\n", pct as f64)));
|
||||
}
|
||||
Regression(pct) => {
|
||||
regressed += 1;
|
||||
if_ok!(self.write_plain(format!(": {}", *k)));
|
||||
if_ok!(self.write_regressed());
|
||||
if_ok!(self.write_plain(format!(" by {:.2f}%\n", pct as f64)));
|
||||
try!(self.write_plain(format!(": {}", *k)));
|
||||
try!(self.write_regressed());
|
||||
try!(self.write_plain(format!(" by {:.2f}%\n", pct as f64)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if_ok!(self.write_plain(format!("result of ratchet: {} metrics added, \
|
||||
try!(self.write_plain(format!("result of ratchet: {} metrics added, \
|
||||
{} removed, {} improved, {} regressed, \
|
||||
{} noise\n",
|
||||
added, removed, improved, regressed,
|
||||
noise)));
|
||||
if regressed == 0 {
|
||||
if_ok!(self.write_plain("updated ratchet file\n"));
|
||||
try!(self.write_plain("updated ratchet file\n"));
|
||||
} else {
|
||||
if_ok!(self.write_plain("left ratchet file untouched\n"));
|
||||
try!(self.write_plain("left ratchet file untouched\n"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -608,38 +608,38 @@ impl<T: Writer> ConsoleTestState<T> {
|
|||
let ratchet_success = match *ratchet_metrics {
|
||||
None => true,
|
||||
Some(ref pth) => {
|
||||
if_ok!(self.write_plain(format!("\nusing metrics ratcher: {}\n",
|
||||
try!(self.write_plain(format!("\nusing metrics ratcher: {}\n",
|
||||
pth.display())));
|
||||
match ratchet_pct {
|
||||
None => (),
|
||||
Some(pct) =>
|
||||
if_ok!(self.write_plain(format!("with noise-tolerance \
|
||||
try!(self.write_plain(format!("with noise-tolerance \
|
||||
forced to: {}%\n",
|
||||
pct)))
|
||||
}
|
||||
let (diff, ok) = self.metrics.ratchet(pth, ratchet_pct);
|
||||
if_ok!(self.write_metric_diff(&diff));
|
||||
try!(self.write_metric_diff(&diff));
|
||||
ok
|
||||
}
|
||||
};
|
||||
|
||||
let test_success = self.failed == 0u;
|
||||
if !test_success {
|
||||
if_ok!(self.write_failures());
|
||||
try!(self.write_failures());
|
||||
}
|
||||
|
||||
let success = ratchet_success && test_success;
|
||||
|
||||
if_ok!(self.write_plain("\ntest result: "));
|
||||
try!(self.write_plain("\ntest result: "));
|
||||
if success {
|
||||
// There's no parallelism at this point so it's safe to use color
|
||||
if_ok!(self.write_ok());
|
||||
try!(self.write_ok());
|
||||
} else {
|
||||
if_ok!(self.write_failed());
|
||||
try!(self.write_failed());
|
||||
}
|
||||
let s = format!(". {} passed; {} failed; {} ignored; {} measured\n\n",
|
||||
self.passed, self.failed, self.ignored, self.measured);
|
||||
if_ok!(self.write_plain(s));
|
||||
try!(self.write_plain(s));
|
||||
return Ok(success);
|
||||
}
|
||||
}
|
||||
|
@ -678,8 +678,8 @@ pub fn run_tests_console(opts: &TestOpts,
|
|||
TeFiltered(ref filtered_tests) => st.write_run_start(filtered_tests.len()),
|
||||
TeWait(ref test, padding) => st.write_test_start(test, padding),
|
||||
TeResult(test, result, stdout) => {
|
||||
if_ok!(st.write_log(&test, &result));
|
||||
if_ok!(st.write_result(&result));
|
||||
try!(st.write_log(&test, &result));
|
||||
try!(st.write_result(&result));
|
||||
match result {
|
||||
TrOk => st.passed += 1,
|
||||
TrIgnored => st.ignored += 1,
|
||||
|
@ -707,7 +707,7 @@ pub fn run_tests_console(opts: &TestOpts,
|
|||
}
|
||||
}
|
||||
}
|
||||
let mut st = if_ok!(ConsoleTestState::new(opts, None::<StdWriter>));
|
||||
let mut st = try!(ConsoleTestState::new(opts, None::<StdWriter>));
|
||||
fn len_if_padded(t: &TestDescAndFn) -> uint {
|
||||
match t.testfn.padding() {
|
||||
PadNone => 0u,
|
||||
|
@ -722,12 +722,12 @@ pub fn run_tests_console(opts: &TestOpts,
|
|||
},
|
||||
None => {}
|
||||
}
|
||||
if_ok!(run_tests(opts, tests, |x| callback(&x, &mut st)));
|
||||
try!(run_tests(opts, tests, |x| callback(&x, &mut st)));
|
||||
match opts.save_metrics {
|
||||
None => (),
|
||||
Some(ref pth) => {
|
||||
if_ok!(st.metrics.save(pth));
|
||||
if_ok!(st.write_plain(format!("\nmetrics saved to: {}",
|
||||
try!(st.metrics.save(pth));
|
||||
try!(st.write_plain(format!("\nmetrics saved to: {}",
|
||||
pth.display())));
|
||||
}
|
||||
}
|
||||
|
@ -793,7 +793,7 @@ fn run_tests(opts: &TestOpts,
|
|||
let filtered_tests = filter_tests(opts, tests);
|
||||
let filtered_descs = filtered_tests.map(|t| t.desc.clone());
|
||||
|
||||
if_ok!(callback(TeFiltered(filtered_descs)));
|
||||
try!(callback(TeFiltered(filtered_descs)));
|
||||
|
||||
let (filtered_tests, filtered_benchs_and_metrics) =
|
||||
filtered_tests.partition(|e| {
|
||||
|
@ -821,7 +821,7 @@ fn run_tests(opts: &TestOpts,
|
|||
// We are doing one test at a time so we can print the name
|
||||
// of the test before we run it. Useful for debugging tests
|
||||
// that hang forever.
|
||||
if_ok!(callback(TeWait(test.desc.clone(), test.testfn.padding())));
|
||||
try!(callback(TeWait(test.desc.clone(), test.testfn.padding())));
|
||||
}
|
||||
run_test(!opts.run_tests, test, ch.clone());
|
||||
pending += 1;
|
||||
|
@ -829,19 +829,19 @@ fn run_tests(opts: &TestOpts,
|
|||
|
||||
let (desc, result, stdout) = p.recv();
|
||||
if concurrency != 1 {
|
||||
if_ok!(callback(TeWait(desc.clone(), PadNone)));
|
||||
try!(callback(TeWait(desc.clone(), PadNone)));
|
||||
}
|
||||
if_ok!(callback(TeResult(desc, result, stdout)));
|
||||
try!(callback(TeResult(desc, result, stdout)));
|
||||
pending -= 1;
|
||||
}
|
||||
|
||||
// All benchmarks run at the end, in serial.
|
||||
// (this includes metric fns)
|
||||
for b in filtered_benchs_and_metrics.move_iter() {
|
||||
if_ok!(callback(TeWait(b.desc.clone(), b.testfn.padding())));
|
||||
try!(callback(TeWait(b.desc.clone(), b.testfn.padding())));
|
||||
run_test(!opts.run_benchmarks, b, ch.clone());
|
||||
let (test, result, stdout) = p.recv();
|
||||
if_ok!(callback(TeResult(test, result, stdout)));
|
||||
try!(callback(TeResult(test, result, stdout)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1026,7 +1026,7 @@ impl MetricMap {
|
|||
|
||||
/// Write MetricDiff to a file.
|
||||
pub fn save(&self, p: &Path) -> io::IoResult<()> {
|
||||
let mut file = if_ok!(File::create(p));
|
||||
let mut file = try!(File::create(p));
|
||||
let MetricMap(ref map) = *self;
|
||||
map.to_json().to_pretty_writer(&mut file)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue