Skip to content

Commit

Permalink
Add an option to downgrade errors to warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Jul 4, 2024
1 parent 7be21f5 commit 32001c2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions cli/driver/src/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ impl From<ExtractionCallbacks> for hax_frontend_exporter_options::Options {
fn from(opts: ExtractionCallbacks) -> hax_frontend_exporter_options::Options {
hax_frontend_exporter_options::Options {
inline_macro_calls: opts.inline_macro_calls,
downgrade_errors: false,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions cli/options/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ impl From<Options> for hax_frontend_exporter_options::Options {
fn from(opts: Options) -> hax_frontend_exporter_options::Options {
hax_frontend_exporter_options::Options {
inline_macro_calls: opts.inline_macro_calls,
downgrade_errors: false,
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion frontend/exporter/options/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ impl Namespace {
}
}

#[derive(Debug, Clone)]
#[derive(Default, Debug, Clone)]
pub struct Options {
pub inline_macro_calls: Vec<Namespace>,
/// Whether to emit errors or downgrade them as warnings.
pub downgrade_errors: bool,
}
23 changes: 20 additions & 3 deletions frontend/exporter/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,27 @@ macro_rules! report {
};
}

macro_rules! error { ($($tt:tt)*) => {$crate::utils::report!(error, $($tt)*)} }
#[allow(unused_macros)]
macro_rules! fatal {
($s:ident $($tt:tt)*) => {
if $s.base().options.downgrade_errors {
// Report the error but don't tell rustc.
$crate::utils::report!(warn, $s $($tt)*);
panic!("Fatal error");
} else {
$crate::utils::report!(fatal, $s $($tt)*);
}
}
}
macro_rules! error {
($s:ident $($tt:tt)*) => {
if $s.base().options.downgrade_errors {
$crate::utils::report!(warn, $s $($tt)*);
} else {
$crate::utils::report!(error, $s $($tt)*);
}
}
}
macro_rules! warning { ($($tt:tt)*) => {$crate::utils::report!(warn, $($tt)*)} }
macro_rules! fatal { ($($tt:tt)*) => {$crate::utils::report!(fatal, $($tt)*)} }

pub(crate) use format_with_context;
pub(crate) use internal_helpers::_span_verb_base;
Expand Down

0 comments on commit 32001c2

Please sign in to comment.