Skip to content

Commit cc662ef

Browse files
committed
Auto merge of #38194 - sgrif:sg-no-span-mangling, r=nrc
Don't perform span mangling when building field/tup access nodes There are no guarantees that the two spans used to create the new one come from the same place or are even valid. Fixes #36081.
2 parents 0102127 + 0ddf618 commit cc662ef

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

src/libsyntax/ext/build.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use abi::Abi;
1212
use ast::{self, Ident, Generics, Expr, BlockCheckMode, UnOp, PatKind};
1313
use attr;
14-
use syntax_pos::{Span, DUMMY_SP, Pos};
14+
use syntax_pos::{Span, DUMMY_SP};
1515
use codemap::{dummy_spanned, respan, Spanned};
1616
use ext::base::ExtCtxt;
1717
use ptr::P;
@@ -659,23 +659,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
659659
}
660660

661661
fn expr_field_access(&self, sp: Span, expr: P<ast::Expr>, ident: ast::Ident) -> P<ast::Expr> {
662-
let field_span = Span {
663-
lo: sp.lo - Pos::from_usize(ident.name.as_str().len()),
664-
hi: sp.hi,
665-
expn_id: sp.expn_id,
666-
};
667-
668-
let id = Spanned { node: ident, span: field_span };
662+
let id = Spanned { node: ident, span: sp };
669663
self.expr(sp, ast::ExprKind::Field(expr, id))
670664
}
671665
fn expr_tup_field_access(&self, sp: Span, expr: P<ast::Expr>, idx: usize) -> P<ast::Expr> {
672-
let field_span = Span {
673-
lo: sp.lo - Pos::from_usize(idx.to_string().len()),
674-
hi: sp.hi,
675-
expn_id: sp.expn_id,
676-
};
677-
678-
let id = Spanned { node: idx, span: field_span };
666+
let id = Spanned { node: idx, span: sp };
679667
self.expr(sp, ast::ExprKind::TupField(expr, id))
680668
}
681669
fn expr_addr_of(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> {

0 commit comments

Comments
 (0)