Skip to content

Commit

Permalink
Replace most invocations of fail keyword with die! macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Desaulniers authored and brson committed Feb 1, 2013
1 parent 2db3175 commit aee7929
Show file tree
Hide file tree
Showing 331 changed files with 914 additions and 908 deletions.
6 changes: 3 additions & 3 deletions src/compiletest/compiletest.rc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn parse_config(args: ~[~str]) -> config {
let matches =
&match getopts::getopts(args_, opts) {
Ok(m) => m,
Err(f) => fail getopts::fail_str(f)
Err(f) => die!(getopts::fail_str(f))
};

fn opt_path(m: &getopts::Matches, nm: ~str) -> Path {
Expand Down Expand Up @@ -131,7 +131,7 @@ pub fn str_mode(s: ~str) -> mode {
~"run-fail" => mode_run_fail,
~"run-pass" => mode_run_pass,
~"pretty" => mode_pretty,
_ => fail ~"invalid mode"
_ => die!(~"invalid mode")
}
}

Expand All @@ -148,7 +148,7 @@ pub fn run_tests(config: config) {
let opts = test_opts(config);
let tests = make_tests(config);
let res = test::run_tests_console(&opts, tests);
if !res { fail ~"Some tests failed"; }
if !res { die!(~"Some tests failed"); }
}

pub fn test_opts(config: config) -> test::TestOpts {
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn parse_exec_env(line: ~str) -> Option<(~str, ~str)> {
match strs.len() {
1u => (strs[0], ~""),
2u => (strs[0], strs[1]),
n => fail fmt!("Expected 1 or 2 strings, not %u", n)
n => die!(fmt!("Expected 1 or 2 strings, not %u", n))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn run(lib_path: ~str,
os::close(pipe_in.out);
os::close(pipe_out.in);
os::close(pipe_err.in);
fail;
die!();
}


Expand Down Expand Up @@ -99,7 +99,7 @@ pub fn run(lib_path: ~str,
(2, s) => {
errs = s;
}
_ => { fail }
_ => { die!() }
};
count -= 1;
};
Expand Down
8 changes: 4 additions & 4 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ actual:\n\
\n",
expected, actual);
io::stdout().write_str(msg);
fail;
die!();
}
}

Expand Down Expand Up @@ -467,7 +467,7 @@ fn compose_and_run_compiler(
fn ensure_dir(path: &Path) {
if os::path_is_dir(path) { return; }
if !os::make_dir(path, 0x1c0i32) {
fail fmt!("can't make dir %s", path.to_str());
die!(fmt!("can't make dir %s", path.to_str()));
}
}

Expand Down Expand Up @@ -617,7 +617,7 @@ fn maybe_dump_to_stdout(config: config, out: ~str, err: ~str) {
fn error(err: ~str) { io::stdout().write_line(fmt!("\nerror: %s", err)); }

fn fatal(err: ~str) -> ! { error(err); fail; }
fn fatal(err: ~str) -> ! { error(err); die!(); }

fn fatal_ProcRes(err: ~str, ProcRes: ProcRes) -> ! {
let msg =
Expand All @@ -635,5 +635,5 @@ stderr:\n\
\n",
err, ProcRes.cmdline, ProcRes.stdout, ProcRes.stderr);
io::stdout().write_str(msg);
fail;
die!();
}
32 changes: 16 additions & 16 deletions src/libcargo/cargo.rc
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ pub fn load_link(mis: ~[@ast::meta_item]) -> (Option<~str>,
_ => { }
}
}
_ => fail ~"load_link: meta items must be name-values"
_ => die!(~"load_link: meta items must be name-values")
}
}
(name, vers, uuid)
Expand Down Expand Up @@ -332,8 +332,8 @@ pub fn load_crate(filename: &Path) -> Option<Crate> {
}
}
_ => {
fail ~"crate attributes may not contain " +
~"meta_words";
die!(~"crate attributes may not contain " +
~"meta_words");
}
}
}
Expand Down Expand Up @@ -435,7 +435,7 @@ pub fn rest(s: ~str, start: uint) -> ~str {
pub fn need_dir(s: &Path) {
if os::path_is_dir(s) { return; }
if !os::make_dir(s, 493_i32 /* oct: 755 */) {
fail fmt!("can't make_dir %s", s.to_str());
die!(fmt!("can't make_dir %s", s.to_str()));
}
}

Expand All @@ -453,7 +453,7 @@ pub fn valid_pkg_name(s: &str) -> bool {

pub fn parse_source(name: ~str, j: &json::Json) -> @Source {
if !valid_pkg_name(name) {
fail fmt!("'%s' is an invalid source name", name);
die!(fmt!("'%s' is an invalid source name", name));
}

match *j {
Expand Down Expand Up @@ -485,7 +485,7 @@ pub fn parse_source(name: ~str, j: &json::Json) -> @Source {
mut keyfp: keyfp,
packages: DVec() };
}
_ => fail ~"needed dict value in source"
_ => die!(~"needed dict value in source")
};
}

Expand All @@ -500,8 +500,8 @@ pub fn try_parse_sources(filename: &Path,
debug!("source: %s", *k);
}
}
Ok(_) => fail ~"malformed sources.json",
Err(e) => fail fmt!("%s:%s", filename.to_str(), e.to_str())
Ok(_) => die!(~"malformed sources.json"),
Err(e) => die!(fmt!("%s:%s", filename.to_str(), e.to_str()))
}
}

