@@ -29,6 +29,11 @@ use std::rc::Rc;
2929
3030struct ParserAnyMacro < ' a > {
3131 parser : RefCell < Parser < ' a > > ,
32+
33+ /// Span of the expansion site of the macro this parser is for
34+ site_span : Span ,
35+ /// The ident of the macro we're parsing
36+ macro_ident : ast:: Ident
3237}
3338
3439impl < ' a > ParserAnyMacro < ' a > {
@@ -50,6 +55,12 @@ impl<'a> ParserAnyMacro<'a> {
5055 token_str) ;
5156 let span = parser. span ;
5257 parser. span_err ( span, & msg[ ..] ) ;
58+
59+ let name = token:: get_ident ( self . macro_ident ) ;
60+ let msg = format ! ( "caused by the macro expansion here; the usage \
61+ of `{}` is likely invalid in this context",
62+ name) ;
63+ parser. span_note ( self . site_span , & msg[ ..] ) ;
5364 }
5465 }
5566}
@@ -169,6 +180,12 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
169180 // Weird, but useful for X-macros.
170181 return box ParserAnyMacro {
171182 parser : RefCell :: new ( p) ,
183+
184+ // Pass along the original expansion site and the name of the macro
185+ // so we can print a useful error message if the parse of the expanded
186+ // macro leaves unparsed tokens.
187+ site_span : sp,
188+ macro_ident : name
172189 }
173190 }
174191 Failure ( sp, ref msg) => if sp. lo >= best_fail_spot. lo {
0 commit comments