1
Fork 0

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:
Alex Crichton 2014-02-19 10:07:49 -08:00
parent 06e1281198
commit 7bb498bd7a
32 changed files with 1222 additions and 1226 deletions

View file

@ -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, "&lt;"));
try!(write!(w, "&lt;"));
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, "&gt;"));
try!(write!(w, "&gt;"));
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(())
}