Stop compilation if macro expansion failed
This commit is contained in:
parent
a955f1cd09
commit
96340f6714
5 changed files with 17 additions and 4 deletions
|
|
@ -1224,6 +1224,7 @@ pub struct ExtCtxt<'a> {
|
|||
pub(super) expanded_inert_attrs: MarkedAttrs,
|
||||
/// `-Zmacro-stats` data.
|
||||
pub macro_stats: FxHashMap<(Symbol, MacroKind), MacroStat>,
|
||||
pub nb_macro_errors: usize,
|
||||
}
|
||||
|
||||
impl<'a> ExtCtxt<'a> {
|
||||
|
|
@ -1254,6 +1255,7 @@ impl<'a> ExtCtxt<'a> {
|
|||
expanded_inert_attrs: MarkedAttrs::new(),
|
||||
buffered_early_lint: vec![],
|
||||
macro_stats: Default::default(),
|
||||
nb_macro_errors: 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1315,6 +1317,12 @@ impl<'a> ExtCtxt<'a> {
|
|||
self.current_expansion.id.expansion_cause()
|
||||
}
|
||||
|
||||
/// This method increases the internal macro errors count and then call `trace_macros_diag`.
|
||||
pub fn macro_error_and_trace_macros_diag(&mut self) {
|
||||
self.nb_macro_errors += 1;
|
||||
self.trace_macros_diag();
|
||||
}
|
||||
|
||||
pub fn trace_macros_diag(&mut self) {
|
||||
for (span, notes) in self.expansions.iter() {
|
||||
let mut db = self.dcx().create_note(errors::TraceMacro { span: *span });
|
||||
|
|
|
|||
|
|
@ -693,7 +693,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||
crate_name: self.cx.ecfg.crate_name,
|
||||
});
|
||||
|
||||
self.cx.trace_macros_diag();
|
||||
self.cx.macro_error_and_trace_macros_diag();
|
||||
guar
|
||||
}
|
||||
|
||||
|
|
@ -707,7 +707,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||
) -> ErrorGuaranteed {
|
||||
let guar =
|
||||
self.cx.dcx().emit_err(WrongFragmentKind { span, kind: kind.name(), name: &mac.path });
|
||||
self.cx.trace_macros_diag();
|
||||
self.cx.macro_error_and_trace_macros_diag();
|
||||
guar
|
||||
}
|
||||
|
||||
|
|
@ -1048,7 +1048,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||
}
|
||||
annotate_err_with_kind(&mut err, kind, span);
|
||||
let guar = err.emit();
|
||||
self.cx.trace_macros_diag();
|
||||
self.cx.macro_error_and_trace_macros_diag();
|
||||
kind.dummy(span, guar)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -299,6 +299,7 @@ enum EofMatcherPositions {
|
|||
}
|
||||
|
||||
/// Represents the possible results of an attempted parse.
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum ParseResult<T, F> {
|
||||
/// Parsed successfully.
|
||||
Success(T),
|
||||
|
|
|
|||
|
|
@ -280,7 +280,7 @@ fn expand_macro<'cx>(
|
|||
// Retry and emit a better error.
|
||||
let (span, guar) =
|
||||
diagnostics::failed_to_match_macro(cx.psess(), sp, def_span, name, arg, rules);
|
||||
cx.trace_macros_diag();
|
||||
cx.macro_error_and_trace_macros_diag();
|
||||
DummyResult::any(span, guar)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -208,6 +208,10 @@ fn configure_and_expand(
|
|||
// Expand macros now!
|
||||
let krate = sess.time("expand_crate", || ecx.monotonic_expander().expand_crate(krate));
|
||||
|
||||
if ecx.nb_macro_errors > 0 {
|
||||
sess.dcx().abort_if_errors();
|
||||
}
|
||||
|
||||
// The rest is error reporting and stats
|
||||
|
||||
sess.psess.buffered_lints.with_lock(|buffered_lints: &mut Vec<BufferedEarlyLint>| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue