Skip to content

Commit aee7929

Browse files
Nick Desaulniersbrson
Nick Desaulniers
authored andcommitted
Replace most invocations of fail keyword with die! macro
1 parent 2db3175 commit aee7929

File tree

331 files changed

+914
-908
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

331 files changed

+914
-908
lines changed

src/compiletest/compiletest.rc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn parse_config(args: ~[~str]) -> config {
6969
let matches =
7070
&match getopts::getopts(args_, opts) {
7171
Ok(m) => m,
72-
Err(f) => fail getopts::fail_str(f)
72+
Err(f) => die!(getopts::fail_str(f))
7373
};
7474

7575
fn opt_path(m: &getopts::Matches, nm: ~str) -> Path {
@@ -131,7 +131,7 @@ pub fn str_mode(s: ~str) -> mode {
131131
~"run-fail" => mode_run_fail,
132132
~"run-pass" => mode_run_pass,
133133
~"pretty" => mode_pretty,
134-
_ => fail ~"invalid mode"
134+
_ => die!(~"invalid mode")
135135
}
136136
}
137137

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

154154
pub fn test_opts(config: config) -> test::TestOpts {

src/compiletest/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn parse_exec_env(line: ~str) -> Option<(~str, ~str)> {
119119
match strs.len() {
120120
1u => (strs[0], ~""),
121121
2u => (strs[0], strs[1]),
122-
n => fail fmt!("Expected 1 or 2 strings, not %u", n)
122+
n => die!(fmt!("Expected 1 or 2 strings, not %u", n))
123123
}
124124
}
125125
}

src/compiletest/procsrv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn run(lib_path: ~str,
7171
os::close(pipe_in.out);
7272
os::close(pipe_out.in);
7373
os::close(pipe_err.in);
74-
fail;
74+
die!();
7575
}
7676

7777

@@ -99,7 +99,7 @@ pub fn run(lib_path: ~str,
9999
(2, s) => {
100100
errs = s;
101101
}
102-
_ => { fail }
102+
_ => { die!() }
103103
};
104104
count -= 1;
105105
};

src/compiletest/runtest.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ actual:\n\
200200
\n",
201201
expected, actual);
202202
io::stdout().write_str(msg);
203-
fail;
203+
die!();
204204
}
205205
}
206206

@@ -467,7 +467,7 @@ fn compose_and_run_compiler(
467467
fn ensure_dir(path: &Path) {
468468
if os::path_is_dir(path) { return; }
469469
if !os::make_dir(path, 0x1c0i32) {
470-
fail fmt!("can't make dir %s", path.to_str());
470+
die!(fmt!("can't make dir %s", path.to_str()));
471471
}
472472
}
473473

@@ -617,7 +617,7 @@ fn maybe_dump_to_stdout(config: config, out: ~str, err: ~str) {
617617
618618
fn error(err: ~str) { io::stdout().write_line(fmt!("\nerror: %s", err)); }
619619
620-
fn fatal(err: ~str) -> ! { error(err); fail; }
620+
fn fatal(err: ~str) -> ! { error(err); die!(); }
621621
622622
fn fatal_ProcRes(err: ~str, ProcRes: ProcRes) -> ! {
623623
let msg =
@@ -635,5 +635,5 @@ stderr:\n\
635635
\n",
636636
err, ProcRes.cmdline, ProcRes.stdout, ProcRes.stderr);
637637
io::stdout().write_str(msg);
638-
fail;
638+
die!();
639639
}

src/libcargo/cargo.rc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ pub fn load_link(mis: ~[@ast::meta_item]) -> (Option<~str>,
295295
_ => { }
296296
}
297297
}
298-
_ => fail ~"load_link: meta items must be name-values"
298+
_ => die!(~"load_link: meta items must be name-values")
299299
}
300300
}
301301
(name, vers, uuid)
@@ -332,8 +332,8 @@ pub fn load_crate(filename: &Path) -> Option<Crate> {
332332
}
333333
}
334334
_ => {
335-
fail ~"crate attributes may not contain " +
336-
~"meta_words";
335+
die!(~"crate attributes may not contain " +
336+
~"meta_words");
337337
}
338338
}
339339
}
@@ -435,7 +435,7 @@ pub fn rest(s: ~str, start: uint) -> ~str {
435435
pub fn need_dir(s: &Path) {
436436
if os::path_is_dir(s) { return; }
437437
if !os::make_dir(s, 493_i32 /* oct: 755 */) {
438-
fail fmt!("can't make_dir %s", s.to_str());
438+
die!(fmt!("can't make_dir %s", s.to_str()));
439439
}
440440
}
441441

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

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

459459
match *j {
@@ -485,7 +485,7 @@ pub fn parse_source(name: ~str, j: &json::Json) -> @Source {
485485
mut keyfp: keyfp,
486486
packages: DVec() };
487487
}
488-
_ => fail ~"needed dict value in source"
488+
_ => die!(~"needed dict value in source")
489489
};
490490
}
491491

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

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

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

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

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

