pedant_types/finding.rs
1use std::sync::Arc;
2
3use serde::{Deserialize, Serialize};
4
5use crate::Capability;
6
7/// File, line, and column of a capability finding.
8#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Hash)]
9pub struct SourceLocation {
10 /// Absolute path; `Arc` because many findings share the same file.
11 pub file: Arc<str>,
12 /// 1-based line number.
13 pub line: usize,
14 /// 1-based column number.
15 pub column: usize,
16}
17
18/// Evidence that a specific capability is exercised at a source location.
19#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Hash)]
20pub struct CapabilityFinding {
21 /// Which capability this finding represents.
22 pub capability: Capability,
23 /// Source position of the triggering expression or import.
24 pub location: SourceLocation,
25 /// Snippet of the triggering code (e.g., the import path or literal).
26 pub evidence: Arc<str>,
27 /// `true` when the finding comes from a `build.rs` (compile-time execution).
28 #[serde(default, skip_serializing_if = "is_false")]
29 pub build_script: bool,
30 /// Reachability from a public entry point.
31 ///
32 /// `None` when DataFlow analysis is unavailable. `Some(true)` when
33 /// reachable, `Some(false)` when dead code.
34 #[serde(default, skip_serializing_if = "Option::is_none")]
35 pub reachable: Option<bool>,
36}
37
38fn is_false(v: &bool) -> bool {
39 !v
40}