Skip to content

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

Merged
sourcefrog merged 1 commit into
sourcefrog:mainfrom
sandersaares:mutants-skip-docs-and-tests
May 27, 2026
Merged

Document and test all scopes where #[mutants::skip] applies#617
sourcefrog merged 1 commit into
sourcefrog:mainfrom
sandersaares:mutants-skip-docs-and-tests

Conversation

@sandersaares
Copy link
Copy Markdown
Contributor

@sandersaares sandersaares commented May 27, 2026

#[mutants::skip] is 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 current behaviour and clarifies the docs. No production code changes — only documentation and added tests.

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.

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 (the cfg_attr(test, ...) form still needs the crate as a dev-dependency, since the attr expands under cfg(test)).
  • Rewrite the inline Note to accurately describe the cfg-condition-not-evaluated behaviour rather than the previous looks for the sequence framing.
  • Add a Scope subsection listing every supported placement.

`#[mutants::skip]` is 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`).

The book's Skip section is rewritten to drop the fn-only framing and
adds a Scope subsection listing every supported placement.

No behaviour change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Documentation and test-only PR that pins down the existing behavior of #[mutants::skip]: the attribute is honoured by the visitor at every scope where attributes are inspected, not only on fn items. The book chapter is rewritten to reflect this, and per-scope unit tests are added under src/visit/test/ for previously-uncovered scopes.

Changes:

  • Rewrite book/src/attrs.md to talk about "items" instead of "functions", clarify the two recognised forms (direct and nested in cfg_attr), correct the note about cfg_attr (condition is not evaluated), and add a "Scope" subsection enumerating supported placements.
  • Add nine new unit-test files (file inner attr, impl block, trait block, call/method-call/match/struct/unary expression attrs, and cfg_attr(...) on impl block and module) wired into the existing mod test in src/visit.rs.
  • Add a NEWS entry noting that only docs and tests changed.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
book/src/attrs.md Rewrites title/wording from functions to items, fixes inaccurate note about cfg_attr evaluation, adds Scope section listing all supported placements.
NEWS.md Adds an unreleased entry describing the doc clarification.
src/visit.rs Declares nine new submodules under the existing mod test to host the new unit tests.
src/visit/test/skip_attr_file.rs Asserts #![mutants::skip] as file inner attribute suppresses all mutants.
src/visit/test/skip_attr_impl.rs Asserts #[mutants::skip] on an impl block suppresses every method.
src/visit/test/skip_attr_trait.rs Asserts #[mutants::skip] on a trait declaration suppresses default-method mutants.
src/visit/test/skip_attr_expr_call.rs Asserts the attribute on a call expression suppresses nested arg mutants, sibling call unaffected.
src/visit/test/skip_attr_expr_method_call.rs Same as above for method-call expressions.
src/visit/test/skip_attr_expr_match.rs Asserts the attribute on a match suppresses both arm-deletion and guard-replacement mutants.
src/visit/test/skip_attr_expr_struct.rs Asserts the attribute on a struct literal suppresses field-deletion mutants.
src/visit/test/skip_attr_expr_unary.rs Asserts the attribute on a unary expression suppresses only that specific delete ! mutant.
src/visit/test/skip_attr_cfg_attr.rs Asserts #[cfg_attr(test, mutants::skip)] is honoured at non-fn scopes (impl block and mod).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Owner

@sourcefrog sourcefrog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good.

@sourcefrog sourcefrog merged commit c527008 into sourcefrog:main May 27, 2026
2 checks passed
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.

3 participants