Skip to content

Commit e5fdc7d

Browse files
committed
auto merge of #9320 : chris-morgan/rust/unreachable-macro-part-two-of-two-containing-the-destruction-of-the-unreachable-function, r=alexcrichton
This is the second of two parts of #8991, now possible as a new snapshot has been made. (The first part implemented the unreachable!() macro; it was #8992, 6b7b8f2.) ``std::util::unreachable()`` is removed summarily; any code which used it should now use the ``unreachable!()`` macro. Closes #9312. Closes #8991.
2 parents c7c769d + e2807a4 commit e5fdc7d

16 files changed

+28
-63
lines changed

src/libextra/glob.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* `glob`/`fnmatch` functions.
2424
*/
2525

26-
use std::{os, path, util};
26+
use std::{os, path};
2727

2828
use sort;
2929

@@ -356,7 +356,7 @@ impl Pattern {
356356
chars_eq(c, c2, options.case_sensitive)
357357
}
358358
AnySequence => {
359-
util::unreachable()
359+
unreachable!()
360360
}
361361
};
362362
if !matches {

src/libextra/terminfo/parm.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
261261
flags.width = (cur as uint - '0' as uint);
262262
fstate = FormatStateWidth;
263263
}
264-
_ => util::unreachable()
264+
_ => unreachable!()
265265
}
266266
state = FormatPattern(flags, fstate);
267267
}
@@ -487,7 +487,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<~[u8],~str> {
487487
FormatDigit => 10,
488488
FormatOctal => 8,
489489
FormatHex|FormatHEX => 16,
490-
FormatString => util::unreachable()
490+
FormatString => unreachable!()
491491
};
492492
let mut s = ~[];
493493
match op {
@@ -535,7 +535,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<~[u8],~str> {
535535
s.push_all_move(s_);
536536
}
537537
}
538-
FormatString => util::unreachable()
538+
FormatString => unreachable!()
539539
}
540540
s
541541
}

src/librustc/back/rpath.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use metadata::cstore;
1414
use metadata::filesearch;
1515

1616
use std::hashmap::HashSet;
17-
use std::{os, util, vec};
17+
use std::{os, vec};
1818

1919
fn not_win32(os: session::Os) -> bool {
2020
os != session::OsWin32
@@ -116,7 +116,7 @@ pub fn get_rpath_relative_to_output(os: session::Os,
116116
session::OsAndroid | session::OsLinux | session::OsFreebsd
117117
=> "$ORIGIN",
118118
session::OsMacos => "@executable_path",
119-
session::OsWin32 => util::unreachable()
119+
session::OsWin32 => unreachable!()
120120
};
121121

122122
Path(prefix).push_rel(&os::make_absolute(output).get_relative_to(&os::make_absolute(lib)))

src/librustc/middle/entry.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use syntax::codemap::Span;
1818
use syntax::parse::token::special_idents;
1919
use syntax::visit;
2020
use syntax::visit::Visitor;
21-
use std::util;
2221

2322
struct EntryContext {
2423
session: Session,
@@ -94,7 +93,7 @@ fn find_item(item: @item, ctxt: &mut EntryContext) {
9493
ctxt.non_main_fns.push((item.id, item.span));
9594
}
9695
}
97-
_ => util::unreachable()
96+
_ => unreachable!()
9897
}
9998
}
10099

src/librustc/middle/trans/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ fn variant_opt(bcx: @mut Block, pat_id: ast::NodeId)
356356
adt::represent_node(bcx, pat_id))
357357
}
358358
}
359-
::std::util::unreachable();
359+
unreachable!();
360360
}
361361
ast::DefFn(*) |
362362
ast::DefStruct(_) => {

src/librustdoc/prune_private_pass.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ use fold::Fold;
2020
use fold;
2121
use pass::Pass;
2222

23-
use std::util;
24-
2523
pub fn mk_pass() -> Pass {
2624
Pass {
2725
name: ~"prune_private",
@@ -148,7 +146,7 @@ fn is_visible(srv: astsrv::Srv, doc: doc::ItemDoc) -> bool {
148146
}
149147
}
150148
}
151-
_ => util::unreachable()
149+
_ => unreachable!()
152150
}
153151
}
154152
}

src/libstd/hashmap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use option::{None, Option, Some};
2727
use rand::RngUtil;
2828
use rand;
2929
use uint;
30-
use util::{replace, unreachable};
30+
use util::replace;
3131
use vec::{ImmutableVector, MutableVector, OwnedVector};
3232
use vec;
3333

@@ -187,7 +187,7 @@ impl<K:Hash + Eq,V> HashMap<K, V> {
187187
fn mut_value_for_bucket<'a>(&'a mut self, idx: uint) -> &'a mut V {
188188
match self.buckets[idx] {
189189
Some(ref mut bkt) => &mut bkt.value,
190-
None => unreachable()
190+
None => unreachable!()
191191
}
192192
}
193193

src/libstd/rand.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ use str;
5656
use sys;
5757
use u32;
5858
use uint;
59-
use util;
6059
use vec;
6160
use libc::size_t;
6261

@@ -586,7 +585,7 @@ impl<R: Rng> RngUtil for R {
586585
return Some(item.item.clone());
587586
}
588587
}
589-
util::unreachable();
588+
unreachable!();
590589
}
591590

