ryo-analysis 0.1.0

Code graph and discovery engine for the RYO project
Documentation
//! LightCheck trait - Interface for lightweight graph-based checks.

use super::result::CheckResult;

/// Trait for lightweight graph-based validation.
///
/// This trait defines the interface for pre-mutation validation checks
/// that can quickly detect common errors without running the full compiler.
///
/// # Implementors
///
/// - `GraphChecker`: Uses `CodeGraph`, `TypeFlowGraph`, and `SymbolRegistry`
///
/// # Usage
///
/// ```rust,ignore
/// fn validate_mutation(checker: &impl LightCheck, target: &str) -> bool {
///     if !checker.check_symbol_exists(target) {
///         return false;
///     }
///     checker.check_derive_possible(target, "Default").is_ok()
/// }
/// ```
///
/// For borrow conflict detection, use `BorrowTrackerV2::conflicts()` directly.
pub trait LightCheck {
    /// Check if a symbol exists in the codebase.
    ///
    /// Searches both by full path (e.g., `my_crate::MyStruct`)
    /// and by short name (e.g., `MyStruct`).
    fn check_symbol_exists(&self, name: &str) -> bool;

    /// Check if a type implements a trait.
    ///
    /// First checks standard library implementations (primitives, common types),
    /// then searches the code graph for user-defined implementations.
    fn check_trait_impl(&self, type_name: &str, trait_name: &str) -> bool;

    /// Check if a derive macro can be applied to a type.
    ///
    /// Verifies that all fields of the type implement the required trait.
    ///
    /// # Returns
    /// - `CheckResult::Ok` if derive is possible
    /// - `CheckResult::Error` with details about missing implementations
    fn check_derive_possible(&self, target: &str, trait_name: &str) -> CheckResult;

    /// Pre-check before applying a mutation.
    ///
    /// This is called before mutation application to catch obvious errors
    /// quickly. Default implementation returns Ok.
    fn pre_check(&self, _mutation_type: &str, _target: &str) -> CheckResult {
        CheckResult::Ok
    }

    /// Post-check after applying a mutation.
    ///
    /// This is called after mutation application to verify the result.
    /// Default implementation returns Ok.
    fn post_check(&self, _mutation_type: &str, _target: &str) -> CheckResult {
        CheckResult::Ok
    }
}