Skip to content
LucaCappelletti94 edited this page Oct 21, 2026 · 1 revision

The local checks group sites with equal canonical forms and report groups with at least --threshold sites, 2 by default. Optional Dependency reuse matches selected contexts against indexed workspace and dependency code.

Check Enable Default minimum size Set the size
Doctests On by default 0 tokens --min-tokens
Functions --functions 30 weighted body tokens --fn-min-tokens
Contexts --context-blocks 30 canonical weighted tokens --context-min-tokens

Size floors are inclusive and independent of each other. For functions and contexts a path, a lifetime or a multi-character operator weighs one token, and commas and brackets weigh nothing, so long paths do not inflate small functions.

Doctests

Every doctest in the scanned targets is compared with every other one. Library doctests are scanned by default, and --all-targets adds binaries and examples. A block that several items share counts once.

Each group names a copy to keep. A copy whose code names its own item comes first, so the example on Vec::push that calls push wins over a copy elsewhere. File and line order break ties. The other copies can always go.

Functions

Functions compare within their own module, across every target and cfg variant. An Organization search compares them across crates and modules instead. Test markers, #[should_panic] and #[ignore] keep otherwise identical tests apart.

Comparisons use the module's original files, its imports and each function's enclosing owner. Two calls to different helpers that share a name stay different. Copies in different impl blocks match up to their owner and its generic parameters, while two methods of one owner that use different parameters stay apart.

Discovery follows available module files selected by cfg_attr(..., path = ...), including configurations other than the doctest model. Each file carries its linking condition into the function remedy comparison. An unconditional path shadows later providers, whose files stay out of default local checks. Doctests still follow the doctest configuration.

A function group names a copy to keep in the same way as a doctest group, and it carries a remedy. The first row that applies wins.

Remedy When What to do
generic-or-macro Methods on different self types Share one body through a generic or a macro
helper-or-macro A trait or an exported symbol needs each copy Keep the signatures and move the body into a helper or a macro
merge-cfg Free functions or inherent methods differ only by cfg Write one function that covers both cfg cases
delete Anything else Delete all copies but the first, or point their callers at it

Only free functions and inherent methods receive deletion suggestions. Public library API, exported symbols and copies with different cfg or self types need a refactor instead.

Contexts

The context check compares whole function bodies, explicit blocks, complete match arms and closures. Each one is normalized independently, and arm patterns, guards and closure inputs count towards the size.

Context matches are exact on the canonical form, like the other checks. Code around a fragment can still give it another meaning, so the report labels context groups approximate and never names a copy to keep or suggests a deletion. The GitHub Action can post them as neutral comments without removal suggestions. Dependency reuse findings have separate actions and review guidance, described in Dependency reuse.

When a larger group contains every site of a smaller one, only the larger group is reported. Each site carries a half-open source range with 1-based lines and 1-based byte columns, counted in the original file bytes, including any BOM or shebang.

cargo echoes --context-blocks --context-min-tokens 30

--context-select chooses the local contexts and --context-search chooses the workspace comparison corpus. Both can select a workspace, crate, file or module. Configuration lists their syntax, and Performance explains the cost of building the context index.

Clone this wiki locally