Skip to content

Commit 20edb36

Browse files
committed
Set span for interpolated tokens correctly
1 parent 877ed0d commit 20edb36

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/libsyntax/ext/tt/transcribe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,13 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
300300
// (a) idents can be in lots of places, so it'd be a pain
301301
// (b) we actually can, since it's a token.
302302
MatchedNonterminal(NtIdent(ref sn, b)) => {
303-
r.cur_span = sp;
303+
r.cur_span = sn.span;
304304
r.cur_tok = token::Ident(sn.node, b);
305305
return ret_val;
306306
}
307307
MatchedNonterminal(NtExpr(ref expr)) => {
308308
let mut expr = (**expr).clone();
309-
update_span(sp, &mut expr);
309+
//update_span(sp, &mut expr);
310310
// FIXME(pcwalton): Bad copy.
311311
r.cur_span = sp;
312312
r.cur_tok = token::Interpolated(NtExpr(ptr::P(expr)));

src/libsyntax/parse/parser.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,18 +2322,29 @@ impl<'a> Parser<'a> {
23222322
-> PResult<'a, P<Expr>> {
23232323
let attrs = try!(self.parse_or_use_outer_attributes(already_parsed_attrs));
23242324

2325+
let interp = if let token::Interpolated(..) = self.token {
2326+
true
2327+
} else {
2328+
false
2329+
};
23252330
let b = try!(self.parse_bottom_expr());
2326-
self.parse_dot_or_call_expr_with(b, attrs)
2331+
let lo = if interp {
2332+
self.last_span.lo
2333+
} else {
2334+
b.span.lo
2335+
};
2336+
self.parse_dot_or_call_expr_with(b, lo, attrs)
23272337
}
23282338

23292339
pub fn parse_dot_or_call_expr_with(&mut self,
23302340
e0: P<Expr>,
2341+
lo: BytePos,
23312342
attrs: ThinAttributes)
23322343
-> PResult<'a, P<Expr>> {
23332344
// Stitch the list of outer attributes onto the return value.
23342345
// A little bit ugly, but the best way given the current code
23352346
// structure
2336-
self.parse_dot_or_call_expr_with_(e0)
2347+
self.parse_dot_or_call_expr_with_(e0, lo)
23372348
.map(|expr|
23382349
expr.map(|mut expr| {
23392350
expr.attrs.update(|a| a.prepend(attrs));
@@ -2408,9 +2419,8 @@ impl<'a> Parser<'a> {
24082419
})
24092420
}
24102421

2411-
fn parse_dot_or_call_expr_with_(&mut self, e0: P<Expr>) -> PResult<'a, P<Expr>> {
2422+
fn parse_dot_or_call_expr_with_(&mut self, e0: P<Expr>, lo: BytePos) -> PResult<'a, P<Expr>> {
24122423
let mut e = e0;
2413-
let lo = e.span.lo;
24142424
let mut hi;
24152425
loop {
24162426
// expr.f
@@ -3828,7 +3838,8 @@ impl<'a> Parser<'a> {
38283838
let e = self.mk_mac_expr(span.lo, span.hi,
38293839
mac.and_then(|m| m.node),
38303840
None);
3831-
let e = try!(self.parse_dot_or_call_expr_with(e, attrs));
3841+
let lo = e.span.lo;
3842+
let e = try!(self.parse_dot_or_call_expr_with(e, lo, attrs));
38323843
let e = try!(self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e)));
38333844
try!(self.handle_expression_like_statement(
38343845
e,

0 commit comments

Comments
 (0)