Skip to content

Commit 99e8c9f

Browse files
committed
rustdoc: fix fallout of merging ast::ViewItem into ast::Item.
1 parent dea67eb commit 99e8c9f

File tree

10 files changed

+224
-250
lines changed

10 files changed

+224
-250
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 78 additions & 111 deletions
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::*;
@@ -303,6 +302,8 @@ impl Item {
303302

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

368361
// determine if we should display the inner contents or
369362
// the outer `mod` item for the source code.
@@ -389,9 +382,7 @@ impl Clean<Item> for doctree::Module {
389382
def_id: ast_util::local_def(self.id),
390383
inner: ModuleItem(Module {
391384
is_crate: self.is_crate,
392-
items: items.iter()
393-
.flat_map(|x| x.iter().map(|x| (*x).clone()))
394-
.collect(),
385+
items: items
395386
})
396387
}
397388
}
@@ -1989,12 +1980,21 @@ impl Clean<Item> for doctree::Impl {
19891980
}
19901981
}
19911982

1992-
#[derive(Clone, RustcEncodable, RustcDecodable)]
1993-
pub struct ViewItem {
1994-
pub inner: ViewItemInner,
1983+
impl Clean<Item> for doctree::ExternCrate {
1984+
fn clean(&self, cx: &DocContext) -> Item {
1985+
Item {
1986+
name: None,
1987+
attrs: self.attrs.clean(cx),
1988+
source: self.whence.clean(cx),
1989+
def_id: ast_util::local_def(0),
1990+
visibility: self.vis.clean(cx),
1991+
stability: None,
1992+
inner: ExternCrateItem(self.name.clean(cx), self.path.clone())
1993+
}
1994+
}
19951995
}
19961996

1997-
impl Clean<Vec<Item>> for ast::ViewItem {
1997+
impl Clean<Vec<Item>> for doctree::Import {
19981998
fn clean(&self, cx: &DocContext) -> Vec<Item> {
19991999
// We consider inlining the documentation of `pub use` statements, but we
20002000
// forcefully don't inline if this is not public or if the
@@ -2005,81 +2005,63 @@ impl Clean<Vec<Item>> for ast::ViewItem {
20052005
None => false,
20062006
}
20072007
});
2008-
let convert = |&: node: &ast::ViewItem_| {
2009-
Item {
2010-
name: None,
2011-
attrs: self.attrs.clean(cx),
2012-
source: self.span.clean(cx),
2013-
def_id: ast_util::local_def(0),
2014-
visibility: self.vis.clean(cx),
2015-
stability: None,
2016-
inner: ViewItemItem(ViewItem { inner: node.clean(cx) }),
2008+
let (mut ret, inner) = match self.node {
2009+
ast::ViewPathGlob(ref p) => {
2010+
(vec![], GlobImport(resolve_use_source(cx, p.clean(cx), self.id)))
20172011
}
2018-
};
2019-
let mut ret = Vec::new();
2020-
match self.node {
2021-
ast::ViewItemUse(ref path) if !denied => {
2022-
match path.node {
2023-
ast::ViewPathGlob(..) => ret.push(convert(&self.node)),
2024-
ast::ViewPathList(ref a, ref list, ref b) => {
2025-
// Attempt to inline all reexported items, but be sure
2026-
// to keep any non-inlineable reexports so they can be
2027-
// listed in the documentation.
2028-
let remaining = list.iter().filter(|path| {
2029-
match inline::try_inline(cx, path.node.id(), None) {
2030-
Some(items) => {
2031-
ret.extend(items.into_iter()); false
2032-
}
2033-
None => true,
2012+
ast::ViewPathList(ref p, ref list) => {
2013+
// Attempt to inline all reexported items, but be sure
2014+
// to keep any non-inlineable reexports so they can be
2015+
// listed in the documentation.
2016+
let mut ret = vec![];
2017+
let remaining = if !denied {
2018+
let mut remaining = vec![];
2019+
for path in list.iter() {
2020+
match inline::try_inline(cx, path.node.id(), None) {
2021+
Some(items) => {
2022+
ret.extend(items.into_iter());
2023+
}
2024+
None => {
2025+
remaining.push(path.clean(cx));
20342026
}
2035-
}).map(|a| a.clone()).collect::<Vec<ast::PathListItem>>();
2036-
if remaining.len() > 0 {
2037-
let path = ast::ViewPathList(a.clone(),
2038-
remaining,
2039-
b.clone());
2040-
let path = syntax::codemap::dummy_spanned(path);
2041-
ret.push(convert(&ast::ViewItemUse(P(path))));
2042-
}
2043-
}
2044-
ast::ViewPathSimple(ident, _, id) => {
2045-
match inline::try_inline(cx, id, Some(ident)) {
2046-
Some(items) => ret.extend(items.into_iter()),
2047-
None => ret.push(convert(&self.node)),
20482027
}
20492028
}
2050-
}
2051-
}
2052-
ref n => ret.push(convert(n)),
2053-
}
2054-
return ret;
2055-
}
2056-
}
2057-
2058-
#[derive(Clone, RustcEncodable, RustcDecodable)]
2059-
pub enum ViewItemInner {
2060-
ExternCrate(String, Option<String>, ast::NodeId),
2061-
Import(ViewPath)
2062-
}
2063-
2064-
impl Clean<ViewItemInner> for ast::ViewItem_ {
2065-
fn clean(&self, cx: &DocContext) -> ViewItemInner {
2066-
match self {
2067-
&ast::ViewItemExternCrate(ref i, ref p, ref id) => {
2068-
let string = match *p {
2069-
None => None,
2070-
Some((ref x, _)) => Some(x.get().to_string()),
2029+
remaining
2030+
} else {
2031+
list.clean(cx)
20712032
};
2072-
ExternCrate(i.clean(cx), string, *id)
2033+
if remaining.is_empty() {
2034+
return ret;
2035+
}
2036+
(ret, ImportList(resolve_use_source(cx, p.clean(cx), self.id),
2037+
remaining))
20732038
}
2074-
&ast::ViewItemUse(ref vp) => {
2075-
Import(vp.clean(cx))
2039+
ast::ViewPathSimple(i, ref p) => {
2040+
if !denied {
2041+
match inline::try_inline(cx, self.id, Some(i)) {
2042+
Some(items) => return items,
2043+
None => {}
2044+
}
2045+
}
2046+
(vec![], SimpleImport(i.clean(cx),
2047+
resolve_use_source(cx, p.clean(cx), self.id)))
20762048
}
2077-
}
2049+
};
2050+
ret.push(Item {
2051+
name: None,
2052+
attrs: self.attrs.clean(cx),
2053+
source: self.whence.clean(cx),
2054+
def_id: ast_util::local_def(0),
2055+
visibility: self.vis.clean(cx),
2056+
stability: None,
2057+
inner: ImportItem(inner)
2058+
});
2059+
ret
20782060
}
20792061
}
20802062

20812063
#[derive(Clone, RustcEncodable, RustcDecodable)]
2082-
pub enum ViewPath {
2064+
pub enum Import {
20832065
// use source as str;
20842066
SimpleImport(String, ImportSource),
20852067
// use source::*;
@@ -2094,21 +2076,6 @@ pub struct ImportSource {
20942076
pub did: Option<ast::DefId>,
20952077
}
20962078

2097-
impl Clean<ViewPath> for ast::ViewPath {
2098-
fn clean(&self, cx: &DocContext) -> ViewPath {
2099-
match self.node {
2100-
ast::ViewPathSimple(ref i, ref p, id) =>
2101-
SimpleImport(i.clean(cx), resolve_use_source(cx, p.clean(cx), id)),
2102-
ast::ViewPathGlob(ref p, id) =>
2103-
GlobImport(resolve_use_source(cx, p.clean(cx), id)),
2104-
ast::ViewPathList(ref p, ref pl, id) => {
2105-
ImportList(resolve_use_source(cx, p.clean(cx), id),
2106-
pl.clean(cx))
2107-
}
2108-
}
2109-
}
2110-
}
2111-
21122079
#[derive(Clone, RustcEncodable, RustcDecodable)]
21132080
pub struct ViewListIdent {
21142081
pub name: String,

src/librustdoc/doctree.rs

Lines changed: 20 additions & 2 deletions
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,
@@ -202,6 +204,22 @@ pub struct Macro {
202204
pub stab: Option<attr::Stability>,
203205
}
204206

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

src/librustdoc/html/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ impl fmt::String for UnsafetySpace {
671671
}
672672
}
673673

674-
impl fmt::String for clean::ViewPath {
674+
impl fmt::String for clean::Import {
675675
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
676676
match *self {
677677
clean::SimpleImport(ref name, ref src) => {

src/librustdoc/html/item_type.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,31 @@ use clean;
2222
#[derive(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)