]> git.lizzy.rs Git - rust.git/commitdiff
Expect macro defs in save-analysis and add expn info to spans for attr proc macros
authorNick Cameron <ncameron@mozilla.com>
Tue, 7 Mar 2017 04:37:45 +0000 (17:37 +1300)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 10 Mar 2017 16:16:21 +0000 (08:16 -0800)
src/librustc_save_analysis/dump_visitor.rs
src/libsyntax/ext/expand.rs

index 3c275e0996dac0c3877c693f5bad6a7763cf0274..33d5c17a41921f9122942da41b394c85c9f1de0f 100644 (file)
@@ -327,6 +327,9 @@ fn process_def_kind(&mut self,
                     scope: scope
                 }.lower(self.tcx));
             }
+            // With macros 2.0, we can legitimately get a ref to a macro, but
+            // we don't handle it properly for now (FIXME).
+            Def::Macro(..) => {}
             Def::Local(..) |
             Def::Upvar(..) |
             Def::SelfTy(..) |
@@ -336,7 +339,6 @@ fn process_def_kind(&mut self,
             Def::AssociatedTy(..) |
             Def::AssociatedConst(..) |
             Def::PrimTy(_) |
-            Def::Macro(..) |
             Def::Err => {
                span_bug!(span,
                          "process_def_kind for unexpected item: {:?}",
index f1662284a88206657283952e9c444e4c5ea39397..f7dcd00e40976d7ba8f16464ca4428dcdc95ce1c 100644 (file)
@@ -464,8 +464,20 @@ fn expand_attr_invoc(&mut self, invoc: Invocation, ext: Rc<SyntaxExtension>) ->
                 let attr_toks = stream_for_attr_args(&attr, &self.cx.parse_sess);
                 let item_toks = stream_for_item(&item, &self.cx.parse_sess);
 
+                let span = Span {
+                    expn_id: self.cx.codemap().record_expansion(ExpnInfo {
+                        call_site: attr.span,
+                        callee: NameAndSpan {
+                            format: MacroAttribute(name),
+                            span: None,
+                            allow_internal_unstable: false,
+                        },
+                    }),
+                    ..attr.span
+                };
+
                 let tok_result = mac.expand(self.cx, attr.span, attr_toks, item_toks);
-                self.parse_expansion(tok_result, kind, name, attr.span)
+                self.parse_expansion(tok_result, kind, name, span)
             }
             SyntaxExtension::ProcMacroDerive(..) | SyntaxExtension::BuiltinDerive(..) => {
                 self.cx.span_err(attr.span, &format!("`{}` is a derive mode", name));