Skip to content

Commit 52582da

Browse files
jbclementsalexcrichton
authored andcommitted
---
yaml --- r: 126650 b: refs/heads/snap-stage3 c: 1607064 h: refs/heads/master v: v3
1 parent 5cb7e3d commit 52582da

File tree

7 files changed

+36
-23
lines changed

7 files changed

+36
-23
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 7be8f0af0393dcdb077c2f6b1653836fd3fba235
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: e8c9d21130ff2f25b18978119e1f123a219af056
4+
refs/heads/snap-stage3: 1607064cfed6d7d4d963de8bb038079592b20995
55
refs/heads/try: 502e4c045236682e9728539dc0d2b3d0b237f55c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/librustc/metadata/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,8 +1618,8 @@ fn encode_macro_defs(ecx: &EncodeContext,
16181618
krate: &Crate,
16191619
ebml_w: &mut Encoder) {
16201620
ebml_w.start_tag(tag_exported_macros);
1621-
for span in krate.exported_macros.iter() {
1622-
encode_macro_def(ecx, ebml_w, span);
1621+
for item in krate.exported_macros.iter() {
1622+
encode_macro_def(ecx, ebml_w, &item.span);
16231623
}
16241624
ebml_w.end_tag();
16251625
}

branches/snap-stage3/src/librustdoc/visit_ast.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ use std::gc::{Gc, GC};
2626
use core;
2727
use doctree::*;
2828

29+
// looks to me like the first two of these are actually
30+
// output parameters, maybe only mutated once; perhaps
31+
// better simply to have the visit method return a tuple
32+
// containing them?
33+
34+
// also, is there some reason that this doesn't use the 'visit'
35+
// framework from syntax?
36+
2937
pub struct RustdocVisitor<'a> {
3038
pub module: Module,
3139
pub attrs: Vec<ast::Attribute>,
@@ -64,6 +72,9 @@ impl<'a> RustdocVisitor<'a> {
6472
ast::CRATE_NODE_ID,
6573
&krate.module,
6674
None);
75+
// attach the crate's exported macros to the top-level module:
76+
self.module.macros = krate.exported_macros.iter()
77+
.map(|it| self.visit_macro(&**it)).collect();
6778
self.module.is_crate = true;
6879
}
6980

@@ -323,15 +334,20 @@ impl<'a> RustdocVisitor<'a> {
323334
ast::ItemForeignMod(ref fm) => {
324335
om.foreigns.push(fm.clone());
325336
}
326-
ast::ItemMac(ref _m) => {
327-
om.macros.push(Macro {
328-
id: item.id,
329-
attrs: item.attrs.iter().map(|x| *x).collect(),
330-
name: item.ident,
331-
where: item.span,
332-
stab: self.stability(item.id),
333-
})
337+
ast::ItemMac(_) => {
338+
fail!("rustdoc: macros should be gone, after expansion");
334339
}
335340
}
336341
}
342+
343+
// convert each exported_macro into a doc item
344+
fn visit_macro(&self, item: &ast::Item) -> Macro {
345+
Macro {
346+
id: item.id,
347+
attrs: item.attrs.iter().map(|x| *x).collect(),
348+
name: item.ident,
349+
where: item.span,
350+
stab: self.stability(item.id),
351+
}
352+
}
337353
}

branches/snap-stage3/src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pub struct Crate {
256256
pub attrs: Vec<Attribute>,
257257
pub config: CrateConfig,
258258
pub span: Span,
259-
pub exported_macros: Vec<Span>
259+
pub exported_macros: Vec<Gc<Item>>
260260
}
261261

262262
pub type MetaItem = Spanned<MetaItem_>;

branches/snap-stage3/src/libsyntax/ext/base.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ pub type IdentMacroExpanderFn =
104104
/// just into the compiler's internal macro table, for `make_def`).
105105
pub trait MacResult {
106106
/// Define a new macro.
107-
// this should go away; the idea that a macro might expand into
108-
// either a macro definition or an expression, depending on what
109-
// the context wants, is kind of silly.
107+
// this particular flavor should go away; the idea that a macro might
108+
// expand into either a macro definition or an expression, depending
109+
// on what the context wants, is kind of silly.
110110
fn make_def(&self) -> Option<MacroDef> {
111111
None
112112
}
@@ -431,7 +431,7 @@ pub struct ExtCtxt<'a> {
431431

432432
pub mod_path: Vec<ast::Ident> ,
433433
pub trace_mac: bool,
434-
pub exported_macros: Vec<codemap::Span>
434+
pub exported_macros: Vec<Gc<ast::Item>>
435435
}
436436

437437
impl<'a> ExtCtxt<'a> {
@@ -562,9 +562,6 @@ impl<'a> ExtCtxt<'a> {
562562
pub fn name_of(&self, st: &str) -> ast::Name {
563563
token::intern(st)
564564
}
565-
pub fn push_exported_macro(&mut self, span: codemap::Span) {
566-
self.exported_macros.push(span);
567-
}
568565
}
569566

570567
/// Extract a string literal from the macro expanded version of `expr`,

branches/snap-stage3/src/libsyntax/ext/expand.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ fn expand_item_mac(it: Gc<ast::Item>, fld: &mut MacroExpander)
536536
// create issue to recommend refactoring here?
537537
fld.extsbox.insert(intern(name.as_slice()), ext);
538538
if attr::contains_name(it.attrs.as_slice(), "macro_export") {
539-
fld.cx.push_exported_macro(it.span);
539+
fld.cx.exported_macros.push(it);
540540
}
541541
SmallVector::zero()
542542
}
@@ -1039,7 +1039,7 @@ pub struct ExportedMacros {
10391039
pub fn expand_crate(parse_sess: &parse::ParseSess,
10401040
cfg: ExpansionConfig,
10411041
// these are the macros being imported to this crate:
1042-
macros: Vec<ExportedMacros>,
1042+
imported_macros: Vec<ExportedMacros>,
10431043
user_exts: Vec<NamedSyntaxExtension>,
10441044
c: Crate) -> Crate {
10451045
let mut cx = ExtCtxt::new(parse_sess, c.config.clone(), cfg);
@@ -1048,7 +1048,7 @@ pub fn expand_crate(parse_sess: &parse::ParseSess,
10481048
cx: &mut cx,
10491049
};
10501050

1051-
for ExportedMacros { crate_name, macros } in macros.move_iter() {
1051+
for ExportedMacros { crate_name, macros } in imported_macros.move_iter() {
10521052
let name = format!("<{} macros>", token::get_ident(crate_name))
10531053
.into_string();
10541054

branches/snap-stage3/src/libsyntax/fold.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ pub fn noop_fold_crate<T: Folder>(c: Crate, folder: &mut T) -> Crate {
752752
attrs: c.attrs.iter().map(|x| folder.fold_attribute(*x)).collect(),
753753
config: c.config.iter().map(|x| fold_meta_item_(*x, folder)).collect(),
754754
span: folder.new_span(c.span),
755-
exported_macros: c.exported_macros.iter().map(|sp| folder.new_span(*sp)).collect(),
755+
exported_macros: c.exported_macros
756756
}
757757
}
758758

0 commit comments

Comments
 (0)