use std::fmt;
use pedant_types::Capability;
use super::facts::IrSpan;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum DataFlowKind {
TaintFlow,
DeadStore,
DiscardedResult,
PartialErrorHandling,
RepeatedCall,
UnnecessaryClone,
AllocationInLoop,
RedundantCollect,
LockAcrossAwait,
InconsistentLockOrder,
ImmutableGrowable,
SwallowedOk,
UnobservedSpawn,
}
impl DataFlowKind {
pub fn code(self) -> &'static str {
match self {
Self::TaintFlow => "taint-flow",
Self::DeadStore => "dead-store",
Self::DiscardedResult => "discarded-result",
Self::PartialErrorHandling => "partial-error-handling",
Self::RepeatedCall => "repeated-call",
Self::UnnecessaryClone => "unnecessary-clone",
Self::AllocationInLoop => "allocation-in-loop",
Self::RedundantCollect => "redundant-collect",
Self::LockAcrossAwait => "lock-across-await",
Self::InconsistentLockOrder => "inconsistent-lock-order",
Self::ImmutableGrowable => "immutable-growable",
Self::SwallowedOk => "swallowed-ok",
Self::UnobservedSpawn => "unobserved-spawn",
}
}
}
impl fmt::Display for DataFlowKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.code())
}
}
#[derive(Debug, Clone)]
pub struct DataFlowFact {
pub kind: DataFlowKind,
pub source_capability: Option<Capability>,
pub source_span: IrSpan,
pub sink_capability: Option<Capability>,
pub sink_span: IrSpan,
pub call_chain: Box<[Box<str>]>,
pub message: Box<str>,
}