Expand description
§cargo-echoes
By chance two separate functions meet, and I am you and what I see is me.
cargo echoes finds duplicated Rust doctests, and optionally duplicated functions and code blocks, across a workspace or across every crate of a GitHub organization. The wiki explains each check, the options and the Action in depth.
§Usage
cargo install echoes
cargo echoes --functions --context-blocks
cargo echoes --organization --functions| 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 |
Options can also live in .echoes.toml at the workspace root, and cargo echoes --help lists them all. Leave out whole paths, such as benchmarks, with gitignore-style exclude globs or --exclude, and keep an intentional copy with a rust,echoes fence or a // echoes: allow line above the function. The wiki lists what counts as the same code.
--organization scans the default branch of every repository of a GitHub organization or user that the GH_TOKEN or GITHUB_TOKEN credential can read, private ones included, and compares functions across crates and modules. Without a name it scans the owner of the current repository, from GITHUB_REPOSITORY_OWNER or the origin remote. Repeat it to join several owners, and pass --repository OWNER/REPO once per repository to add repositories of any owner, alone or beside the organizations. Downloaded repositories never configure the scan or run code, so pass --config for options, and the exit status is 2 whenever a repository could not be analyzed, even with --no-fail.
§GitHub Action
on: pull_request
jobs:
echoes:
runs-on: ubuntu-26.04
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: LucaCappelletti94/cargo-echoes@v1
with:
pr-number: ${{ github.event.pull_request.number }}
functions: trueThe action reviews the pull request and suggests removing each copy it introduces, with links to report a wrong review and support echoes. On every new commit it dismisses its earlier requests for changes, updates its earlier comment-only summaries and resolves the threads of copies that are gone, which needs contents: write. action.yml lists every input, and these two workflows review pull requests from forks.
§Library
let report = echoes::Echoes::default()
.functions()
.context_blocks()
.run(".")
.unwrap();
println!("{}", echoes::human(&report, false));Use default-features = false, features = ["std"] to drop the CLI. Coding agents get the same guidance from the echoes skill.
npx skills add LucaCappelletti94/cargo-echoesModules§
- extract
- Doc comment walking and doctest block extraction.
Structs§
- Context
Group - Approximate lexical contexts sharing an exact canonical form.
- Context
Site - One approximate lexical context match at its original source range.
- Dependency
Candidate - An upstream lexical context matching selected local code.
- Dependency
Coverage - Coverage and failures of a requested dependency search.
- Dependency
Search - Parameters for dependency context discovery.
- DocTest
- A duplicated site, a doctest block or a function.
- Echoes
- Scan parameters. In
run, unset values fall back to.echoes.toml, then to defaults. - Existing
Issue - An existing tagged upstream extraction request.
- Group
- Duplicated sites sharing one canonical form.
- Organization
Coverage - Completeness of the accessible organization corpus.
- Organization
Package - A Cargo package in an organization snapshot.
- Organization
Report - Organization source provenance and analysis coverage.
- Organization
Repository - A repository and its pinned default-branch revision.
- Report
- Outcome of a scan.
- Reuse
Group - Dependency reuse alternatives for one selected local context.
- Reuse
Report - Grouped dependency findings and requested-analysis coverage.
- Source
File - One file of a target.
- Target
Scan - One resolved target.
Enums§
- Context
Access - Source-established accessibility of a lexical context.
- Context
Kind - The kind of lexical scope a context candidate covers.
- Context
Scope - A selection over the workspace context corpus.
- Error
- Failure of a scan.
- Kind
- What a group’s sites are.
- Owner
Error - Why the current repository’s GitHub owner could not be determined.
- Remedy
- What to do with the copies of a function group, the first matching row of the rule table winning.
- Reuse
Action - The reuse path suggested by source evidence.
Functions§
- annotations
- Render the report as GitHub workflow annotations, one per copy to remove plus one per approximate context site. They need no token, so a fork pull request still shows them anchored in the diff.
- exit_
code - Exit status for a finished scan.
- group
- Group doctests by canonical form, dropping allowed sites, blocks under
min_tokens, and groups underthreshold. - human
- Render the report for humans.
- json
- Render the report as JSON.
- repository_
owner - The GitHub owner of the repository at
dir, fromGITHUB_REPOSITORY_OWNERwhen set and non-empty, else from itsoriginremote.