From b4295b9fb0789b9c354d17457dc60a7ca13119a6 Mon Sep 17 00:00:00 2001 From: Kevin Yeh Date: Thu, 26 Nov 2015 13:14:10 -0600 Subject: [PATCH 1/2] Fix spans for macros --- src/libsyntax/parse/parser.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 56a06f70ed4b4..74b8fdea538bf 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3253,7 +3253,7 @@ impl<'a> Parser<'a> { let tts = try!(self.parse_seq_to_end(&token::CloseDelim(delim), seq_sep_none(), |p| p.parse_token_tree())); let mac = Mac_ { path: path, tts: tts, ctxt: EMPTY_CTXT }; - pat = PatMac(codemap::Spanned {node: mac, span: self.span}); + pat = PatMac(codemap::Spanned {node: mac, span: mk_sp(lo, self.span.hi)}); } else { // Parse ident @ pat // This can give false positives and parse nullary enums, @@ -4475,6 +4475,7 @@ impl<'a> Parser<'a> { let last_span = self.last_span; self.complain_if_pub_macro(vis, last_span); + let lo = self.span.lo; let pth = try!(self.parse_path(NoTypesAllowed)); try!(self.expect(&token::Not)); @@ -4485,7 +4486,7 @@ impl<'a> Parser<'a> { |p| p.parse_token_tree())); let m_ = Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT }; let m: ast::Mac = codemap::Spanned { node: m_, - span: mk_sp(self.span.lo, + span: mk_sp(lo, self.span.hi) }; if delim != token::Brace { try!(self.expect(&token::Semi)) @@ -5513,6 +5514,8 @@ impl<'a> Parser<'a> { let last_span = self.last_span; self.complain_if_pub_macro(visibility, last_span); + let mac_lo = self.span.lo; + // item macro. let pth = try!(self.parse_path(NoTypesAllowed)); try!(self.expect(&token::Not)); @@ -5533,7 +5536,7 @@ impl<'a> Parser<'a> { // single-variant-enum... : let m = Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT }; let m: ast::Mac = codemap::Spanned { node: m, - span: mk_sp(self.span.lo, + span: mk_sp(mac_lo, self.span.hi) }; if delim != token::Brace { From 920120ed4ce2389b0db5cdabb3eb60535da5836d Mon Sep 17 00:00:00 2001 From: Kevin Yeh Date: Sat, 28 Nov 2015 22:36:37 -0600 Subject: [PATCH 2/2] Use last_span for macro spans --- src/libsyntax/parse/parser.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 74b8fdea538bf..ce65f99e2f0c9 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3253,7 +3253,8 @@ impl<'a> Parser<'a> { let tts = try!(self.parse_seq_to_end(&token::CloseDelim(delim), seq_sep_none(), |p| p.parse_token_tree())); let mac = Mac_ { path: path, tts: tts, ctxt: EMPTY_CTXT }; - pat = PatMac(codemap::Spanned {node: mac, span: mk_sp(lo, self.span.hi)}); + pat = PatMac(codemap::Spanned {node: mac, + span: mk_sp(lo, self.last_span.hi)}); } else { // Parse ident @ pat // This can give false positives and parse nullary enums, @@ -4487,7 +4488,7 @@ impl<'a> Parser<'a> { let m_ = Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT }; let m: ast::Mac = codemap::Spanned { node: m_, span: mk_sp(lo, - self.span.hi) }; + self.last_span.hi) }; if delim != token::Brace { try!(self.expect(&token::Semi)) } @@ -5537,7 +5538,7 @@ impl<'a> Parser<'a> { let m = Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT }; let m: ast::Mac = codemap::Spanned { node: m, span: mk_sp(mac_lo, - self.span.hi) }; + self.last_span.hi) }; if delim != token::Brace { if !try!(self.eat(&token::Semi) ){