592591
/**

src/libstd/rt/io/extensions.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use rt::io::{Reader, Writer, Decorator};
2121
use rt::io::{read_error, standard_error, EndOfFile, DEFAULT_BUF_SIZE};
2222
use option::{Option, Some, None};
2323
use unstable::finally::Finally;
24-
use util;
2524
use cast;
2625
use io::{u64_to_le_bytes, u64_to_be_bytes};
2726

@@ -293,7 +292,7 @@ impl<T: Reader> ReaderUtil for T {
293292
self.read_byte()
294293
}
295294
Some(1) => Some(buf[0]),
296-
Some(_) => util::unreachable(),
295+
Some(_) => unreachable!(),
297296
None => None
298297
}
299298
}

src/libstd/util.rs

-28
Original file line numberDiff line numberDiff line change
@@ -104,34 +104,6 @@ impl Void {
104104
}
105105

106106

107-
/**
108-
A utility function for indicating unreachable code. It will fail if
109-
executed. This is occasionally useful to put after loops that never
110-
terminate normally, but instead directly return from a function.
111-
112-
# Example
113-
114-
~~~ {.rust}
115-
fn choose_weighted_item(v: &[Item]) -> Item {
116-
assert!(!v.is_empty());
117-
let mut so_far = 0u;
118-
for v.each |item| {
119-
so_far += item.weight;
120-
if so_far > 100 {
121-
return item;
122-
}
123-
}
124-
// The above loop always returns, so we must hint to the
125-
// type checker that it isn't possible to get down here
126-
util::unreachable();
127-
}
128-
~~~
129-
130-
*/
131-
pub fn unreachable() -> ! {
132-
fail!("internal error: entered unreachable code");
133-
}
134-
135107
#[cfg(test)]
136108
mod tests {
137109
use super::*;

src/test/compile-fail/borrowck-move-out-of-vec-tail.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ pub fn main() {
1919
//~^^ ERROR cannot move out of dereference of & pointer
2020
}
2121
_ => {
22-
::std::util::unreachable();
22+
unreachable!();
2323
}
2424
}
2525
let z = tail[0].clone();
2626
info!(fmt!("%?", z));
2727
}
2828
_ => {
29-
::std::util::unreachable();
29+
unreachable!();
3030
}
3131
}
3232
}

src/test/compile-fail/borrowck-vec-pattern-move-tail.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ fn main() {
22
let mut a = [1, 2, 3, 4];
33
let t = match a {
44
[1, 2, ..tail] => tail,
5-
_ => std::util::unreachable()
5+
_ => unreachable!()
66
};
77
a[0] = 0; //~ ERROR cannot assign to `a[]` because it is borrowed
88
t[0];

src/test/debug-info/lexical-scope-in-if.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@
7878
// check:$16 = -1
7979
// debugger:continue
8080

81-
use std::util;
82-
8381
fn main() {
8482

8583
let x = 999;
@@ -102,14 +100,14 @@ fn main() {
102100
zzz();
103101
sentinel();
104102
} else {
105-
util::unreachable();
103+
unreachable!();
106104
}
107105

108106
zzz();
109107
sentinel();
110108

111109
if x > 1000 {
112-
util::unreachable();
110+
unreachable!();
113111
} else {
114112
zzz();
115113
sentinel();

src/test/run-pass/vec-matching-fixed.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
fn a() {
22
let x = [1, 2, 3];
33
match x {
4-
[1, 2, 4] => ::std::util::unreachable(),
5-
[0, 2, 3, .._] => ::std::util::unreachable(),
6-
[0, .._, 3] => ::std::util::unreachable(),
7-
[0, .._] => ::std::util::unreachable(),
4+
[1, 2, 4] => unreachable!(),
5+
[0, 2, 3, .._] => unreachable!(),
6+
[0, .._, 3] => unreachable!(),
7+
[0, .._] => unreachable!(),
88
[1, 2, 3] => (),
9-
[_, _, _] => ::std::util::unreachable(),
9+
[_, _, _] => unreachable!(),
1010
}
1111
match x {
1212
[.._] => (),

src/test/run-pass/vec-matching-legal-tail-element-borrow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub fn main() {
33
if !x.is_empty() {
44
let el = match x {
55
[1, ..ref tail] => &tail[0],
6-
_ => ::std::util::unreachable()
6+
_ => unreachable!()
77
};
88
printfln!("%d", *el);
99
}

src/test/run-pass/vec-tail-matching.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ pub fn main() {
1717
1818
match tail {
1919
[Foo { _ }, _, Foo { _ }, .. _tail] => {
20-
::std::util::unreachable();
20+
unreachable!();
2121
}
2222
[Foo { string: ref a }, Foo { string: ref b }] => {
2323
assert_eq!("bar", a.slice(0, a.len()));
2424
assert_eq!("baz", b.slice(0, b.len()));
2525
}
2626
_ => {
27-
::std::util::unreachable();
27+
unreachable!();
2828
}
2929
}
3030
}
3131
_ => {
32-
::std::util::unreachable();
32+
unreachable!();
3333
}
3434
}
3535
}

0 commit comments

Comments
 (0)