Skip to content

Commit

Permalink
Rename info error fields
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaAmora committed Mar 7, 2024
1 parent 6375099 commit d522994
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ pub const ERR_INDENT_SIZE: usize = 2;
#[derive(Debug, Clone, Default)]
pub struct Info {
err_counter: usize,
errs: Vec<Error>,
errs_with_def: BTreeMap<Name, Vec<Error>>,
book_errs: Vec<Error>,
rule_errs: BTreeMap<Name, Vec<Error>>,
pub warns: Warnings,
}

impl Info {
pub fn error<E: Into<Error>>(&mut self, e: E) {
self.err_counter += 1;
self.errs.push(e.into())
self.book_errs.push(e.into())
}

pub fn def_error<E: Into<Error>>(&mut self, name: Name, e: E) {
self.err_counter += 1;
let entry = self.errs_with_def.entry(name).or_default();
let entry = self.rule_errs.entry(name).or_default();
entry.push(e.into());
}

Expand All @@ -52,7 +52,7 @@ impl Info {
}

pub fn has_errors(&self) -> bool {
!(self.errs.is_empty() && self.errs_with_def.is_empty())
!(self.book_errs.is_empty() && self.rule_errs.is_empty())
}

/// Resets the internal counter
Expand All @@ -73,9 +73,9 @@ impl Info {

pub fn display(&self, verbose: bool) -> impl Display + '_ {
DisplayFn(move |f| {
writeln!(f, "{}", self.errs.iter().map(|err| err.display(verbose)).join("\n"))?;
writeln!(f, "{}", self.book_errs.iter().map(|err| err.display(verbose)).join("\n"))?;

for (def_name, errs) in &self.errs_with_def {
for (def_name, errs) in &self.rule_errs {
in_definition(def_name, f)?;
for err in errs {
writeln!(f, "{:ERR_INDENT_SIZE$}{}", "", err.display(verbose))?;
Expand All @@ -99,7 +99,7 @@ impl Display for Info {

impl From<String> for Info {
fn from(value: String) -> Self {
Info { errs: vec![Error::Custom(value)], ..Default::default() }
Info { book_errs: vec![Error::Custom(value)], ..Default::default() }
}
}

Expand Down

0 comments on commit d522994

Please sign in to comment.