Skip to content

Commit f300582

Browse files
committed
rustdoc: fix fallout of merging ast::ViewItem into ast::Item.
1 parent 50e1896 commit f300582

File tree

10 files changed

+221
-250
lines changed

10 files changed

+221
-250
lines changed

src/librustdoc/clean/mod.rs

+76-112
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ pub use self::TypeKind::*;
1818
pub use self::StructField::*;
1919
pub use self::VariantKind::*;
2020
pub use self::Mutability::*;
21-
pub use self::ViewItemInner::*;
22-
pub use self::ViewPath::*;
21+
pub use self::Import::*;
2322
pub use self::ItemEnum::*;
2423
pub use self::Attribute::*;
2524
pub use self::TyParamBound::*;
@@ -304,6 +303,8 @@ impl Item {
304303

305304
#[deriving(Clone, RustcEncodable, RustcDecodable)]
306305
pub enum ItemEnum {
306+
ExternCrateItem(String, Option<String>),
307+
ImportItem(Import),
307308
StructItem(Struct),
308309
EnumItem(Enum),
309310
FunctionItem(Function),
@@ -313,8 +314,6 @@ pub enum ItemEnum {
313314
ConstantItem(Constant),
314315
TraitItem(Trait),
315316
ImplItem(Impl),
316-
/// `use` and `extern crate`
317-
ViewItemItem(ViewItem),
318317
/// A method signature only. Used for required methods in traits (ie,
319318
/// non-default-methods).
320319
TyMethodItem(TyMethod),
@@ -344,27 +343,21 @@ impl Clean<Item> for doctree::Module {
344343
} else {
345344
"".to_string()
346345
};
347-
let mut foreigns = Vec::new();
348-
for subforeigns in self.foreigns.clean(cx).into_iter() {
349-
for foreign in subforeigns.into_iter() {
350-
foreigns.push(foreign)
351-
}
352-
}
353-
let items: Vec<Vec<Item> > = vec!(
354-
self.structs.clean(cx),
355-
self.enums.clean(cx),
356-
self.fns.clean(cx),
357-
foreigns,
358-
self.mods.clean(cx),
359-
self.typedefs.clean(cx),
360-
self.statics.clean(cx),
361-
self.constants.clean(cx),
362-
self.traits.clean(cx),
363-
self.impls.clean(cx),
364-
self.view_items.clean(cx).into_iter()
365-
.flat_map(|s| s.into_iter()).collect(),
366-
self.macros.clean(cx),
367-
);
346+
let items: Vec<Item> =
347+
self.extern_crates.iter().map(|x| x.clean(cx))
348+
.chain(self.imports.iter().flat_map(|x| x.clean(cx).into_iter()))
349+
.chain(self.structs.iter().map(|x| x.clean(cx)))
350+
.chain(self.enums.iter().map(|x| x.clean(cx)))
351+
.chain(self.fns.iter().map(|x| x.clean(cx)))
352+
.chain(self.foreigns.iter().flat_map(|x| x.clean(cx).into_iter()))
353+
.chain(self.mods.iter().map(|x| x.clean(cx)))
354+
.chain(self.typedefs.iter().map(|x| x.clean(cx)))
355+
.chain(self.statics.iter().map(|x| x.clean(cx)))
356+
.chain(self.constants.iter().map(|x| x.clean(cx)))
357+
.chain(self.traits.iter().map(|x| x.clean(cx)))
358+
.chain(self.impls.iter().map(|x| x.clean(cx)))
359+
.chain(self.macros.iter().map(|x| x.clean(cx)))
360+
.collect();
368361

369362
// determine if we should display the inner contents or
370363
// the outer `mod` item for the source code.
@@ -390,9 +383,7 @@ impl Clean<Item> for doctree::Module {
390383
def_id: ast_util::local_def(self.id),
391384
inner: ModuleItem(Module {
392385
is_crate: self.is_crate,
393-
items: items.iter()
394-
.flat_map(|x| x.iter().map(|x| (*x).clone()))
395-
.collect(),
386+
items: items
396387
})
397388
}
398389
}
@@ -2000,12 +1991,21 @@ impl Clean<Item> for doctree::Impl {
20001991
}
20011992
}
20021993

2003-
#[deriving(Clone, RustcEncodable, RustcDecodable)]
2004-
pub struct ViewItem {
2005-
pub inner: ViewItemInner,
1994+
impl Clean<Item> for doctree::ExternCrate {
1995+
fn clean(&self, cx: &DocContext) -> Item {
1996+
Item {
1997+
name: None,
1998+
attrs: self.attrs.clean(cx),
1999+
source: self.whence.clean(cx),
2000+
def_id: ast_util::local_def(0),
2001+
visibility: self.vis.clean(cx),
2002+
stability: None,
2003+
inner: ExternCrateItem(self.name.clean(cx), self.path.clone())
2004+
}
2005+
}
20062006
}
20072007

2008-
impl Clean<Vec<Item>> for ast::ViewItem {
2008+
impl Clean<Vec<Item>> for doctree::Import {
20092009
fn clean(&self, cx: &DocContext) -> Vec<Item> {
20102010
// We consider inlining the documentation of `pub use` statements, but we
20112011
// forcefully don't inline if this is not public or if the
@@ -2016,81 +2016,60 @@ impl Clean<Vec<Item>> for ast::ViewItem {
20162016
None => false,
20172017
}
20182018
});
2019-
let convert = |node: &ast::ViewItem_| {
2020-
Item {
2021-
name: None,
2022-
attrs: self.attrs.clean(cx),
2023-
source: self.span.clean(cx),
2024-
def_id: ast_util::local_def(0),
2025-
visibility: self.vis.clean(cx),
2026-
stability: None,
2027-
inner: ViewItemItem(ViewItem { inner: node.clean(cx) }),
2019+
let (mut ret, inner) = match self.node {
2020+
ast::ViewPathGlob(ref p) => {
2021+
(vec![], GlobImport(resolve_use_source(cx, p.clean(cx), self.id)))
20282022
}
2029-
};
2030-
let mut ret = Vec::new();
2031-
match self.node {
2032-
ast::ViewItemUse(ref path) if !denied => {
2033-
match path.node {
2034-
ast::ViewPathGlob(..) => ret.push(convert(&self.node)),
2035-
ast::ViewPathList(ref a, ref list, ref b) => {
2036-
// Attempt to inline all reexported items, but be sure
2037-
// to keep any non-inlineable reexports so they can be
2038-
// listed in the documentation.
2039-
let remaining = list.iter().filter(|path| {
2040-
match inline::try_inline(cx, path.node.id(), None) {
2041-
Some(items) => {
2042-
ret.extend(items.into_iter()); false
2043-
}
2044-
None => true,
2023+
ast::ViewPathList(ref p, ref list) => {
2024+
// Attempt to inline all reexported items, but be sure
2025+
// to keep any non-inlineable reexports so they can be
2026+
// listed in the documentation.
2027+
let mut ret = vec![];
2028+
let remaining = if !denied {
2029+
list.iter().filter_map(|path| {
2030+
match inline::try_inline(cx, path.node.id(), None) {
2031+
Some(items) => {
2032+
ret.extend(items.into_iter());
2033+
None
20452034
}
2046-
}).map(|a| a.clone()).collect::<Vec<ast::PathListItem>>();
2047-
if remaining.len() > 0 {
2048-
let path = ast::ViewPathList(a.clone(),
2049-
remaining,
2050-
b.clone());
2051-
let path = syntax::codemap::dummy_spanned(path);
2052-
ret.push(convert(&ast::ViewItemUse(P(path))));
2053-
}
2054-
}
2055-
ast::ViewPathSimple(ident, _, id) => {
2056-
match inline::try_inline(cx, id, Some(ident)) {
2057-
Some(items) => ret.extend(items.into_iter()),
2058-
None => ret.push(convert(&self.node)),
2035+
None => Some(path.clean(cx))
20592036
}
2060-
}
2061-
}
2062-
}
2063-
ref n => ret.push(convert(n)),
2064-
}
2065-
return ret;
2066-
}
2067-
}
2068-
2069-
#[deriving(Clone, RustcEncodable, RustcDecodable)]
2070-
pub enum ViewItemInner {
2071-
ExternCrate(String, Option<String>, ast::NodeId),
2072-
Import(ViewPath)
2073-
}
2074-
2075-
impl Clean<ViewItemInner> for ast::ViewItem_ {
2076-
fn clean(&self, cx: &DocContext) -> ViewItemInner {
2077-
match self {
2078-
&ast::ViewItemExternCrate(ref i, ref p, ref id) => {
2079-
let string = match *p {
2080-
None => None,
2081-
Some((ref x, _)) => Some(x.get().to_string()),
2037+
}).collect::<Vec<_>>()
2038+
} else {
2039+
list.clean(cx)
20822040
};
2083-
ExternCrate(i.clean(cx), string, *id)
2041+
if remaining.is_empty() {
2042+
return ret;
2043+
}
2044+
(ret, ImportList(resolve_use_source(cx, p.clean(cx), self.id),
2045+
remaining))
20842046
}
2085-
&ast::ViewItemUse(ref vp) => {
2086-
Import(vp.clean(cx))
2047+
ast::ViewPathSimple(i, ref p) => {
2048+
if !denied {
2049+
match inline::try_inline(cx, self.id, Some(i)) {
2050+
Some(items) => return items,
2051+
None => {}
2052+
}
2053+
}
2054+
(vec![], SimpleImport(i.clean(cx),
2055+
resolve_use_source(cx, p.clean(cx), self.id)))
20872056
}
2088-
}
2057+
};
2058+
ret.push(Item {
2059+
name: None,
2060+
attrs: self.attrs.clean(cx),
2061+
source: self.whence.clean(cx),
2062+
def_id: ast_util::local_def(0),
2063+
visibility: self.vis.clean(cx),
2064+
stability: None,
2065+
inner: ImportItem(inner)
2066+
});
2067+
ret
20892068
}
20902069
}
20912070

20922071
#[deriving(Clone, RustcEncodable, RustcDecodable)]
2093-
pub enum ViewPath {
2072+
pub enum Import {
20942073
// use source as str;
20952074
SimpleImport(String, ImportSource),
20962075
// use source::*;
@@ -2105,21 +2084,6 @@ pub struct ImportSource {
21052084
pub did: Option<ast::DefId>,
21062085
}
21072086

2108-
impl Clean<ViewPath> for ast::ViewPath {
2109-
fn clean(&self, cx: &DocContext) -> ViewPath {
2110-
match self.node {
2111-
ast::ViewPathSimple(ref i, ref p, id) =>
2112-
SimpleImport(i.clean(cx), resolve_use_source(cx, p.clean(cx), id)),
2113-
ast::ViewPathGlob(ref p, id) =>
2114-
GlobImport(resolve_use_source(cx, p.clean(cx), id)),
2115-
ast::ViewPathList(ref p, ref pl, id) => {
2116-
ImportList(resolve_use_source(cx, p.clean(cx), id),
2117-
pl.clean(cx))
2118-
}
2119-
}
2120-
}
2121-
}
2122-
21232087
#[deriving(Clone, RustcEncodable, RustcDecodable)]
21242088
pub struct ViewListIdent {
21252089
pub name: String,

src/librustdoc/doctree.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub struct Module {
2525
pub attrs: Vec<ast::Attribute>,
2626
pub where_outer: Span,
2727
pub where_inner: Span,
28+
pub extern_crates: Vec<ExternCrate>,
29+
pub imports: Vec<Import>,
2830
pub structs: Vec<Struct>,
2931
pub enums: Vec<Enum>,
3032
pub fns: Vec<Function>,
@@ -38,7 +40,6 @@ pub struct Module {
3840
pub stab: Option<attr::Stability>,
3941
pub impls: Vec<Impl>,
4042
pub foreigns: Vec<ast::ForeignMod>,
41-
pub view_items: Vec<ast::ViewItem>,
4243
pub macros: Vec<Macro>,
4344
pub is_crate: bool,
4445
}
@@ -53,6 +54,8 @@ impl Module {
5354
where_outer: syntax::codemap::DUMMY_SP,
5455
where_inner: syntax::codemap::DUMMY_SP,
5556
attrs : Vec::new(),
57+
extern_crates: Vec::new(),
58+
imports : Vec::new(),
5659
structs : Vec::new(),
5760
enums : Vec::new(),
5861
fns : Vec::new(),
@@ -62,7 +65,6 @@ impl Module {
6265
constants : Vec::new(),
6366
traits : Vec::new(),
6467
impls : Vec::new(),
65-
view_items : Vec::new(),
6668
foreigns : Vec::new(),
6769
macros : Vec::new(),
6870
is_crate : false,
@@ -201,6 +203,22 @@ pub struct Macro {
201203
pub stab: Option<attr::Stability>,
202204
}
203205

206+
pub struct ExternCrate {
207+
pub name: Ident,
208+
pub path: Option<String>,
209+
pub vis: ast::Visibility,
210+
pub attrs: Vec<ast::Attribute>,
211+
pub whence: Span,
212+
}
213+
214+
pub struct Import {
215+
pub id: NodeId,
216+
pub vis: ast::Visibility,
217+
pub attrs: Vec<ast::Attribute>,
218+
pub node: ast::ViewPath_,
219+
pub whence: Span,
220+
}
221+
204222
pub fn struct_type_from_def(sd: &ast::StructDef) -> StructType {
205223
if sd.ctor_id.is_some() {
206224
// We are in a tuple-struct

src/librustdoc/html/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ impl fmt::Show for UnsafetySpace {
647647
}
648648
}
649649

650-
impl fmt::Show for clean::ViewPath {
650+
impl fmt::Show for clean::Import {
651651
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
652652
match *self {
653653
clean::SimpleImport(ref name, ref src) => {

src/librustdoc/html/item_type.rs

+21-19
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,31 @@ use clean;
2222
#[deriving(Copy, PartialEq, Clone)]
2323
pub enum ItemType {
2424
Module = 0,
25-
Struct = 1,
26-
Enum = 2,
27-
Function = 3,
28-
Typedef = 4,
29-
Static = 5,
30-
Trait = 6,
31-
Impl = 7,
32-
ViewItem = 8,
33-
TyMethod = 9,
34-
Method = 10,
35-
StructField = 11,
36-
Variant = 12,
37-
// we used to have ForeignFunction and ForeignStatic. they are retired now.
38-
Macro = 15,
39-
Primitive = 16,
40-
AssociatedType = 17,
41-
Constant = 18,
25+
ExternCrate = 1,
26+
Import = 2,
27+
Struct = 3,
28+
Enum = 4,
29+
Function = 5,
30+
Typedef = 6,
31+
Static = 7,
32+
Trait = 8,
33+
Impl = 9,
34+
TyMethod = 10,
35+
Method = 11,
36+
StructField = 12,
37+
Variant = 13,
38+
Macro = 14,
39+
Primitive = 15,
40+
AssociatedType = 16,
41+
Constant = 17,
4242
}
4343

4444
impl ItemType {
4545
pub fn from_item(item: &clean::Item) -> ItemType {
4646
match item.inner {
4747
clean::ModuleItem(..) => ItemType::Module,
48+
clean::ExternCrateItem(..) => ItemType::ExternCrate,
49+
clean::ImportItem(..) => ItemType::Import,
4850
clean::StructItem(..) => ItemType::Struct,
4951
clean::EnumItem(..) => ItemType::Enum,
5052
clean::FunctionItem(..) => ItemType::Function,
@@ -53,7 +55,6 @@ impl ItemType {
5355
clean::ConstantItem(..) => ItemType::Constant,
5456
clean::TraitItem(..) => ItemType::Trait,
5557
clean::ImplItem(..) => ItemType::Impl,
56-
clean::ViewItemItem(..) => ItemType::ViewItem,
5758
clean::TyMethodItem(..) => ItemType::TyMethod,
5859
clean::MethodItem(..) => ItemType::Method,
5960
clean::StructFieldItem(..) => ItemType::StructField,
@@ -83,14 +84,15 @@ impl ItemType {
8384
pub fn to_static_str(&self) -> &'static str {
8485
match *self {
8586
ItemType::Module => "mod",
87+
ItemType::ExternCrate => "externcrate",
88+
ItemType::Import => "import",
8689
ItemType::Struct => "struct",
8790
ItemType::Enum => "enum",
8891
ItemType::Function => "fn",
8992
ItemType::Typedef => "type",
9093
ItemType::Static => "static",
9194
ItemType::Trait => "trait",
9295
ItemType::Impl => "impl",
93-
ItemType::ViewItem => "viewitem",
9496
ItemType::TyMethod => "tymethod",
9597
ItemType::Method => "method",
9698
ItemType::StructField => "structfield",

0 commit comments

Comments
 (0)