Skip to content

coverage: Treat #[automatically_derived] as #[coverage(off)] #144560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 29, 2025

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented Jul 28, 2025

One of the contributing factors behind #141577 (comment) was the presence of derive-macro-generated code containing nested closures.

Coverage instrumentation already has a heuristic for skipping code marked with #[automatically_derived] (#120185), because derived code is usually not worth instrumenting, and also has a tendency to trigger vexing edge-case bugs in coverage instrumentation or coverage codegen.

However, the existing heuristic only applied to the associated items directly within an auto-derived impl block, and had no effect on closures or nested items within those associated items.

This PR therefore extends the search for #[coverage(..)] attributes to also treat #[automatically_derived] as an implied #[coverage(off)] for the purposes of coverage instrumentation.


This change doesn’t rule out an entire category of bugs, because it only affects code that actually uses the auto-derived attribute. But it should reduce the overall chance of edge-case macro span bugs being observed in the wild.

@Zalathar Zalathar added the A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) label Jul 28, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 28, 2025

r? @SparrowLii

rustbot has assigned @SparrowLii.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 28, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 28, 2025

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

Some changes occurred in compiler/rustc_attr_data_structures

cc @jdonszelmann

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@Zalathar
Copy link
Contributor Author

I have also taken this opportunity to rename some of the coverage-attribute data structures introduced by #143891.

@compiler-errors
Copy link
Member

It would be nice to include this nuance somewhere. Ideally we'd have some documentation for when an item is instrumented that it would be easy to add this to, but that probably doesn't exist yet.

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jul 28, 2025

📌 Commit 019be9e has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 28, 2025
@bors
Copy link
Collaborator

bors commented Jul 28, 2025

☔ The latest upstream changes (presumably #144377) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 28, 2025
@Zalathar
Copy link
Contributor Author

Rebased to fix trivial conflict.

@bors r=compiler-errors

@bors
Copy link
Collaborator

bors commented Jul 29, 2025

📌 Commit 682f744 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 29, 2025
@bors
Copy link
Collaborator

bors commented Jul 29, 2025

⌛ Testing commit 682f744 with merge 3f761e5...

bors added a commit that referenced this pull request Jul 29, 2025
coverage: Treat `#[automatically_derived]` as `#[coverage(off)]`

One of the contributing factors behind #141577 (comment) was the presence of derive-macro-generated code containing nested closures.

Coverage instrumentation already has a heuristic for skipping code marked with `#[automatically_derived]` (#120185), because derived code is usually not worth instrumenting, and also has a tendency to trigger vexing edge-case bugs in coverage instrumentation or coverage codegen.

However, the existing heuristic only applied to the associated items directly within an auto-derived impl block, and had no effect on closures or nested items within those associated items.

This PR therefore extends the search for `#[coverage(..)]` attributes to also treat `#[automatically_derived]` as an implied `#[coverage(off)]` for the purposes of coverage instrumentation.

---

This change doesn’t rule out an entire category of bugs, because it only affects code that actually uses the auto-derived attribute. But it should reduce the overall chance of edge-case macro span bugs being observed in the wild.
bors added a commit that referenced this pull request Jul 29, 2025
coverage: Treat `#[automatically_derived]` as `#[coverage(off)]`

One of the contributing factors behind #141577 (comment) was the presence of derive-macro-generated code containing nested closures.

Coverage instrumentation already has a heuristic for skipping code marked with `#[automatically_derived]` (#120185), because derived code is usually not worth instrumenting, and also has a tendency to trigger vexing edge-case bugs in coverage instrumentation or coverage codegen.

However, the existing heuristic only applied to the associated items directly within an auto-derived impl block, and had no effect on closures or nested items within those associated items.

This PR therefore extends the search for `#[coverage(..)]` attributes to also treat `#[automatically_derived]` as an implied `#[coverage(off)]` for the purposes of coverage instrumentation.

---

This change doesn’t rule out an entire category of bugs, because it only affects code that actually uses the auto-derived attribute. But it should reduce the overall chance of edge-case macro span bugs being observed in the wild.
@bors
Copy link
Collaborator

bors commented Jul 29, 2025

⌛ Testing commit 682f744 with merge 916b023...

@Zalathar
Copy link
Contributor Author

Yielding to rollup:

@bors retry

bors added a commit that referenced this pull request Jul 29, 2025
Rollup of 6 pull requests

Successful merges:

 - #144560 (coverage: Treat `#[automatically_derived]` as `#[coverage(off)]`)
 - #144566 (Simplify `align_of_val::<[T]>(…)` → `align_of::<T>()`)
 - #144587 (expand: Micro-optimize prelude injection)
 - #144589 (Account for `.yield` in illegal postfix operator message)
 - #144615 (Make resolve_fn_signature responsible for its own rib.)
 - #144634 (Fix typo in `DropGuard` doc)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit f837028 into rust-lang:master Jul 29, 2025
10 of 11 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 29, 2025
rust-timer added a commit that referenced this pull request Jul 29, 2025
Rollup merge of #144560 - Zalathar:auto-derived, r=compiler-errors

coverage: Treat `#[automatically_derived]` as `#[coverage(off)]`

One of the contributing factors behind #141577 (comment) was the presence of derive-macro-generated code containing nested closures.

Coverage instrumentation already has a heuristic for skipping code marked with `#[automatically_derived]` (#120185), because derived code is usually not worth instrumenting, and also has a tendency to trigger vexing edge-case bugs in coverage instrumentation or coverage codegen.

However, the existing heuristic only applied to the associated items directly within an auto-derived impl block, and had no effect on closures or nested items within those associated items.

This PR therefore extends the search for `#[coverage(..)]` attributes to also treat `#[automatically_derived]` as an implied `#[coverage(off)]` for the purposes of coverage instrumentation.

---

This change doesn’t rule out an entire category of bugs, because it only affects code that actually uses the auto-derived attribute. But it should reduce the overall chance of edge-case macro span bugs being observed in the wild.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants