TL;DR

  • Cargo refuses to build two Rust crates that depend on each other ("cyclic package dependency"), but modules inside one crate can use each other freely.
  • In the median of 15 Rust repos with 1,000+ GitHub stars, 22.2% of production files sit in a circular import chain between files, against 9.2% across all 195 repos in the set.
  • In bevy, all 75 of those cycle groups stay inside a single crate, and cargo machete flagged 34 unused dependencies across 25 manifests in 4.6 seconds.
  • Numbers come from repowise's index of 195 public repos with 1,000+ GitHub stars (November 2026), plus fresh runs on bevy and ratatui.

Two crates that depend on each other will not build. Cargo stops before compiling anything:

error: cyclic package dependency: package `cart v0.1.0 (./split/cart)` depends on itself. Cycle: package `cart v0.1.0 (./split/cart)` ... which satisfies path dependency `cart` of package `pricing v0.1.0 (./split/pricing)` ... which satisfies path dependency `pricing` of package `cart v0.1.0 (./split/cart)` 

Put the same two files in one crate as modules and it compiles in under a second. That difference explains most of what I found when I looked at the file-level import graphs of 15 popular Rust repositories: a median of 22% of production files sit inside a circular import chain between files (a cycle of use statements), more than in Python, TypeScript or Go. In bevy, the repo I checked by hand, not one of those chains crosses a crate boundary.

How common are circular dependencies in Rust repos?

I looked at production source files (tests, examples, generated and vendored code excluded) in public repos with 1,000+ GitHub stars, as part of a larger set of 195 repos. Fifteen of them have Rust as their primary language. That is a small group, so read the Rust column as indicative.

A "cycle group" here is a set of two or more files that can all reach each other through imports. In Rust that means use crate::..., use super::... and friends between files of the same crate.

Median per repo Rust (15 repos) All 195 repos
Repos with at least one cycle group 14 of 15 (93%) 89%
Production files inside a cycle group 22.2% 9.2%
Cycle groups per repo 13 5
Files in the largest group 37 16
Files where one author made 80%+ of the commits 79% 60%
Dead-code findings per 100 files 5.0 16.2
Test files per production file 0.19 0.52

The Go post in this series compares cycle rates across languages. Here I want to go into why Rust looks like this, what the cycles actually are, and what the last two rows mean, because both are easy to misread.

Can Rust crates have circular dependencies?

Not between crates. Inside one crate, modules can import each other in a cycle.

The crate is Rust's compilation unit. rustc reads every module of a crate together and resolves names across the whole crate at once. Items can be declared in any order and in any file, and a use is a path into that crate-wide namespace. There is no load order like Python's import-time execution, so a.rs naming something in b.rs while b.rs names something in a.rs costs nothing.

Here is the smallest version. One crate, two modules that use each other:

// src/lib.rs pub mod cart; pub mod pricing; 
// src/cart.rs use crate::pricing::price_of; pub struct Item { pub sku: String, pub qty: u32, } pub fn total(items: &[Item]) -> u32 { items.iter().map(|i| price_of(i) * i.qty).sum() } 
// src/pricing.rs use crate::cart::Item; pub fn price_of(item: &Item) -> u32 { if item.sku.starts_with("gift-") { 0 } else { 500 } } 
$ cargo build Compiling shop v0.1.0 (./shop) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.43s 

Cargo works one level up. It compiles crates in dependency order, so the graph between packages has to be a DAG. Move cart and pricing into a workspace as two crates, give each a path dependency on the other, and you get the error at the top of this post. It fails at dependency resolution, before rustc runs at all.

The fix is the same one you would use in Go: move what both sides need into a crate that depends on neither. Here Item goes into its own item crate:

$ cargo build && cargo tree Compiling item v0.1.0 (./split-fixed/item) Compiling pricing v0.1.0 (./split-fixed/pricing) Compiling cart v0.1.0 (./split-fixed/cart) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.48s cart v0.1.0 (./split-fixed/cart) ├── item v0.1.0 (./split-fixed/item) └── pricing v0.1.0 (./split-fixed/pricing) └── item v0.1.0 (./split-fixed/item) ... 

