@@ -29,6 +29,11 @@ use std::rc::Rc;
29
29
30
30
struct ParserAnyMacro < ' a > {
31
31
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
32
37
}
33
38
34
39
impl < ' a > ParserAnyMacro < ' a > {
@@ -50,6 +55,12 @@ impl<'a> ParserAnyMacro<'a> {
50
55
token_str) ;
51
56
let span = parser. span ;
52
57
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[ ..] ) ;
53
64
}
54
65
}
55
66
}
@@ -169,6 +180,12 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
169
180
// Weird, but useful for X-macros.
170
181
return box ParserAnyMacro {
171
182
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
172
189
}
173
190
}
174
191
Failure ( sp, ref msg) => if sp. lo >= best_fail_spot. lo {
0 commit comments