Replace unreachable() calls with unreachable!().

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, 6b7b8f2682.)

``std::util::unreachable()`` is removed summarily; any code which used
it should now use the ``unreachable!()`` macro.

Closes #9312.

Closes #8991.
This commit is contained in:
Chris Morgan 2013-09-19 15:04:03 +10:00
parent 4dacd73651
commit e2807a4565
16 changed files with 28 additions and 63 deletions

View File

@ -23,7 +23,7 @@
* `glob`/`fnmatch` functions. * `glob`/`fnmatch` functions.
*/ */
use std::{os, path, util}; use std::{os, path};
use sort; use sort;
@ -356,7 +356,7 @@ impl Pattern {
chars_eq(c, c2, options.case_sensitive) chars_eq(c, c2, options.case_sensitive)
} }
AnySequence => { AnySequence => {
util::unreachable() unreachable!()
} }
}; };
if !matches { if !matches {

View File

@ -261,7 +261,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
flags.width = (cur as uint - '0' as uint); flags.width = (cur as uint - '0' as uint);
fstate = FormatStateWidth; fstate = FormatStateWidth;
} }
_ => util::unreachable() _ => unreachable!()
} }
state = FormatPattern(flags, fstate); state = FormatPattern(flags, fstate);
} }
@ -487,7 +487,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<~[u8],~str> {
FormatDigit => 10, FormatDigit => 10,
FormatOctal => 8, FormatOctal => 8,
FormatHex|FormatHEX => 16, FormatHex|FormatHEX => 16,
FormatString => util::unreachable() FormatString => unreachable!()
}; };
let mut s = ~[]; let mut s = ~[];
match op { match op {
@ -535,7 +535,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<~[u8],~str> {
s.push_all_move(s_); s.push_all_move(s_);
} }
} }
FormatString => util::unreachable() FormatString => unreachable!()
} }
s s
} }

View File

@ -14,7 +14,7 @@ use metadata::cstore;
use metadata::filesearch; use metadata::filesearch;
use std::hashmap::HashSet; use std::hashmap::HashSet;
use std::{os, util, vec}; use std::{os, vec};
fn not_win32(os: session::Os) -> bool { fn not_win32(os: session::Os) -> bool {
os != session::OsWin32 os != session::OsWin32
@ -116,7 +116,7 @@ pub fn get_rpath_relative_to_output(os: session::Os,
session::OsAndroid | session::OsLinux | session::OsFreebsd session::OsAndroid | session::OsLinux | session::OsFreebsd
=> "$ORIGIN", => "$ORIGIN",
session::OsMacos => "@executable_path", session::OsMacos => "@executable_path",
session::OsWin32 => util::unreachable() session::OsWin32 => unreachable!()
}; };
Path(prefix).push_rel(&os::make_absolute(output).get_relative_to(&os::make_absolute(lib))) Path(prefix).push_rel(&os::make_absolute(output).get_relative_to(&os::make_absolute(lib)))

View File

@ -18,7 +18,6 @@ use syntax::codemap::Span;
use syntax::parse::token::special_idents; use syntax::parse::token::special_idents;
use syntax::visit; use syntax::visit;
use syntax::visit::Visitor; use syntax::visit::Visitor;
use std::util;
struct EntryContext { struct EntryContext {
session: Session, session: Session,
@ -94,7 +93,7 @@ fn find_item(item: @item, ctxt: &mut EntryContext) {
ctxt.non_main_fns.push((item.id, item.span)); ctxt.non_main_fns.push((item.id, item.span));
} }
} }
_ => util::unreachable() _ => unreachable!()
} }
} }

View File

@ -356,7 +356,7 @@ fn variant_opt(bcx: @mut Block, pat_id: ast::NodeId)
adt::represent_node(bcx, pat_id)) adt::represent_node(bcx, pat_id))
} }
} }
::std::util::unreachable(); unreachable!();
} }
ast::DefFn(*) | ast::DefFn(*) |
ast::DefStruct(_) => { ast::DefStruct(_) => {

View File

@ -20,8 +20,6 @@ use fold::Fold;
use fold; use fold;
use pass::Pass; use pass::Pass;
use std::util;
pub fn mk_pass() -> Pass { pub fn mk_pass() -> Pass {
Pass { Pass {
name: ~"prune_private", name: ~"prune_private",
@ -148,7 +146,7 @@ fn is_visible(srv: astsrv::Srv, doc: doc::ItemDoc) -> bool {
} }
} }
} }
_ => util::unreachable() _ => unreachable!()
} }
} }
} }

View File

@ -27,7 +27,7 @@ use option::{None, Option, Some};
use rand::RngUtil; use rand::RngUtil;
use rand; use rand;
use uint; use uint;
use util::{replace, unreachable}; use util::replace;
use vec::{ImmutableVector, MutableVector, OwnedVector}; use vec::{ImmutableVector, MutableVector, OwnedVector};
use vec; use vec;
@ -187,7 +187,7 @@ impl<K:Hash + Eq,V> HashMap<K, V> {
fn mut_value_for_bucket<'a>(&'a mut self, idx: uint) -> &'a mut V { fn mut_value_for_bucket<'a>(&'a mut self, idx: uint) -> &'a mut V {
match self.buckets[idx] { match self.buckets[idx] {
Some(ref mut bkt) => &mut bkt.value, Some(ref mut bkt) => &mut bkt.value,
None => unreachable() None => unreachable!()
} }
} }

View File

