# 1.0.0[−][src]Macro std::unreachable

    macro_rules! unreachable {
        (  ) => { ... };
        (
    $ msg : expr ) => { ... };
        ( $ msg : expr , ) => { ... };
        ( $ fmt : expr , $ ( $ arg : tt ) * ) => { ... };
    }

A utility macro for indicating unreachable code.

This is useful any time that the compiler can't determine that some code is unreachable. For example:

- Match arms with guard conditions.
- Loops that dynamically terminate.
- Iterators that dynamically terminate.

If the determination that the code is unreachable proves incorrect, the program immediately terminates with a `panic!`. The function `unreachable_unchecked`, which belongs to the `std::hint` module, informs the compiler to optimize the code out of the release version entirely.

# Panics

This will always `panic!`

# Examples

Match arms:

    fn foo(x: Option<i32>) {
        match x {
            Some(n) if n >= 0 => println!("Some(Non-negative)"),
            Some(n) if n <  0 => println!("Some(Negative)"),
            Some(_)           => unreachable!(), // compile error if commented out
            None              => println!("None")
        }
    }Run

Iterators:

    fn divide_by_three(x: u32) -> u32 { // one of the poorest implementations of x/3
        for i in 0.. {
            if 3*i < i { panic!("u32 overflow"); }
            if x < 3*i { return i-1; }
        }
        unreachable!();
    }Run

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)