Rust Code Analysis
Structural analysis of Rust crates, workspace dependencies, and systems-level architectures
What Axiom Refract Analyzes in Rust
Crate and Module Tree Resolution
Resolves Rust module declarations (mod), use statements, and re-exports (pub use) across the module tree. Maps dependencies between crates in Cargo workspaces and across external crate boundaries.
Trait Implementation Graph
Maps trait definitions, implementations, and blanket implementations. Identifies where trait-based polymorphism creates structural coupling between crates that may not be obvious from import analysis alone.
Macro Expansion Awareness
Detects declarative (macro_rules!) and procedural macro usage. While macro expansion is not performed, the dependency on macro-defining crates and the structural patterns created by common macros (derive, serde, tokio) are tracked.
Unsafe Block Mapping
Identifies unsafe blocks and functions throughout the codebase. Maps the structural relationship between unsafe code and its callers to assess the blast radius of unsafe sections.
Feature Flag Dependency Analysis
Parses Cargo.toml feature definitions and conditional compilation attributes. Maps how feature flags alter the dependency graph and identifies features that significantly change the architectural structure.
How It Works
Rust is parsed using a hand-hardened Tree-sitter grammar supporting Rust 2021 edition syntax, including const generics, generic associated types (GATs), let-else, async traits, and return position impl Trait in traits. The parser resolves the module tree from mod declarations and file system structure, handles path attribute overrides, and maps cross-crate dependencies from Cargo.toml manifests. Workspace member relationships in Cargo workspaces are resolved for multi-crate dependency mapping.
Common Findings in Rust Codebases
Crate Boundary Coupling
Rust workspaces can develop tight coupling between crates that should be independently compilable. Axiom identifies inter-crate dependencies that violate intended architectural boundaries.
Unsafe Code Concentration
Unsafe code should be isolated in dedicated modules with safe wrappers. Axiom identifies codebases where unsafe blocks are scattered across many modules, increasing the verification burden.
Type Complexity Accumulation
Rust's type system enables deeply nested generic types that increase cognitive complexity. Axiom identifies type definitions with high nesting depth and wide generic parameter lists.
Dead Feature Flags
Cargo features that are defined but never enabled in the workspace default or by any dependent create dead conditional compilation paths. Axiom identifies unused features and the code they gate.
Polyglot Support
Rust is one of 145+ languages Axiom Refract supports through Tree-sitter AST parsing. Rust analysis covers Cargo.toml (including workspace manifests), Cargo.lock, build.rs scripts, and .cargo/config.toml settings. Crate features, target-specific dependencies, and platform-conditional compilation are detected and annotated in the dependency graph. Your entire codebase is analyzed in a single scan — regardless of how many languages it contains.