Expand Down Expand Up @@ -662,7 +662,7 @@ pub fn build_cargo_options(argv: ~[~str]) -> Options {
let matches = &match getopts::getopts(argv, opts()) {
result::Ok(m) => m,
result::Err(f) => {
fail fmt!("%s", getopts::fail_str(f));
die!(fmt!("%s", getopts::fail_str(f)));
}
};

Expand All @@ -675,10 +675,10 @@ pub fn build_cargo_options(argv: ~[~str]) -> Options {
let is_install = len > 1u && matches.free[1] == ~"install";
let is_uninstall = len > 1u && matches.free[1] == ~"uninstall";

if G && g { fail ~"-G and -g both provided"; }
if G && g { die!(~"-G and -g both provided"); }

if !is_install && !is_uninstall && (g || G) {
fail ~"-g and -G are only valid for `install` and `uninstall|rm`";
die!(~"-g and -G are only valid for `install` and `uninstall|rm`");
}

let mode =
Expand Down Expand Up @@ -845,7 +845,7 @@ pub fn install_source(c: &Cargo, path: &Path) {
}

if vec::is_empty(cratefiles) {
fail ~"this doesn't look like a rust package (no .rc files)";
die!(~"this doesn't look like a rust package (no .rc files)");
}

for cratefiles.each |cf| {
Expand Down Expand Up @@ -888,7 +888,7 @@ pub fn install_curl(c: &Cargo, wd: &Path, url: ~str) {
let p = run::program_output(~"curl", ~[~"-f", ~"-s", ~"-o",
tarpath.to_str(), url]);
if p.status != 0 {
fail fmt!("fetch of %s failed: %s", url, p.err);
die!(fmt!("fetch of %s failed: %s", url, p.err));
}
run::run_program(~"tar", ~[~"-x", ~"--strip-components=1",
~"-C", wd.to_str(),
Expand Down Expand Up @@ -1123,8 +1123,8 @@ pub fn install_query(c: &Cargo, wd: &Path, target: ~str) {
pub fn get_temp_workdir(c: &Cargo) -> Path {
match tempfile::mkdtemp(&c.workdir, "cargo") {
Some(wd) => wd,
None => fail fmt!("needed temp dir: %s",
c.workdir.to_str())
None => die!(fmt!("needed temp dir: %s",
c.workdir.to_str()))
}
}

Expand All @@ -1138,7 +1138,7 @@ pub fn cmd_install(c: &Cargo) {
wd.to_str()]);

if status != 0 {
fail fmt!("could not copy directory: %s", cwd.to_str());
die!(fmt!("could not copy directory: %s", cwd.to_str()));
}

install_source(c, &wd);
Expand Down
4 changes: 2 additions & 2 deletions src/libcargo/pgp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub fn init(root: &Path) {
p.input().write_str(signing_key());
let s = p.finish();
if s != 0 {
fail ~"pgp init failed";
die!(~"pgp init failed");
}
}
}
Expand All @@ -98,7 +98,7 @@ pub fn add(root: &Path, key: &Path) {
run::program_output(~"gpg", ~[~"--homedir", path.to_str(),
~"--import", key.to_str()]);
if p.status != 0 {
fail ~"pgp add failed: " + p.out;
die!(~"pgp add failed: " + p.out);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<T, U> Condition<T, U> {

fn raise(t: T) -> U {
let msg = fmt!("Unhandled condition: %s: %?", self.name, t);
self.raise_default(t, || fail copy msg)
self.raise_default(t, || die!(copy msg))
}

fn raise_default(t: T, default: &fn() -> U) -> U {
Expand Down
1 change: 1 addition & 0 deletions src/libcore/core.rc
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ pub mod core {
pub use condition;
pub use option;
pub use kinds;
pub use sys;
}


Expand Down
30 changes: 16 additions & 14 deletions src/libcore/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ priv impl<T> DListNode<T> {
match self.next {
Some(neighbour) => match neighbour.prev {
Some(me) => if !managed::ptr_eq(self, me) {
fail ~"Asymmetric next-link in dlist node."
die!(~"Asymmetric next-link in dlist node.")
},
None => fail ~"One-way next-link in dlist node."
None => die!(~"One-way next-link in dlist node.")
},
None => ()
}
match self.prev {
Some(neighbour) => match neighbour.next {
Some(me) => if !managed::ptr_eq(me, self) {
fail ~"Asymmetric prev-link in dlist node."
die!(~"Asymmetric prev-link in dlist node.")
},
None => fail ~"One-way prev-link in dlist node."
None => die!(~"One-way prev-link in dlist node.")
},
None => ()
}
Expand All @@ -76,7 +76,7 @@ impl<T> DListNode<T> {
pure fn next_node(@self) -> @DListNode<T> {
match self.next_link() {
Some(nobe) => nobe,
None => fail ~"This dlist node has no next neighbour."
None => die!(~"This dlist node has no next neighbour.")
}
}
/// Get the previous node in the list, if there is one.
Expand All @@ -88,7 +88,7 @@ impl<T> DListNode<T> {
pure fn prev_node(@self) -> @DListNode<T> {
match self.prev_link() {
Some(nobe) => nobe,
None => fail ~"This dlist node has no previous neighbour."
None => die!(~"This dlist node has no previous neighbour.")
}
}
}
Expand Down Expand Up @@ -135,21 +135,21 @@ priv impl<T> DList<T> {
// These asserts could be stronger if we had node-root back-pointers,
// but those wouldn't allow for O(1) append.
if self.size == 0 {
fail ~"This dlist is empty; that node can't be on it."
die!(~"This dlist is empty; that node can't be on it.")
}
if !nobe.linked { fail ~"That node isn't linked to any dlist." }
if !nobe.linked { die!(~"That node isn't linked to any dlist.") }
if !((nobe.prev.is_some()
|| managed::ptr_eq(self.hd.expect(~"headless dlist?"),
nobe)) &&
(nobe.next.is_some()
|| managed::ptr_eq(self.tl.expect(~"tailless dlist?"),
nobe))) {
fail ~"That node isn't on this dlist."
die!(~"That node isn't on this dlist.")
}
}
fn make_mine(nobe: @DListNode<T>) {
if nobe.prev.is_some() || nobe.next.is_some() || nobe.linked {
fail ~"Cannot insert node that's already on a dlist!"
die!(~"Cannot insert node that's already on a dlist!")
}
nobe.linked = true;
}
Expand Down Expand Up @@ -313,14 +313,16 @@ impl<T> DList<T> {
pure fn head_n(@self) -> @DListNode<T> {
match self.hd {
Some(nobe) => nobe,
None => fail ~"Attempted to get the head of an empty dlist."
None => die!(
~"Attempted to get the head of an empty dlist.")
}
}
/// Get the node at the list's tail, failing if empty. O(1).
pure fn tail_n(@self) -> @DListNode<T> {
match self.tl {
Some(nobe) => nobe,
None => fail ~"Attempted to get the tail of an empty dlist."
None => die!(
~"Attempted to get the tail of an empty dlist.")
}
}

Expand All @@ -333,7 +335,7 @@ impl<T> DList<T> {
*/
fn append(@self, them: @DList<T>) {
if managed::ptr_eq(self, them) {
fail ~"Cannot append a dlist to itself!"
die!(~"Cannot append a dlist to itself!")
}
if them.len() > 0 {
self.link(self.tl, them.hd);
Expand All @@ -350,7 +352,7 @@ impl<T> DList<T> {
*/
fn prepend(@self, them: @DList<T>) {
if managed::ptr_eq(self, them) {
fail ~"Cannot prepend a dlist to itself!"
die!(~"Cannot prepend a dlist to itself!")
}
if them.len() > 0 {
self.link(them.tl, self.hd);
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/dvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ priv impl<A> DVec<A> {
unsafe {
let data: *() = cast::reinterpret_cast(&self.data);
if data.is_null() {
fail ~"Recursive use of dvec";
die!(~"Recursive use of dvec");
}
}
}
Expand All @@ -102,7 +102,7 @@ priv impl<A> DVec<A> {
let mut data = cast::reinterpret_cast(&null::<()>());
data <-> self.data;
let data_ptr: *() = cast::reinterpret_cast(&data);
if data_ptr.is_null() { fail ~"Recursive use of dvec"; }
if data_ptr.is_null() { die!(~"Recursive use of dvec"); }
return f(move data);
}
}
Expand Down Expand Up @@ -329,7 +329,7 @@ impl<A: Copy> DVec<A> {

let length = self.len();
if length == 0 {
fail ~"attempt to retrieve the last element of an empty vector";
die!(~"attempt to retrieve the last element of an empty vector");
}

return self.data[length - 1];
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub pure fn unwrap_left<T,U>(eith: Either<T,U>) -> T {
//! Retrieves the value in the left branch. Fails if the either is Right.

match move eith {
Left(move x) => move x, Right(_) => fail ~"either::unwrap_left Right"
Left(move x) => move x, Right(_) => die!(~"either::unwrap_left Right")
}
}

Expand All @@ -145,7 +145,7 @@ pub pure fn unwrap_right<T,U>(eith: Either<T,U>) -> U {
//! Retrieves the value in the right branch. Fails if the either is Left.

match move eith {
Right(move x) => move x, Left(_) => fail ~"either::unwrap_right Left"
Right(move x) => move x, Left(_) => die!(~"either::unwrap_right Left")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/extfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ pub mod ct {
}
#[cfg(test)]
fn die(s: &str) -> ! { fail s.to_owned() }
fn die(s: &str) -> ! { die!(s.to_owned()) }
#[test]
fn test_parse_count() {
Expand Down
Loading

0 comments on commit aee7929

Please sign in to comment.