So Rust has two rules at two levels. Inside a crate, anything goes. Between crates, strict layering. The 22% is the first rule showing up in the data.

What the cycles look like in a real repo: bevy

To check the numbers on a real codebase, I cloned bevy (shallow, commit 6a91165, 10 November 2026), indexed it, and ran a strongly connected components pass over the stored file import graph:

production .rs files: 1304 import edges: 10573 cycle groups: 75 files in a group: 725 (55.6%) largest groups: [142, 60, 37, 35, 31, 26, 25, 21, 20, 20] groups spanning more than one crate: 0 largest group by crate: [('crates/bevy_ecs', 142)] file names in largest group: [('mod.rs', 20), ('error.rs', 3), ('access.rs', 2), ('map_entities.rs', 2), ('system_param.rs', 2), ('builder.rs', 2)] most imported inside the largest group: 84 crates/bevy_ecs/src/world/mod.rs 68 crates/bevy_ecs/src/component/mod.rs 66 crates/bevy_ecs/src/entity/mod.rs 65 crates/bevy_ecs/src/change_detection/mod.rs 62 crates/bevy_ecs/src/schedule/mod.rs 58 crates/bevy_ecs/src/system/mod.rs 36 crates/bevy_ecs/src/world/unsafe_world_cell.rs 33 crates/bevy_ecs/src/query/mod.rs 

The same 75 groups and the same 142-file largest group showed up at bevy's last index on repowise.dev, so this is a stable property of the codebase.

The line that matters is groups spanning more than one crate: 0. Bevy is a workspace with 66 crates under crates/, and every one of its 75 cycle groups stays inside a single crate, exactly as Cargo requires. The biggest one is bevy_ecs, the ECS core, where nearly everything takes or returns a World, an Entity or a Component.

The files at the center are mod.rs files. This is the most common shape of a Rust module cycle, and you can see it in two lines of world/mod.rs and world/deferred_world.rs:

// crates/bevy_ecs/src/world/mod.rs mod deferred_world; // ... pub use deferred_world::DeferredWorld; 
// crates/bevy_ecs/src/world/deferred_world.rs use super::{unsafe_world_cell::UnsafeWorldCell, Mut, World}; 

The parent declares the child and re-exports its public type so callers can write bevy_ecs::world::DeferredWorld. The child reaches back up with use super:: for World, which is defined in the parent. That is a two-file cycle by construction, and it is the normal way to organize a Rust module. Repeat it for every child of world/, add the edges between world/, component/ and entity/ that any ECS needs, and you get one group of 142 files.

The newer layout without mod.rs (a layout.rs file next to a layout/ directory) has the same shape. In ratatui's ratatui-core, layout.rs declares mod rect; and layout/rect.rs starts with use crate::layout::{Margin, Offset, Position, Size};. (ratatui is the one Rust repo with no cycle group at its August index. A fresh index of today's code finds 8 groups, the largest 31 files inside ratatui-core, and none of them crosses a crate either.)

So when a tool tells you a Rust crate has a 100-file cycle, read it as "this crate is one tightly connected unit". That is a statement about where crate boundaries could go, not about anything being broken.

One note on the dataset: "primary language" is GitHub's label, and the graph covers every production file in the repo. A few of the Rust repos carry a TypeScript or Python layer too, and those files are counted with the rest.

Do Rust repos really have fewer tests?

The cohort median is 0.52 test files per production file. For Rust it is 0.19. That does not mean Rust projects test less. Rust unit tests usually live inside the source file they test, in a #[cfg(test)] mod tests block, so a file-level count classifies the file as production and never sees them.