684684
let mode =
@@ -845,7 +845,7 @@ pub fn install_source(c: &Cargo, path: &Path) {
845845
}
846846

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

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

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

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

11441144
install_source(c, &wd);

src/libcargo/pgp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub fn init(root: &Path) {
8787
p.input().write_str(signing_key());
8888
let s = p.finish();
8989
if s != 0 {
90-
fail ~"pgp init failed";
90+
die!(~"pgp init failed");
9191
}
9292
}
9393
}
@@ -98,7 +98,7 @@ pub fn add(root: &Path, key: &Path) {
9898
run::program_output(~"gpg", ~[~"--homedir", path.to_str(),
9999
~"--import", key.to_str()]);
100100
if p.status != 0 {
101-
fail ~"pgp add failed: " + p.out;
101+
die!(~"pgp add failed: " + p.out);
102102
}
103103
}
104104

src/libcore/condition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<T, U> Condition<T, U> {
3737

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

4343
fn raise_default(t: T, default: &fn() -> U) -> U {

src/libcore/core.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ pub mod core {
251251
pub use condition;
252252
pub use option;
253253
pub use kinds;
254+
pub use sys;
254255
}
255256

256257

src/libcore/dlist.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ priv impl<T> DListNode<T> {
4848
match self.next {
4949
Some(neighbour) => match neighbour.prev {
5050
Some(me) => if !managed::ptr_eq(self, me) {
51-
fail ~"Asymmetric next-link in dlist node."
51+
die!(~"Asymmetric next-link in dlist node.")
5252
},
53-
None => fail ~"One-way next-link in dlist node."
53+
None => die!(~"One-way next-link in dlist node.")
5454
},
5555
None => ()
5656
}
5757
match self.prev {
5858
Some(neighbour) => match neighbour.next {
5959
Some(me) => if !managed::ptr_eq(me, self) {
60-
fail ~"Asymmetric prev-link in dlist node."
60+
die!(~"Asymmetric prev-link in dlist node.")
6161
},
62-
None => fail ~"One-way prev-link in dlist node."
62+
None => die!(~"One-way prev-link in dlist node.")
6363
},
6464
None => ()
6565
}
@@ -76,7 +76,7 @@ impl<T> DListNode<T> {
7676
pure fn next_node(@self) -> @DListNode<T> {
7777
match self.next_link() {
7878
Some(nobe) => nobe,
79-
None => fail ~"This dlist node has no next neighbour."
79+
None => die!(~"This dlist node has no next neighbour.")
8080
}
8181
}
8282
/// Get the previous node in the list, if there is one.
@@ -88,7 +88,7 @@ impl<T> DListNode<T> {
8888
pure fn prev_node(@self) -> @DListNode<T> {
8989
match self.prev_link() {
9090
Some(nobe) => nobe,
91-
None => fail ~"This dlist node has no previous neighbour."
91+
None => die!(~"This dlist node has no previous neighbour.")
9292
}
9393
}
9494
}
@@ -135,21 +135,21 @@ priv impl<T> DList<T> {
135135
// These asserts could be stronger if we had node-root back-pointers,
136136
// but those wouldn't allow for O(1) append.
137137
if self.size == 0 {
138-
fail ~"This dlist is empty; that node can't be on it."
138+
die!(~"This dlist is empty; that node can't be on it.")
139139
}
140-
if !nobe.linked { fail ~"That node isn't linked to any dlist." }
140+
if !nobe.linked { die!(~"That node isn't linked to any dlist.") }
141141
if !((nobe.prev.is_some()
142142
|| managed::ptr_eq(self.hd.expect(~"headless dlist?"),
143143
nobe)) &&
144144
(nobe.next.is_some()
145145
|| managed::ptr_eq(self.tl.expect(~"tailless dlist?"),
146146
nobe))) {
147-
fail ~"That node isn't on this dlist."
147+
die!(~"That node isn't on this dlist.")
148148
}
149149
}
150150
fn make_mine(nobe: @DListNode<T>) {
151151
if nobe.prev.is_some() || nobe.next.is_some() || nobe.linked {
152-
fail ~"Cannot insert node that's already on a dlist!"
152+
die!(~"Cannot insert node that's already on a dlist!")
153153
}
154154
nobe.linked = true;
155155
}
@@ -313,14 +313,16 @@ impl<T> DList<T> {
313313
pure fn head_n(@self) -> @DListNode<T> {
314314
match self.hd {
315315
Some(nobe) => nobe,
316-
None => fail ~"Attempted to get the head of an empty dlist."
316+
None => die!(
317+
~"Attempted to get the head of an empty dlist.")
317318
}
318319
}
319320
/// Get the node at the list's tail, failing if empty. O(1).
320321
pure fn tail_n(@self) -> @DListNode<T> {
321322
match self.tl {
322323
Some(nobe) => nobe,
323-
None => fail ~"Attempted to get the tail of an empty dlist."
324+
None => die!(
325+
~"Attempted to get the tail of an empty dlist.")
324326
}
325327
}
326328
@@ -333,7 +335,7 @@ impl<T> DList<T> {
333335
*/
334336
fn append(@self, them: @DList<T>) {
335337
if managed::ptr_eq(self, them) {
336-
fail ~"Cannot append a dlist to itself!"
338+
die!(~"Cannot append a dlist to itself!")
337339
}
338340
if them.len() > 0 {
339341
self.link(self.tl, them.hd);
@@ -350,7 +352,7 @@ impl<T> DList<T> {
350352
*/
351353
fn prepend(@self, them: @DList<T>) {
352354
if managed::ptr_eq(self, them) {
353-
fail ~"Cannot prepend a dlist to itself!"
355+
die!(~"Cannot prepend a dlist to itself!")
354356
}
355357
if them.len() > 0 {
356358
self.link(them.tl, self.hd);

src/libcore/dvec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ priv impl<A> DVec<A> {
9191
unsafe {
9292
let data: *() = cast::reinterpret_cast(&self.data);
9393
if data.is_null() {
94-
fail ~"Recursive use of dvec";
94+
die!(~"Recursive use of dvec");
9595
}
9696
}
9797
}
@@ -102,7 +102,7 @@ priv impl<A> DVec<A> {
102102
let mut data = cast::reinterpret_cast(&null::<()>());
103103
data <-> self.data;
104104
let data_ptr: *() = cast::reinterpret_cast(&data);
105-
if data_ptr.is_null() { fail ~"Recursive use of dvec"; }
105+
if data_ptr.is_null() { die!(~"Recursive use of dvec"); }
106106
return f(move data);
107107
}
108108
}
@@ -329,7 +329,7 @@ impl<A: Copy> DVec<A> {
329329
330330
let length = self.len();
331331
if length == 0 {
332-
fail ~"attempt to retrieve the last element of an empty vector";
332+
die!(~"attempt to retrieve the last element of an empty vector");
333333
}
334334

335335
return self.data[length - 1];

src/libcore/either.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub pure fn unwrap_left<T,U>(eith: Either<T,U>) -> T {
136136
//! Retrieves the value in the left branch. Fails if the either is Right.
137137
138138
match move eith {
139-
Left(move x) => move x, Right(_) => fail ~"either::unwrap_left Right"
139+
Left(move x) => move x, Right(_) => die!(~"either::unwrap_left Right")
140140
}
141141
}
142142
@@ -145,7 +145,7 @@ pub pure fn unwrap_right<T,U>(eith: Either<T,U>) -> U {
145145
//! Retrieves the value in the right branch. Fails if the either is Left.
146146
147147
match move eith {
148-
Right(move x) => move x, Left(_) => fail ~"either::unwrap_right Left"
148+
Right(move x) => move x, Left(_) => die!(~"either::unwrap_right Left")
149149
}
150150
}
151151

src/libcore/extfmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ pub mod ct {
342342
}
343343
344344
#[cfg(test)]
345-
fn die(s: &str) -> ! { fail s.to_owned() }
345+
fn die(s: &str) -> ! { die!(s.to_owned()) }
346346
347347
#[test]
348348
fn test_parse_count() {

0 commit comments

Comments
 (0)