From cf9283ea9376525c59015a52c729e7a79f576426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 25 Nov 2017 08:48:11 -0800 Subject: [PATCH] Fix proc_macro output with struct parse error --- src/libsyntax_ext/deriving/custom.rs | 8 +++++++- src/test/compile-fail-fulldeps/proc-macro/derive-bad.rs | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) 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() {}