find_dead_code

Function find_dead_code 

Source
pub fn find_dead_code(path: &str) -> Result<Vec<FunctionRef>>
Expand description

Find dead (unreachable) code in a project.

Identifies functions that are not reachable from any entry point. Entry points are detected heuristically (main functions, test functions, exported modules, etc.).

§Arguments

  • path - Root project directory

§Returns

A vector of FunctionRef for functions that appear to be unreachable.

§Examples

use go_brrr::find_dead_code;

let dead = find_dead_code("./project")?;
if dead.is_empty() {
    println!("No dead code detected!");
} else {
    println!("Potentially dead code ({} functions):", dead.len());
    for func in &dead {
        println!("  {}:{}", func.file, func.name);
    }
}

§Caveats

  • Dynamic dispatch (e.g., getattr, reflection) may cause false positives
  • Decorator-wrapped functions may not be detected as entry points
  • Test discovery patterns are language-specific

§Errors

Returns BrrrError if the project cannot be scanned.