惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The Cloudflare Blog
U
Unit 42
D
Docker
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
Recent Announcements
Recent Announcements
GbyAI
GbyAI
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
V
Visual Studio Blog
I
InfoQ
Google DeepMind News
Google DeepMind News
小众软件
小众软件
L
LangChain Blog
C
Check Point Blog
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 【当耐特】
J
Java Code Geeks
罗磊的独立博客

Rust Blog

Security Advisory for Cargo (CVE-2026-5223) | Rust Blog Security Advisory for Cargo (CVE-2026-5222) | Rust Blog Project goals update — April 2026 (end of 2025H2) | Rust Blog Rust is participating in Outreachy | Rust Blog Raising the baseline for the `nvptx64-nvidia-cuda` target | Rust Blog Announcing Google Summer of Code 2026 selected projects | Rust Blog Announcing Rust 1.95.0 | Rust Blog docs.rs: building fewer targets by default | Rust Blog Changes to WebAssembly targets and handling undefined symbols | Rust Blog Announcing Rust 1.94.1 | Rust Blog Security advisory for Cargo | Rust Blog What we heard about Rust's challenges | Rust Blog Call for Testing: Build Dir Layout v2 | Rust Blog Announcing rustup 1.29.0 | Rust Blog Announcing Rust 1.94.0 | Rust Blog 2025 State of Rust Survey Results | Rust Blog Rust debugging survey 2026 | Rust Blog Update on the October 15, 2018 incident on crates.io Announcing Rust 1.29.2 Announcing Rust 1.29 Announcing Rust 1.28 What is Rust 2018? Announcing Rust 1.27.2 Announcing Rust 1.27.1 Security Advisory for rustdoc Announcing Rust 1.27 Announcing Rust 1.26.2 Announcing Rust 1.26.1 Rust turns three Announcing Rust 1.26
Source-based code coverage in nightly | Inside Rust Blog
Tyler Mandry on behalf of The Compiler Team · 2020-11-12 · via Rust Blog

Support has landed in the nightly compiler for source-based code coverage, and we want your help testing it!

What is source-based code coverage, exactly?

You may already be familiar with code coverage, which shows you which lines of code execute. Code coverage is usually applied to tests to find out which code is actually being tested and which code isn’t.

Nightly Rust already supports another kind of source code coverage, commonly called gcov, which relies on debug info to map from LLVM IR to lines of source code. Instrumentation is then added in the LLVM backend during code generation to count how many times each line is run.

However, since LLVM doesn’t know exactly how Rust code is structured, there’s a lot lost in the translation between Rust source and LLVM IR. Line-level granularity is sometimes too coarse, and debug info can be unreliable, especially when building in release mode. The result is coverage reports that only show an approximation of what code actually executed.

Source-based code coverage instrumentation is applied by the Rust compiler, not LLVM. This instrumentation is more precise because it's being done in MIR, which holds a mapping between the original Rust source code and the control-flow graph of the program.

That means things like short-circuited conditionals, closures, and match guards are all precisely counted. And since instrumentation counters are injected as regular MIR statements, the compiler can further optimize the program without affecting coverage results.

Comparison of gcov and source-based coverage results

Above: A comparison of the gcov (left) and source-based coverage (right) results. gcov highlights skipped lines, marked with #####, while source-based coverage highlights exact regions of code that were skipped. Note that on line 30, one boolean subexpression is short-circuited. This is surfaced by source-based coverage but not gcov.

What this means is that source-based code coverage is both efficient and accurate. LLVM’s existing coverage tools (llvm-profdata and llvm-cov) generate both coverage summaries and very fine-grained code regions, helping you find gaps in your testing coverage. What you do about that is up to you!

Trying it out

Work on the implementation began back in April, and many PRs later, it’s ready for you to try. All you need is a recent nightly and a tool to read the coverage reports.

Take a look at this guide to get started. If you spot any issues, please report them. It’s a huge help!

Finally, if you try it out and it works well, we’d also like to hear from you! Come by the Zulip stream for this change or comment on the feature request.

Acknowledgements

The implementation work was all done by Rich Kadel; thanks to him for all the amazing work he’s done. Thanks also to Wesley Wiser for helping with reviews, to Bob Wilson for lending his experience with LLVM's InstrProf coverage APIs, and to eddyb for their guidance in choosing a MIR-based approach.