Expand description
The intra-crate module dependency graph, built heuristically from use
statements — the lean, pure-Rust alternative to booting a semantic engine
(the same honesty class as crate::outline). It is the single-crate
analogue of crate::deps: it produces a [deps::Graph] whose nodes are
modules (crate-relative paths like domain::entity) and whose edges are
use dependencies, so the very same [deps::forbid_path] /
[deps::cycles] / [deps::layer_violations] assertions apply at module
granularity.
§What it sees, and what it does not
Nodes come from the source files walked (one module per file; lib.rs /
main.rs / mod.rs map to their containing module). Edges come from
use crate::…, use self::…, and use super::… statements — brace groups
are expanded, as aliases stripped, globs and self segments folded to the
enclosing module, and each path resolved to the longest known module
prefix. External imports (use std::…, use serde::…) are ignored.
Heuristic, not a parser: each use is read from the start of its line (how
rustfmt always writes them); a use reaching through a pub use re-export
resolves to the re-exporting module (not the origin); use inside macros or
#[cfg(...)]-disabled code, fully-qualified paths written inline without a
use, and the nesting of inline mod foo { … } blocks are not modelled —
the latter fold into their file’s module. When in doubt the graph
under-reports rather than inventing edges.
Functions§
- build_
graph - Build the module-use
Graphfrom(module_name, file_contents)pairs. Nodes are the module names; an edgeA -> Bmeans a file in moduleAhas auseresolving into moduleB. Self-edges are dropped. - check
- Run a
modsbuilt-in check: walk the crate source underroot/--base, build the module-use graph, and assert against it. Returns the probe outcome, a one-line reason, and the violation report. Spec / walk errors areProbeOutcome::Broken. - check_
grammar - The
modscheck’s introspected grammar (see [crate::deps::grammar]). - module_
name - The crate-relative module path for a source file, given its path relative
to the crate source root. The crate root file (
lib.rs/main.rs) and anymod.rsmap to their containing module; every other file adds its stem. - use_
targets - The intra-crate
usetargets in a source file: each returned string is a brace-expanded, alias-stripped path beginning withcrate,self, orsuper(external imports are dropped).