Skip to main content

ryo_analysis/check/
traits.rs

1//! LightCheck trait - Interface for lightweight graph-based checks.
2
3use super::result::CheckResult;
4
5/// Trait for lightweight graph-based validation.
6///
7/// This trait defines the interface for pre-mutation validation checks
8/// that can quickly detect common errors without running the full compiler.
9///
10/// # Implementors
11///
12/// - `GraphChecker`: Uses `CodeGraph`, `TypeFlowGraph`, and `SymbolRegistry`
13///
14/// # Usage
15///
16/// ```rust,ignore
17/// fn validate_mutation(checker: &impl LightCheck, target: &str) -> bool {
18///     if !checker.check_symbol_exists(target) {
19///         return false;
20///     }
21///     checker.check_derive_possible(target, "Default").is_ok()
22/// }
23/// ```
24///
25/// For borrow conflict detection, use `BorrowTrackerV2::conflicts()` directly.
26pub trait LightCheck {
27    /// Check if a symbol exists in the codebase.
28    ///
29    /// Searches both by full path (e.g., `my_crate::MyStruct`)
30    /// and by short name (e.g., `MyStruct`).
31    fn check_symbol_exists(&self, name: &str) -> bool;
32
33    /// Check if a type implements a trait.
34    ///
35    /// First checks standard library implementations (primitives, common types),
36    /// then searches the code graph for user-defined implementations.
37    fn check_trait_impl(&self, type_name: &str, trait_name: &str) -> bool;
38
39    /// Check if a derive macro can be applied to a type.
40    ///
41    /// Verifies that all fields of the type implement the required trait.
42    ///
43    /// # Returns
44    /// - `CheckResult::Ok` if derive is possible
45    /// - `CheckResult::Error` with details about missing implementations
46    fn check_derive_possible(&self, target: &str, trait_name: &str) -> CheckResult;
47
48    /// Pre-check before applying a mutation.
49    ///
50    /// This is called before mutation application to catch obvious errors
51    /// quickly. Default implementation returns Ok.
52    fn pre_check(&self, _mutation_type: &str, _target: &str) -> CheckResult {
53        CheckResult::Ok
54    }
55
56    /// Post-check after applying a mutation.
57    ///
58    /// This is called after mutation application to verify the result.
59    /// Default implementation returns Ok.
60    fn post_check(&self, _mutation_type: &str, _target: &str) -> CheckResult {
61        CheckResult::Ok
62    }
63}