xbp-analysis 10.57.0

Language-agnostic static analysis (error-handling / Aspirator-style) for XBP
Documentation
use super::{base_caps, concepts_of, finding_from_concept};
use crate::domain::concepts::ConceptKind;
use crate::domain::model::LanguageModel;
use crate::domain::rule::{Rule, RuleMeta};
use crate::domain::types::{Confidence, Finding, Severity};
use std::sync::OnceLock;

#[derive(Default)]
pub struct IgnoredFailureRule;

impl Rule for IgnoredFailureRule {
    fn meta(&self) -> &RuleMeta {
        static META: OnceLock<RuleMeta> = OnceLock::new();
        META.get_or_init(|| RuleMeta {
            id: "ignored-failure".into(),
            name: "Ignored failure".into(),
            description: "A fallible operation's error is discarded without handling.".into(),
            default_severity: Severity::High,
            required_capabilities: base_caps(),
            autofix_safe: false,
        })
    }

    fn evaluate(&self, model: &LanguageModel) -> Vec<Finding> {
        concepts_of(model, ConceptKind::IgnoredFailure)
            .map(|(lang, c)| {
                finding_from_concept(
                    &self.meta().id,
                    lang,
                    c,
                    Severity::High,
                    Confidence::High,
                    "Fallible result is ignored; failure becomes silent success.",
                    "Upstream errors are dropped; callers assume success and corrupt state.",
                    "Propagate with ? / map_err, or match and handle both arms explicitly.",
                )
            })
            .collect()
    }
}