Skip to content

Commit 0b8decf

Browse files
committed
Fix macro call site spans
1 parent 764ef92 commit 0b8decf

File tree

2 files changed

+8
-31
lines changed

2 files changed

+8
-31
lines changed

src/libsyntax/ext/base.rs

-16
Original file line numberDiff line numberDiff line change
@@ -602,22 +602,6 @@ impl<'a> ExtCtxt<'a> {
602602
}
603603
pub fn backtrace(&self) -> ExpnId { self.backtrace }
604604

605-
/// Original span that caused the current exapnsion to happen.
606-
pub fn original_span(&self) -> Span {
607-
let mut expn_id = self.backtrace;
608-
let mut call_site = None;
609-
loop {
610-
match self.codemap().with_expn_info(expn_id, |ei| ei.map(|ei| ei.call_site)) {
611-
None => break,
612-
Some(cs) => {
613-
call_site = Some(cs);
614-
expn_id = cs.expn_id;
615-
}
616-
}
617-
}
618-
call_site.expect("missing expansion backtrace")
619-
}
620-
621605
/// Returns span for the macro which originally caused the current expansion to happen.
622606
///
623607
/// Stops backtracing at include! boundary.

src/libsyntax/ext/expand.rs

+8-15
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ fn expand_mac_invoc<T, F, G>(mac: ast::Mac,
224224
}
225225
Some(rc) => match *rc {
226226
NormalTT(ref expandfun, exp_span, allow_internal_unstable) => {
227+
let span = fld.new_span(span);
227228
fld.cx.bt_push(ExpnInfo {
228229
call_site: span,
229230
callee: NameAndSpan {
@@ -235,16 +236,8 @@ fn expand_mac_invoc<T, F, G>(mac: ast::Mac,
235236
let fm = fresh_mark();
236237
let marked_before = mark_tts(&tts[..], fm);
237238

238-
// The span that we pass to the expanders we want to
239-
// be the root of the call stack. That's the most
240-
// relevant span and it's the actual invocation of
241-
// the macro.
242-
let mac_span = fld.cx.original_span();
243-
244239
let opt_parsed = {
245-
let expanded = expandfun.expand(fld.cx,
246-
mac_span,
247-
&marked_before[..]);
240+
let expanded = expandfun.expand(fld.cx, span, &marked_before);
248241
parse_thunk(expanded)
249242
};
250243
let parsed = match opt_parsed {
@@ -372,8 +365,10 @@ fn contains_macro_use(fld: &mut MacroExpander, attrs: &[ast::Attribute]) -> bool
372365
pub fn expand_item_mac(it: P<ast::Item>,
373366
fld: &mut MacroExpander) -> SmallVector<P<ast::Item>> {
374367
let (extname, path_span, tts, span, attrs, ident) = it.and_then(|it| match it.node {
375-
ItemKind::Mac(codemap::Spanned { node: Mac_ { path, tts, .. }, .. }) =>
376-
(path.segments[0].identifier.name, path.span, tts, it.span, it.attrs, it.ident),
368+
ItemKind::Mac(codemap::Spanned { node: Mac_ { path, tts, .. }, .. }) => {
369+
let span = fld.new_span(it.span);
370+
(path.segments[0].identifier.name, path.span, tts, span, it.attrs, it.ident)
371+
}
377372
_ => fld.cx.span_bug(it.span, "invalid item macro invocation")
378373
});
379374

@@ -775,6 +770,7 @@ fn expand_pat(p: P<ast::Pat>, fld: &mut MacroExpander) -> P<ast::Pat> {
775770

776771
Some(rc) => match *rc {
777772
NormalTT(ref expander, tt_span, allow_internal_unstable) => {
773+
let span = fld.new_span(span);
778774
fld.cx.bt_push(ExpnInfo {
779775
call_site: span,
780776
callee: NameAndSpan {
@@ -786,10 +782,7 @@ fn expand_pat(p: P<ast::Pat>, fld: &mut MacroExpander) -> P<ast::Pat> {
786782

787783
let fm = fresh_mark();
788784
let marked_before = mark_tts(&tts[..], fm);
789-
let mac_span = fld.cx.original_span();
790-
let pat = expander.expand(fld.cx,
791-
mac_span,
792-
&marked_before[..]).make_pat();
785+
let pat = expander.expand(fld.cx, span, &marked_before).make_pat();
793786
let expanded = match pat {
794787
Some(e) => e,
795788
None => {

0 commit comments

Comments
 (0)