Skip to content

Commit

Permalink
Fix proc_macro output with struct parse error
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Nov 25, 2017
1 parent 0e241d0 commit cf9283e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/libsyntax_ext/deriving/custom.rs
Expand Up @@ -96,12 +96,18 @@ impl MultiItemModifier for ProcMacroDerive {
}
};

let error_count_before = ecx.parse_sess.span_diagnostic.err_count();
__internal::set_sess(ecx, || {
let msg = "proc-macro derive produced unparseable tokens";
match __internal::token_stream_parse_items(stream) {
// fail if there have been errors emitted
Ok(_) if ecx.parse_sess.span_diagnostic.err_count() > error_count_before => {
ecx.struct_span_fatal(span, msg).emit();
panic!(FatalError);
}
Ok(new_items) => new_items.into_iter().map(Annotatable::Item).collect(),
Err(_) => {
// FIXME: handle this better
let msg = "proc-macro derive produced unparseable tokens";
ecx.struct_span_fatal(span, msg).emit();
panic!(FatalError);
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/compile-fail-fulldeps/proc-macro/derive-bad.rs
Expand Up @@ -17,7 +17,8 @@ extern crate derive_bad;
#[derive(
A
)]
//~^^ ERROR: proc-macro derive produced unparseable tokens
//~^^ ERROR proc-macro derive produced unparseable tokens
//~| ERROR expected `:`, found `}`
struct A;

fn main() {}

0 comments on commit cf9283e

Please sign in to comment.