@ -56,7 +56,6 @@ use str;
use sys; use sys;
use u32; use u32;
use uint; use uint;
use util;
use vec; use vec;
use libc::size_t; use libc::size_t;
@ -586,7 +585,7 @@ impl<R: Rng> RngUtil for R {
return Some(item.item.clone()); return Some(item.item.clone());
} }
} }
util::unreachable(); unreachable!();
} }
/** /**

View File

@ -21,7 +21,6 @@ use rt::io::{Reader, Writer, Decorator};
use rt::io::{read_error, standard_error, EndOfFile, DEFAULT_BUF_SIZE}; use rt::io::{read_error, standard_error, EndOfFile, DEFAULT_BUF_SIZE};
use option::{Option, Some, None}; use option::{Option, Some, None};
use unstable::finally::Finally; use unstable::finally::Finally;
use util;
use cast; use cast;
use io::{u64_to_le_bytes, u64_to_be_bytes}; use io::{u64_to_le_bytes, u64_to_be_bytes};
@ -293,7 +292,7 @@ impl<T: Reader> ReaderUtil for T {
self.read_byte() self.read_byte()
} }
Some(1) => Some(buf[0]), Some(1) => Some(buf[0]),
Some(_) => util::unreachable(), Some(_) => unreachable!(),
None => None None => None
} }
} }

View File

@ -104,34 +104,6 @@ impl Void {
} }
/**
A utility function for indicating unreachable code. It will fail if
executed. This is occasionally useful to put after loops that never
terminate normally, but instead directly return from a function.
# Example
~~~ {.rust}
fn choose_weighted_item(v: &[Item]) -> Item {
assert!(!v.is_empty());
let mut so_far = 0u;
for v.each |item| {
so_far += item.weight;
if so_far > 100 {
return item;
}
}
// The above loop always returns, so we must hint to the
// type checker that it isn't possible to get down here
util::unreachable();
}
~~~
*/
pub fn unreachable() -> ! {
fail!("internal error: entered unreachable code");
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View File

@ -19,14 +19,14 @@ pub fn main() {
//~^^ ERROR cannot move out of dereference of & pointer //~^^ ERROR cannot move out of dereference of & pointer
} }
_ => { _ => {
::std::util::unreachable(); unreachable!();
} }
} }
let z = tail[0].clone(); let z = tail[0].clone();
info!(fmt!("%?", z)); info!(fmt!("%?", z));
} }
_ => { _ => {
::std::util::unreachable(); unreachable!();
} }
} }
} }

View File

@ -2,7 +2,7 @@ fn main() {
let mut a = [1, 2, 3, 4]; let mut a = [1, 2, 3, 4];
let t = match a { let t = match a {
[1, 2, ..tail] => tail, [1, 2, ..tail] => tail,
_ => std::util::unreachable() _ => unreachable!()
}; };
a[0] = 0; //~ ERROR cannot assign to `a[]` because it is borrowed a[0] = 0; //~ ERROR cannot assign to `a[]` because it is borrowed
t[0]; t[0];

View File

@ -78,8 +78,6 @@
// check:$16 = -1 // check:$16 = -1
// debugger:continue // debugger:continue
use std::util;
fn main() { fn main() {
let x = 999; let x = 999;
@ -102,14 +100,14 @@ fn main() {
zzz(); zzz();
sentinel(); sentinel();
} else { } else {
util::unreachable(); unreachable!();
} }
zzz(); zzz();
sentinel(); sentinel();
if x > 1000 { if x > 1000 {
util::unreachable(); unreachable!();
} else { } else {
zzz(); zzz();
sentinel(); sentinel();

View File

@ -1,12 +1,12 @@
fn a() { fn a() {
let x = [1, 2, 3]; let x = [1, 2, 3];
match x { match x {
[1, 2, 4] => ::std::util::unreachable(), [1, 2, 4] => unreachable!(),
[0, 2, 3, .._] => ::std::util::unreachable(), [0, 2, 3, .._] => unreachable!(),
[0, .._, 3] => ::std::util::unreachable(), [0, .._, 3] => unreachable!(),
[0, .._] => ::std::util::unreachable(), [0, .._] => unreachable!(),
[1, 2, 3] => (), [1, 2, 3] => (),
[_, _, _] => ::std::util::unreachable(), [_, _, _] => unreachable!(),
} }
match x { match x {
[.._] => (), [.._] => (),

View File

@ -3,7 +3,7 @@ pub fn main() {
if !x.is_empty() { if !x.is_empty() {
let el = match x { let el = match x {
[1, ..ref tail] => &tail[0], [1, ..ref tail] => &tail[0],
_ => ::std::util::unreachable() _ => unreachable!()
}; };
printfln!("%d", *el); printfln!("%d", *el);
} }

View File

@ -17,19 +17,19 @@ pub fn main() {
match tail { match tail {
[Foo { _ }, _, Foo { _ }, .. _tail] => { [Foo { _ }, _, Foo { _ }, .. _tail] => {
::std::util::unreachable(); unreachable!();
} }
[Foo { string: ref a }, Foo { string: ref b }] => { [Foo { string: ref a }, Foo { string: ref b }] => {
assert_eq!("bar", a.slice(0, a.len())); assert_eq!("bar", a.slice(0, a.len()));
assert_eq!("baz", b.slice(0, b.len())); assert_eq!("baz", b.slice(0, b.len()));
} }
_ => { _ => {
::std::util::unreachable(); unreachable!();
} }
} }
} }
_ => { _ => {
::std::util::unreachable(); unreachable!();
} }
} }
} }