rust-lang / rust-lang/rust-clippy

Lint idea: detect circular module dependencies

Open
#5,782 1 comment 27 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint E-hard
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

Forbids mutually recursive module dependencies within a crate.

Consider two modules, crate::foo and crate::bar. If foo uses bar, then bar must not use foo (and vice versa). At a high level, this enforces that the crate's internal dependency tree forms a DAG.

Categories (optional)
  • Kind: probably pedantic
What benefit of this lint over old code?
  • Keep a crate's internal dependency tree manageable
    • This helps in understanding the structure of an unfamiliar codebase
    • This can aid future refactors of a monolithic crate into smaller crates
  • Possibly speed up compilation by making it easier for rustc to internally parallelize builds of a single crate or divide a crate into isolated codegen units for incremental compilation

I stole the idea from tending, originally posted here. Further discussion in that thread

Prior art: eslint import/no-cycle

Drawbacks

Possibly too pedantic for some projects

Example

foo.rs

use crate::bar::bar;

struct Common {}

pub fn foo(common: &Common) {
    bar(common);
}

bar.rs

use crate::foo::Common;

pub fn bar(common: &Common) {}

Could be written as:

common.rs

struct Common {}

foo.rs

use crate::common::Common;
use crate::bar::bar;

pub fn foo(common: &Common) {
    bar(common);
}

bar.rs

use crate::common::Common;

pub fn bar(common: &Common) {}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the proposed examples and compare the idea with ESLint's import/no-cycle prior art and the linked tending discussion. Done means the lint detects mutually recursive module dependencies within a crate while allowing an internal dependency structure that forms a DAG.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.