ErrorGuaranteed

The previous sections have been about the error message that a user of the compiler sees. But emitting an error can also have a second important side effect within the compiler source code: it generates an ErrorGuaranteed.

ErrorGuaranteed is a zero-sized type that is unconstructable outside of the rustc_errors crate. It is generated whenever an error is reported to the user, so that if your compiler code ever encounters a value of type ErrorGuaranteed, the compilation is statically guaranteed to fail. This is useful for avoiding unsoundness bugs because you can statically check that an error code path leads to a failure.

There are some important considerations about the usage of ErrorGuaranteed:

Thankfully, in most cases, it should be statically impossible to abuse ErrorGuaranteed.