use crate::diag::{Diag, Diagnostic, LintCode, Span};
use crate::eval::mag::TaintEvent;
#[derive(Debug, Default)]
pub struct LintSink {
lints: Vec<Diag>,
exactness_lost: bool,
}
impl LintSink {
pub fn new() -> Self {
Self::default()
}
pub fn lints(&self) -> &[Diag] {
&self.lints
}
pub fn into_lints(self) -> Vec<Diag> {
self.lints
}
pub fn extend(&mut self, other: &mut Self) {
self.lints.append(&mut other.lints);
self.exactness_lost |= other.exactness_lost;
}
pub fn record_mag_event(&mut self, event: TaintEvent, span: Span, message: impl Into<String>) {
match event {
TaintEvent::ExactnessLost => {
if !self.exactness_lost {
self.exactness_lost = true;
self.lints.push(Diag::new(Diagnostic::lint(
LintCode::ExactnessLost,
message,
span,
)));
}
}
TaintEvent::RationalOverflow => {
self.lints.push(Diag::new(Diagnostic::lint(
LintCode::RationalOverflow,
message,
span,
)));
}
}
}
pub fn push(&mut self, lint: Diag) {
if lint.diagnostic().code == LintCode::ExactnessLost.as_str() {
if self.exactness_lost {
return;
}
self.exactness_lost = true;
}
self.lints.push(lint);
}
}