From 1607064cfed6d7d4d963de8bb038079592b20995 Mon Sep 17 00:00:00 2001 From: John Clements Date: Thu, 17 Jul 2014 09:45:31 -0700 Subject: repair macro docs In f1ad425199b0d89dab275a8c8f6f29a73d316f70, I changed the handling of macros, to prevent macro invocations from occurring in fully expanded source. Instead, I added a side table. It contained only the spans of the macros, because this was the only information required in order to make macro export work. However, librustdoc was also affected by this change, since it extracts macro information in a similar way. As a result of the earlier change, exported macros were no longer documented. In order to repair this, I've adjusted the side table to contain whole items, rather than just the spans. --- src/libsyntax/ext/base.rs | 11 ++++------- src/libsyntax/ext/expand.rs | 6 +++--- 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 49bd3697884..5341f0c2d61 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -104,9 +104,9 @@ pub type IdentMacroExpanderFn = /// just into the compiler's internal macro table, for `make_def`). pub trait MacResult { /// Define a new macro. - // this should go away; the idea that a macro might expand into - // either a macro definition or an expression, depending on what - // the context wants, is kind of silly. + // this particular flavor should go away; the idea that a macro might + // expand into either a macro definition or an expression, depending + // on what the context wants, is kind of silly. fn make_def(&self) -> Option { None } @@ -431,7 +431,7 @@ pub struct ExtCtxt<'a> { pub mod_path: Vec , pub trace_mac: bool, - pub exported_macros: Vec + pub exported_macros: Vec> } impl<'a> ExtCtxt<'a> { @@ -562,9 +562,6 @@ impl<'a> ExtCtxt<'a> { pub fn name_of(&self, st: &str) -> ast::Name { token::intern(st) } - pub fn push_exported_macro(&mut self, span: codemap::Span) { - self.exported_macros.push(span); - } } /// Extract a string literal from the macro expanded version of `expr`, diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index fdb698441fc..c10f3ce0774 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -536,7 +536,7 @@ fn expand_item_mac(it: Gc, fld: &mut MacroExpander) // create issue to recommend refactoring here? fld.extsbox.insert(intern(name.as_slice()), ext); if attr::contains_name(it.attrs.as_slice(), "macro_export") { - fld.cx.push_exported_macro(it.span); + fld.cx.exported_macros.push(it); } SmallVector::zero() } @@ -1039,7 +1039,7 @@ pub struct ExportedMacros { pub fn expand_crate(parse_sess: &parse::ParseSess, cfg: ExpansionConfig, // these are the macros being imported to this crate: - macros: Vec, + imported_macros: Vec, user_exts: Vec, c: Crate) -> Crate { let mut cx = ExtCtxt::new(parse_sess, c.config.clone(), cfg); @@ -1048,7 +1048,7 @@ pub fn expand_crate(parse_sess: &parse::ParseSess, cx: &mut cx, }; - for ExportedMacros { crate_name, macros } in macros.move_iter() { + for ExportedMacros { crate_name, macros } in imported_macros.move_iter() { let name = format!("<{} macros>", token::get_ident(crate_name)) .into_string(); -- cgit 1.4.1-3-g733a5