coverage: Don't show coverage for code paths that must panic/diverge by Zalathar · Pull Request #120013 · rust-lang/rust (original) (raw)
I thought of a case where this approach might give unexpected results:
std::process:exit
.
Thinking about this some more, I realised that from the instrumentor's perspective, there is no reliable difference between a peaceful process exit and a panic/unwind/abort.
For example, suppose we have a function like this:
fn maybe_exit(cond: bool) { if cond { std::process::exit(0); } }
When instrumenting callers of this function, the instrumentor is already committed to the assumption that it will return normally and not exit. If it does exit, any subsequent code in the caller is liable to give incorrect counts anyway.
So by assuming the absence of panics, we have already assumed the absence of peaceful termination as well. Therefore, the fact that this PR interacts poorly with std::process::exit
should not be considered a showstopper, because we have already committed to not properly instrumenting such code.