Set span for interpolated tokens correctly
This commit is contained in:
parent
877ed0d068
commit
20edb366e7
2 changed files with 18 additions and 7 deletions
|
@ -300,13 +300,13 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
|
||||||
// (a) idents can be in lots of places, so it'd be a pain
|
// (a) idents can be in lots of places, so it'd be a pain
|
||||||
// (b) we actually can, since it's a token.
|
// (b) we actually can, since it's a token.
|
||||||
MatchedNonterminal(NtIdent(ref sn, b)) => {
|
MatchedNonterminal(NtIdent(ref sn, b)) => {
|
||||||
r.cur_span = sp;
|
r.cur_span = sn.span;
|
||||||
r.cur_tok = token::Ident(sn.node, b);
|
r.cur_tok = token::Ident(sn.node, b);
|
||||||
return ret_val;
|
return ret_val;
|
||||||
}
|
}
|
||||||
MatchedNonterminal(NtExpr(ref expr)) => {
|
MatchedNonterminal(NtExpr(ref expr)) => {
|
||||||
let mut expr = (**expr).clone();
|
let mut expr = (**expr).clone();
|
||||||
update_span(sp, &mut expr);
|
//update_span(sp, &mut expr);
|
||||||
// FIXME(pcwalton): Bad copy.
|
// FIXME(pcwalton): Bad copy.
|
||||||
r.cur_span = sp;
|
r.cur_span = sp;
|
||||||
r.cur_tok = token::Interpolated(NtExpr(ptr::P(expr)));
|
r.cur_tok = token::Interpolated(NtExpr(ptr::P(expr)));
|
||||||
|
|
|
@ -2322,18 +2322,29 @@ impl<'a> Parser<'a> {
|
||||||
-> PResult<'a, P<Expr>> {
|
-> PResult<'a, P<Expr>> {
|
||||||
let attrs = try!(self.parse_or_use_outer_attributes(already_parsed_attrs));
|
let attrs = try!(self.parse_or_use_outer_attributes(already_parsed_attrs));
|
||||||
|
|
||||||
|
let interp = if let token::Interpolated(..) = self.token {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
let b = try!(self.parse_bottom_expr());
|
let b = try!(self.parse_bottom_expr());
|
||||||
self.parse_dot_or_call_expr_with(b, attrs)
|
let lo = if interp {
|
||||||
|
self.last_span.lo
|
||||||
|
} else {
|
||||||
|
b.span.lo
|
||||||
|
};
|
||||||
|
self.parse_dot_or_call_expr_with(b, lo, attrs)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_dot_or_call_expr_with(&mut self,
|
pub fn parse_dot_or_call_expr_with(&mut self,
|
||||||
e0: P<Expr>,
|
e0: P<Expr>,
|
||||||
|
lo: BytePos,
|
||||||
attrs: ThinAttributes)
|
attrs: ThinAttributes)
|
||||||
-> PResult<'a, P<Expr>> {
|
-> PResult<'a, P<Expr>> {
|
||||||
// Stitch the list of outer attributes onto the return value.
|
// Stitch the list of outer attributes onto the return value.
|
||||||
// A little bit ugly, but the best way given the current code
|
// A little bit ugly, but the best way given the current code
|
||||||
// structure
|
// structure
|
||||||
self.parse_dot_or_call_expr_with_(e0)
|
self.parse_dot_or_call_expr_with_(e0, lo)
|
||||||
.map(|expr|
|
.map(|expr|
|
||||||
expr.map(|mut expr| {
|
expr.map(|mut expr| {
|
||||||
expr.attrs.update(|a| a.prepend(attrs));
|
expr.attrs.update(|a| a.prepend(attrs));
|
||||||
|
@ -2408,9 +2419,8 @@ impl<'a> Parser<'a> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_dot_or_call_expr_with_(&mut self, e0: P<Expr>) -> PResult<'a, P<Expr>> {
|
fn parse_dot_or_call_expr_with_(&mut self, e0: P<Expr>, lo: BytePos) -> PResult<'a, P<Expr>> {
|
||||||
let mut e = e0;
|
let mut e = e0;
|
||||||
let lo = e.span.lo;
|
|
||||||
let mut hi;
|
let mut hi;
|
||||||
loop {
|
loop {
|
||||||
// expr.f
|
// expr.f
|
||||||
|
@ -3828,7 +3838,8 @@ impl<'a> Parser<'a> {
|
||||||
let e = self.mk_mac_expr(span.lo, span.hi,
|
let e = self.mk_mac_expr(span.lo, span.hi,
|
||||||
mac.and_then(|m| m.node),
|
mac.and_then(|m| m.node),
|
||||||
None);
|
None);
|
||||||
let e = try!(self.parse_dot_or_call_expr_with(e, attrs));
|
let lo = e.span.lo;
|
||||||
|
let e = try!(self.parse_dot_or_call_expr_with(e, lo, attrs));
|
||||||
let e = try!(self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e)));
|
let e = try!(self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e)));
|
||||||
try!(self.handle_expression_like_statement(
|
try!(self.handle_expression_like_statement(
|
||||||
e,
|
e,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue