diff options
| author | Will Hipschman <whipsch@gmail.com> | 2015-04-04 13:13:57 -0700 |
|---|---|---|
| committer | Will Hipschman <whipsch@gmail.com> | 2015-04-06 17:59:58 -0700 |
| commit | ab3215406d0cd76ea71a554e0f4bdd16331cca7f (patch) | |
| tree | 6c4790fffc3449788b4ba3ff3d41ed166e3ae2e1 /src/libsyntax | |
| parent | b49a5ef003fedcbb0d78aebda62ba30dfdd17a20 (diff) | |
| download | rust-ab3215406d0cd76ea71a554e0f4bdd16331cca7f.tar.gz rust-ab3215406d0cd76ea71a554e0f4bdd16331cca7f.zip | |
Provide context for macro expansions which result in unparsed tokens.
Issue #22425
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 250ba0442ba..009075540fa 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -29,6 +29,11 @@ use std::rc::Rc; struct ParserAnyMacro<'a> { parser: RefCell<Parser<'a>>, + + /// Span of the expansion site of the macro this parser is for + site_span: Span, + /// The ident of the macro we're parsing + macro_ident: ast::Ident } impl<'a> ParserAnyMacro<'a> { @@ -50,6 +55,12 @@ impl<'a> ParserAnyMacro<'a> { token_str); let span = parser.span; parser.span_err(span, &msg[..]); + + let name = token::get_ident(self.macro_ident); + let msg = format!("caused by the macro expansion here; the usage \ + of `{}` is likely invalid in this context", + name); + parser.span_note(self.site_span, &msg[..]); } } } @@ -169,6 +180,12 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt, // Weird, but useful for X-macros. return box ParserAnyMacro { parser: RefCell::new(p), + + // Pass along the original expansion site and the name of the macro + // so we can print a useful error message if the parse of the expanded + // macro leaves unparsed tokens. + site_span: sp, + macro_ident: name } } Failure(sp, ref msg) => if sp.lo >= best_fail_spot.lo { |
