diff --git a/src/libsyntax_ext/deriving/custom.rs b/src/libsyntax_ext/deriving/custom.rs index fa5537b5d8f..f375847e705 100644 --- a/src/libsyntax_ext/deriving/custom.rs +++ b/src/libsyntax_ext/deriving/custom.rs @@ -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); } diff --git a/src/test/compile-fail-fulldeps/proc-macro/derive-bad.rs b/src/test/compile-fail-fulldeps/proc-macro/derive-bad.rs index b03409c9c28..93790f59372 100644 --- a/src/test/compile-fail-fulldeps/proc-macro/derive-bad.rs +++ b/src/test/compile-fail-fulldeps/proc-macro/derive-bad.rs @@ -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() {}