rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.97k stars 12.69k forks source link

#[no_coverage] didn't exclude internal functions and closures inside a function #113564

Closed mhfan closed 1 month ago

mhfan commented 1 year ago

Thus, require "#[cfg_attr(coverage_nightly, no_coverage)]" prepend before each internal functions/closures for coverage exclusion, e.g.:

https://github.com/mhfan/inrust/blob/d4bd798028b9d06709b1c65ef92993af805ba4a4/src/calc24.rs#L737C1-L762C6

https://github.com/taiki-e/cargo-llvm-cov/issues/291

taiki-e commented 1 year ago

@rustbot label +A-code-coverage +requires-nightly

Zalathar commented 1 year ago

Yeah, the current implementation of #[no_coverage] is pretty crude, since it only applies to the item it's directly attached to.

From the instrumentation pass's point of view, every internal function/closure is treated as a completely separate function, and there's no logic to detect no-coverage attributes on enclosing items.

I imagine this would be relatively straightforward to fix, by scanning all enclosing functions for the attribute (instead of just checking the current function), though I'm currently not familiar enough with MIR APIs to do it myself.

Zalathar commented 4 months ago

I've filed #126625 to be the canonical version of this issue.

ranger-ross commented 1 month ago

@rustbot close

rustbot commented 1 month ago

Error: The feature close is not enabled in this repository. To enable it add its section in the triagebot.toml in the root of the repository.

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

ranger-ross commented 1 month ago

Oops, I thought I could close this.

I think we are good to close this now that #126625 has been closed