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

File tree

16 files changed

+28
-63
lines changed

16 files changed

+28
-63
lines changed

src/libextra/glob.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 0 additions & 28 deletions
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::*;

0 commit comments

Comments
 (0)