about summary refs log tree commit diff
path: root/src/libsyntax/ext/expand.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-08-04 16:19:04 +0000
committerbors <bors@rust-lang.org>2019-08-04 16:19:04 +0000
commitf01b9f803b59f170f5dabaaa8aedc96abe45bfea (patch)
treee7388497c7f95770a07c90e2a67edbc0aa9851f4 /src/libsyntax/ext/expand.rs
parent460072ebeed5a2463109894592ac172b47cdfb74 (diff)
parentc82e1f2d0e0b7fec9265eac851b2ac8b500ec4cc (diff)
Auto merge of #62816 - estebank:type-ascription-macros, r=petrochenkov
Point at type ascription before macro invocation on expansion parse error

Fix https://github.com/rust-lang/rust/issues/47666. Follow up to https://github.com/rust-lang/rust/pull/62791.

r? @petrochenkov
Diffstat (limited to 'src/libsyntax/ext/expand.rs')
-rw-r--r--src/libsyntax/ext/expand.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 1e9e16d72f8..35017824233 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -517,8 +517,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
                     result
                 }
                 SyntaxExtensionKind::LegacyBang(expander) => {
+                    let prev = self.cx.current_expansion.prior_type_ascription;
+                    self.cx.current_expansion.prior_type_ascription =
+                        mac.node.prior_type_ascription;
                     let tok_result = expander.expand(self.cx, span, mac.node.stream());
-                    if let Some(result) = fragment_kind.make_from(tok_result) {
+                    let result = if let Some(result) = fragment_kind.make_from(tok_result) {
                         result
                     } else {
                         let msg = format!("non-{kind} macro in {kind} position: {path}",
@@ -526,7 +529,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
                         self.cx.span_err(span, &msg);
                         self.cx.trace_macros_diag();
                         fragment_kind.dummy(span)
-                    }
+                    };
+                    self.cx.current_expansion.prior_type_ascription = prev;
+                    result
                 }
                 _ => unreachable!()
             }