I counted test functions (#[test], #[rstest], #[tokio::test]) in two repos. In bevy, 3,275 sit inside production files and 154 in separate test files (95% inline). In ratatui it is 1,317 against 135 (91%). Counting files makes Rust look thin on tests. Count test functions or run cargo llvm-cov instead.

The low dead-code number (files flagged as unreachable plus public items nothing imports) has a Rust-specific root too. A file only becomes part of a crate when some parent declares it with mod, so a file nothing points to is not compiled at all, and it tends to get noticed and deleted. Pooled across the 15 repos, 1,701 of the 2,208 findings are public items nothing inside the repo uses, which in a library is often the public API.

Unused Cargo dependencies: cargo machete on bevy

The dependency-level cousin of dead code is a crate listed in Cargo.toml that the code never uses. cargo-machete finds these without building anything. It reads the manifests and searches the source for each dependency's name, so it runs in seconds on a large workspace.

cargo install cargo-machete cargo machete 

On bevy (cargo-machete 0.9.2, 103 Cargo.toml files):

Analyzing dependencies of crates in this directory... cargo-machete found the following unused dependencies in this directory: benches -- .\benches\Cargo.toml: nonmax bevy_anti_alias -- .\crates\bevy_anti_alias\Cargo.toml: bevy_extract bevy_asset -- .\crates\bevy_asset\Cargo.toml: either ... bevy_mesh -- .\crates\bevy_mesh\Cargo.toml: glam bevy_platform -- .\crates\bevy_platform\Cargo.toml: critical-section ... bevy_render -- .\crates\bevy_render\Cargo.toml: derive_more downcast-rs profiling ... If you believe cargo-machete has detected an unused dependency incorrectly, you can add the dependency to the list of dependencies to ignore in the `[package.metadata.cargo-machete]` section of the appropriate Cargo.toml. ... Done! real 0m4.591s 

34 dependencies across 25 manifests in 4.6 seconds. Each line is a lead to check. Several of the ones I checked exist only to switch on a feature: bevy_mesh has morph = ["glam/encase-013"], bevy_platform forwards critical-section features, and bevy_render pulls in profiling behind its trace feature. None of those names needs to appear in the source, so a grep-based tool cannot see them. Mark them in [package.metadata.cargo-machete] ignored = [...], and for the rest, remove the line and build.

For more precise answers at the cost of a build, cargo-udeps asks the compiler which crates each target used (it needs nightly and compiles the workspace), and rustc's built-in unused_crate_dependencies lint turns on with [lints.rust] unused_crate_dependencies = "warn" in Cargo.toml. Machete fits in CI because it is fast. The other two are better run once in a while.

One main author on 79% of files

The ownership number is the one I find more interesting. In the median Rust repo in the set, one person made at least 80% of the commits to 79% of the production files. Across all 195 repos the median is 60% (the bus factor post in this series has the per-language table).

Part of it is age and team size. Several of the Rust repos in the set are young projects with a handful of contributors. The median Rust repo has 38 contributors in its indexed history, against 59 across all 195. A two-year-old project built by three people will have one main author per file almost everywhere, and that is fine.

The counterexample is bevy. At its last index on repowise.dev, 168 of its 1,262 production files (13%) had one main author. With 1,670 contributors in its history, knowledge of most files is spread across several people.

To measure this on your own repo, this script makes one pass over git log instead of running git shortlog per file, so it is quick even on a large history. It counts, for every current .rs source file, how many of its commits came from its most frequent author:

# bf1.sh: share of .rs source files where one author made 80%+ of the commits awk 'NR == FNR { live[$0] = 1; next } /^@/ { a = substr($0, 2); next } ($0 in live) { n[$0]++; k = $0 SUBSEP a; c[k]++; if (c[k] > top[$0]) top[$0] = c[k] } END { for (f in n) { t++; if (top[f] >= 0.8 * n[f]) b++ } printf "%d of %d files: one author made 80%%+ of the commits (%.0f%%)\n", b, t, 100 * b / t }' \ <(git ls-files '*.rs' | grep -vE '(^|/)(tests|examples|benches)/') \ <(git log --no-merges --format='@%aE' --name-only "$@" -- '*.rs') 

Run it at the root of a full clone. Extra arguments go to git log. On ratatui (full clone, 2b7b78e, 2,456 commits):

$ bash bf1.sh 26 of 127 files: one author made 80%+ of the commits (20%) $ bash bf1.sh --since="1 year ago" 43 of 92 files: one author made 80%+ of the commits (47%) 

A few notes on reading it. %aE respects .mailmap, so add one if people commit from several addresses. The script does not follow renames, so a file that moved into a new crate starts with a fresh history. And the time window changes the answer a lot: over the last year, the share of single-author files more than doubles, because recent work on any given file tends to come from fewer people. For which of those files actually matter (the ones still changing while their main author has gone quiet), the guide to measuring bus factor from git covers the method and what to do about them.

What I would do with this in a Rust codebase

Leave module cycles alone by default. A mod.rs that re-exports its children while the children use super:: is idiomatic Rust. Breaking it buys nothing.

Split a crate when you want a boundary the compiler enforces. The real reasons are build time (Cargo compiles independent crates in parallel and only rebuilds what changed), a piece of code other projects want to depend on alone, or a layer you want to stop people from reaching around. A big cycle group is a useful map for that decision. Files that sit outside the group, and that the group only imports, are the easy candidates for a lower crate. Files deep inside it will drag half the crate with them.

Use pub(crate) before you split. If the goal is "nothing outside this crate should call this", pub(crate) gives you that today with no new manifest. Bevy's world/mod.rs does exactly this with pub(crate) mod command_queue;. Reach for a new crate when you need the boundary inside the crate too.

Give the workspace a clear bottom layer. Workspaces that stay easy to change usually have a small set of leaf crates (types, errors, platform shims) that depend on nothing else in the workspace, with everything else stacked on top. In bevy, bevy_platform has no bevy dependencies at all and bevy_utils builds only on it. When you hit the cyclic package dependency error, the shared piece usually belongs in that layer, same as the item crate above.

Put the shared types in one place, not in a common crate that grows forever. The leaf crate trick works because the leaf stays small. If it becomes the place where everything goes, every crate rebuilds whenever it changes.

To see how bevy's crates and modules layer on top of each other, the bevy architecture view shows the dependency graph and its layers.

If you have split a large Rust crate into a workspace, which piece did you pull out first, and did the compile time win justify it?

How I ran this

The cohort is 195 of the most-starred public repositories indexed on repowise (1,000+ GitHub stars each, 253,688 production source files, November 2026). The Rust rows are the 15 repos whose GitHub primary language is Rust, each measured at its own latest index between July and November 2026. Cycle groups are strongly connected components of the file import graph among production files. Bus factor 1 means one author made at least 80% of a file's commits in the indexed history. Unreachable findings come from repowise's dead-code analysis.

The bevy check was repowise init --yes --no-prose --no-editor-setup on a shallow clone at 6a91165, then an SCC pass over the stored graph restricted to production .rs files. The ratatui runs used a full clone at 2b7b78e. The Cargo demos were built with cargo 1.99.0 and rustc 1.99.0, and cargo-machete was version 0.9.2.

FAQ

How do you fix a circular dependency between Rust crates?
Move whatever both crates need (usually shared types or errors) into a new crate that depends on neither, and have both depend on it. In the example above, Item moved into an item crate and the workspace built.

What does cargo machete do?
cargo-machete lists dependencies in Cargo.toml files that the source never seems to use. It searches the source for each dependency's name without building, so it is fast (4.6 seconds on bevy), but it misses dependencies that exist only to turn on a feature.

Are circular imports between modules a problem in Rust?
Usually not. rustc compiles a whole crate at once, so a mod.rs that re-exports its children while the children use super:: is normal Rust. A large cycle group is a hint about where a crate boundary could go.