One advantage of using a strongly typed language like Rust is that some programmer errors are immediately detected at compile time and lead to a compilation failure.
For compiler-enforced properties like borrow checking, we trust the
rustc team to make sure that this actually happens via their magical compiler test harness. But for library-defined properties, and especially (but not only) when
unsafe code is involved, the library author is responsible for ensuring that the library's compile-time API preconditions are actually checked at compile time.
So, how does one go about actually testing this, beyond ocasionally checking that some code does not compile by hand?
I know that rustdoc has a
compile_fail attribute that can be applied to documentation examples, does it plug into a more general-purpose mechanism that one can use internally without writing down every "should-not-compile" example in the documentation?