use cairo_lang_utils::ordered_hash_set::OrderedHashSet;
use super::BorrowChecker;
use crate::diagnostic::LoweringDiagnosticKind::*;
use crate::VariableId;
#[derive(Clone, Default)]
pub struct Demand {
pub vars: OrderedHashSet<VariableId>,
}
impl Demand {
pub fn variables_used(&mut self, borrow_checker: &mut BorrowChecker<'_>, vars: &[VariableId]) {
for var in vars {
if !self.vars.insert(*var) {
let var = &borrow_checker.lowered.variables[*var];
if !var.duplicatable {
borrow_checker.diagnostics.report_by_location(var.location, VariableMoved);
}
}
}
}
pub fn variables_introduced(
&mut self,
borrow_checker: &mut BorrowChecker<'_>,
vars: &[VariableId],
) {
for var in vars {
if !self.vars.swap_remove(var) {
let var = &borrow_checker.lowered.variables[*var];
#[allow(clippy::overly_complex_bool_expr)]
if !var.droppable {
borrow_checker.diagnostics.report_by_location(var.location, VariableNotDropped);
}
}
}
}
}