Skip to content

Commit 78be7d2

Browse files
author
Ariel Ben-Yehuda
authored
Rollup merge of rust-lang#40311 - nrc:save-proc-macro-attr, r=jseyfried
Expect macro defs in save-analysis and add expn info to spans for att… …r proc macros r? @jseyfried
2 parents a98e38f + 5afe784 commit 78be7d2

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/librustc_save_analysis/dump_visitor.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
327327
scope: scope
328328
}.lower(self.tcx));
329329
}
330+
// With macros 2.0, we can legitimately get a ref to a macro, but
331+
// we don't handle it properly for now (FIXME).
332+
Def::Macro(..) => {}
330333
Def::Local(..) |
331334
Def::Upvar(..) |
332335
Def::SelfTy(..) |
@@ -336,7 +339,6 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
336339
Def::AssociatedTy(..) |
337340
Def::AssociatedConst(..) |
338341
Def::PrimTy(_) |
339-
Def::Macro(..) |
340342
Def::Err => {
341343
span_bug!(span,
342344
"process_def_kind for unexpected item: {:?}",

src/libsyntax/ext/expand.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,20 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
464464
let attr_toks = stream_for_attr_args(&attr, &self.cx.parse_sess);
465465
let item_toks = stream_for_item(&item, &self.cx.parse_sess);
466466

467+
let span = Span {
468+
expn_id: self.cx.codemap().record_expansion(ExpnInfo {
469+
call_site: attr.span,
470+
callee: NameAndSpan {
471+
format: MacroAttribute(name),
472+
span: None,
473+
allow_internal_unstable: false,
474+
},
475+
}),
476+
..attr.span
477+
};
478+
467479
let tok_result = mac.expand(self.cx, attr.span, attr_toks, item_toks);
468-
self.parse_expansion(tok_result, kind, name, attr.span)
480+
self.parse_expansion(tok_result, kind, name, span)
469481
}
470482
SyntaxExtension::ProcMacroDerive(..) | SyntaxExtension::BuiltinDerive(..) => {
471483
self.cx.span_err(attr.span, &format!("`{}` is a derive mode", name));

0 commit comments

Comments
 (0)