13

Unreachable

Comments
  • 0
    unreachable
  • 0
    But why?
  • 2
    Have a ++ because Rust is my favorite language ❤️

    This is used for signalling of intent. When pattern matching, you may know that certain patterns will never happen. So then you plop in an unreachable.

    The compiler should optimize it so that it still does get checked, but only as the unhappy path. Then a panic happens.

    If you absolutely know for certain that it will never happen, then you can also use: https://doc.rust-lang.org/std/hint/...
    Now it will be Undefined Behavior to run that branch, but it can potentially be optimized harder.
  • 0
    Exclamation mark in function name.
    No.
  • 3
    @Ranchonyx it's not a function! 🙂

    The exclamation mark is used for macros to differentiate them. You never have to guess like you have to do in C and C++
  • 1
    @Geoxion Oh! The more you know I guess
  • 1
    @Ranchonyx Yeah, it's a macro that crashes the thread with a panic. It lets you mark a branch that should never be reachable unless you have a bug or invalid state somewhere. There's also "todo!()" which basically does the same but with a slightly different error message. It lets you check the rest of the code without the compiler whining about missing return values and shit.

    The compiler figured out this part was guaranteed to be always unreachable and marked the macro unreachable.
Add Comment