Expand description
Structural Rust module resolution for the project graph (gh-2269).
Rust import edges cannot be derived from a use string alone: the same
module is reached through crate::, super::, self::, a workspace crate
name, a pub use re-export chain or a glob, and a module’s file depends on
foo.rs vs foo/mod.rs and #[path]. This resolver builds the module tree
of every Cargo target in the project (no compiler, no build scripts) and
resolves each use path and each fully qualified path in code to the file
that defines the named item:
- crate roots come from each
Cargo.toml([lib], bins, tests, examples, benches, build script), workspace crates are named by their library name with-mapped to_, renamed dependencies (package = "…") included; mod x;followsx.rs,x/mod.rsand#[path = "…"]; a#[cfg_attr(…, path = "…")]target is an additional file of the same module (the configuration is not evaluated, so every existing candidate is loaded and the module is their union); inlinemod x { … }blocks are modules of their own (sosuper::inside an inlinemod testsis the file’s module);pub usere-exports and globs are followed up to four hops;- strings and comments are skipped, so a module named only in a comment or a string is not a dependency.
Facade modules — crate roots and mod.rs files that declare child files —
never receive an import edge: almost every file reaches its imports through
them, and an edge there would make every impact the whole workspace. Their
mod declarations are still recorded as module edges.
Structs§
- Rust
Module Graph - Edges and coverage produced by
resolve_workspace.
Constants§
- IMPORT_
EDGE_ KIND - Graph edge kind of a resolved Rust use (
(from, to)inRustModuleGraph::imports). - IMPORT_
EDGE_ WEIGHT - Weight of an
IMPORT_EDGE_KINDedge in the project graph. - MODULE_
EDGE_ KIND - Graph edge kind of a
mod child;declaration ((parent, child)inRustModuleGraph::modules). - MODULE_
EDGE_ WEIGHT - Weight of a
MODULE_EDGE_KINDedge in the project graph. - UNKNOWN_
DEPENDENTS_ ADVICE - The advice that follows an unknown-dependents answer.
Functions§
- resolve_
workspace - Resolve the Rust module graph of every Cargo target below
root. - unresolved_
dependents_ reason - Why the dependents of a Rust file cannot be listed from the resolved
graph, or
Nonewhen they can.declared: some file declares it withmod(it has an incomingMODULE_EDGE_KINDedge);declares_children: it declares child files itself. Every impact answer for a.rsfile asks this before it may say that nothing depends on the file.