rust-lang / rust-lang/rust

code coverage reporting for `let-else` interacts poorly with rustfmt

Open
#143,149 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-code-coverage C-bug F-let_else T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

 let (m_original, []) = slice::as_chunks::<_, 8>(m.limbs()) else {
     return Err(LimbSliceError::len_mismatch(LenMismatchError::new(8)));
}

In my test suite, the positive if case is covered, but the else is never covered.

I expected to see this happen:

Code coverage tools should clearly report that let (m_original, []) = slice::as_chunks::<_, 8>(m.limbs()) is fully covered and should clearly report that the entire else case is not covered.

Instead, this happened:

Code coverage reports that let (m_original, []) = slice::as_chunks::<_, 8>(m.limbs()) else { is partially covered and that the rest of the else is uncovered:

Image

This is really unfortunate as it leads to confusion about whether part of the positive case is uncovered.

Meta

rustc +nightly --version --verbose:

rustc 1.90.0-nightly (706f244db 2025-06-23)
binary: rustc
commit-hash: 706f244db581212cabf2e619e0113d70999b2bbe
commit-date: 2025-06-23
host: aarch64-apple-darwin
release: 1.90.0-nightly
LLVM version: 20.1.7

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided let-else example with the referenced nightly rustc and rustfmt, then inspect how coverage is reported for the positive pattern and else block. Done means the positive case is clearly reported as fully covered while the entire else case is clearly reported as uncovered.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.