[src]

std::macros::unreachable

macro_rules! unreachable(
    () => (fail!("internal error: entered unreachable code"))
)

A utility macro 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

struct Item { weight: uint }

fn choose_weighted_item(v: &[Item]) -> Item {
    assert!(!v.is_empty());
    let mut so_far = 0u;
    for item in v.iter() {
        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
    unreachable!();
}