Fix proc_macro output with struct parse error

This commit is contained in:
Esteban Küber 2017-11-25 08:48:11 -08:00
parent 0e241d0059
commit cf9283ea93
2 changed files with 9 additions and 2 deletions

View File

@ -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);
}

View File

@ -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() {}