ArenaAllocator with StringHashMap, panic or segfault

There can be cases where you know that an error is never going to happen, but the compiler doesn’t know that, in those cases it is a valid use. Here is an example:

// has error signature because that signature is needed for a function pointer somewhere
fn neverErrorGetVal() error{OutOfMemory}!u32 { 
    return 5;
}
fn use() void {
    const val = neverErrorGetVal() catch unreachable; // here the programmer knows that the catch is actually impossible
    ...
}

The example is a bit contrived but similar examples actually exist in real code.

2 Likes