Skip to main content

find_phantom_modules

Function find_phantom_modules 

Source
pub fn find_phantom_modules(
    project: &ProjectRoot,
    max_results: usize,
) -> Result<Vec<PhantomModuleEntry>>
Expand description

Finds Rust mod NAME; declarations whose NAME does not appear as a path segment anywhere else in the workspace.

Match strategy (v1, regex-only):

  1. Collect every mod NAME; declaration with its parent file and line.
  2. Build a set of referenced module names by scanning all Rust source for tokens that look like NAME::, ::NAME;, or ::NAME::.
  3. Any declared NAME not in the set is a phantom.

Tradeoffs:

  • Reports pub mod too — re-export patterns may keep them useful; visibility is reported so callers can filter.
  • Does not understand path aliases (use foo as bar;); we still catch the original name on either side of the alias.