Skip to content

Document and test all scopes where #[mutants::skip] applies#1

Closed
sandersaares wants to merge 1 commit into
exclude-re-attrfrom
unify-attr-scoping
Closed

Document and test all scopes where #[mutants::skip] applies#1
sandersaares wants to merge 1 commit into
exclude-re-attrfrom
unify-attr-scoping

Conversation

@sandersaares

Copy link
Copy Markdown
Owner

Stacked on top of sourcefrog#607 (�xclude-re-attr).#[mutants::skip] has always been honoured at every scope where the visitor checks attributes — not just on fn declarations. The book's Skipping functions with an attribute section implied otherwise, and explicit test coverage of the attribute only exercised top-level functions, impl methods, trait default methods, and modules (via testdata trees), leaving every other supported scope unexercised.

This PR locks in the existing behaviour and clarifies the docs. No production code changes.

Tests added

New unit tests under src/visit/test/ for every previously-uncovered scope:

  • #![mutants::skip] — file inner attribute
  • #[mutants::skip] impl Foo { ... } — on the impl block itself
  • #[mutants::skip] trait Foo { ... } — on the trait declaration itself
  • expression-level skip on call, method-call, match, struct literal, and unary expressions
  • #[cfg_attr(test, mutants::skip)] at non-fn scopes (impl, mod)

Skip on a binary expression is intentionally not tested: syn absorbs a leading attribute into the leftmost operand, so ExprBinary.attrs is unreachable from any current Rust syntax (same constraint that applies to mutants::exclude_re).

Tests follow the per-file layout already established by the exclude_re_expr_* modules.

Docs

book/src/attrs.md:

  • Rename heading from Skipping functions with an attribute to Skipping mutations with an attribute and reword functionsitems.
  • Tighten the second list item to specify the only two recognised forms (direct #[mutants::skip] or nested inside cfg_attr); drop the misleading avoid the dependency sentence.
  • Rewrite the inline Note to accurately describe the cfg-condition-not-evaluated behaviour rather than the previous looks for the sequence framing.
  • Tighten the parallel paragraph in the exclude_re section the same way.
  • Add a Scope subsection to the Skip section, mirroring the one for exclude_re.

`#[mutants::skip]` has always been honoured at every scope where the
visitor checks attributes — not just on `fn` declarations. The book's
"Skipping functions with an attribute" section, and the surrounding
explanatory text, implied otherwise; the only explicit test coverage of
the attribute was on top-level functions, impl methods, trait default
methods, and modules (via testdata trees), leaving every other supported
scope unexercised.

This commit clarifies the docs and locks in the behaviour with unit
tests for every previously-uncovered scope:

- file inner attribute `#![mutants::skip]`
- `#[mutants::skip] impl Foo { ... }` on the impl block itself
- `#[mutants::skip] trait Foo { ... }` on the trait declaration itself
- expression-level skip on call, method-call, match, struct literal,
  and unary expressions
- `#[cfg_attr(test, mutants::skip)]` at non-fn scopes (impl, mod)

Skip on a binary expression is intentionally not tested: syn absorbs
a leading attribute into the leftmost operand, so `ExprBinary.attrs`
is unreachable from any current Rust syntax (same constraint that
applies to `mutants::exclude_re`).

Tests follow the per-file layout already established by the
`exclude_re_expr_*` modules under `src/visit/test/`.

The book's Skip section is rewritten to drop the fn-only framing and
adds a Scope subsection mirroring the one for `exclude_re`.

No behaviour change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sandersaares

Copy link
Copy Markdown
Owner Author

Splitting this up: the exclude_re doc tightening goes into PR sourcefrog#607 (exclude-re-attr) directly; the mutants::skip docs + tests will go in a new independent PR based on main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant