Skip to content

Commit 3102b9e

Browse files
committed
rustdoc: fix fallout of merging ast::ViewItem into ast::Item.
1 parent f83a972 commit 3102b9e

File tree

10 files changed

+224
-250
lines changed

10 files changed

+224
-250
lines changed

src/librustdoc/clean/mod.rs

+78-111
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::*;
@@ -309,6 +308,8 @@ impl Item {
309308

310309
#[derive(Clone, RustcEncodable, RustcDecodable)]
311310
pub enum ItemEnum {
311+
ExternCrateItem(String, Option<String>),
312+
ImportItem(Import),
312313
StructItem(Struct),
313314
EnumItem(Enum),
314315
FunctionItem(Function),
@@ -318,8 +319,6 @@ pub enum ItemEnum {
318319
ConstantItem(Constant),
319320
TraitItem(Trait),
320321
ImplItem(Impl),
321-
/// `use` and `extern crate`
322-
ViewItemItem(ViewItem),
323322
/// A method signature only. Used for required methods in traits (ie,
324323
/// non-default-methods).
325324
TyMethodItem(TyMethod),
@@ -349,27 +348,21 @@ impl Clean<Item> for doctree::Module {
349348
} else {
350349
"".to_string()
351350
};
352-
let mut foreigns = Vec::new();
353-
for subforeigns in self.foreigns.clean(cx).into_iter() {
354-
for foreign in subforeigns.into_iter() {
355-
foreigns.push(foreign)
356-
}
357-
}
358-
let items: Vec<Vec<Item> > = vec!(
359-
self.structs.clean(cx),
360-
self.enums.clean(cx),
361-
self.fns.clean(cx),
362-
foreigns,
363-
self.mods.clean(cx),
364-
self.typedefs.clean(cx),
365-
self.statics.clean(cx),
366-
self.constants.clean(cx),
367-
self.traits.clean(cx),
368-
self.impls.clean(cx),
369-
self.view_items.clean(cx).into_iter()
370-
.flat_map(|s| s.into_iter()).collect(),
371-
self.macros.clean(cx),
372-
);
351+
let items: Vec<Item> =
352+
self.extern_crates.iter().map(|x| x.clean(cx))
353+
.chain(self.imports.iter().flat_map(|x| x.clean(cx).into_iter()))
354+
.chain(self.structs.iter().map(|x| x.clean(cx)))
355+
.chain(self.enums.iter().map(|x| x.clean(cx)))
356+
.chain(self.fns.iter().map(|x| x.clean(cx)))
357+
.chain(self.foreigns.iter().flat_map(|x| x.clean(cx).into_iter()))
358+
.chain(self.mods.iter().map(|x| x.clean(cx)))
359+
.chain(self.typedefs.iter().map(|x| x.clean(cx)))
360+
.chain(self.statics.iter().map(|x| x.clean(cx)))
361+
.chain(self.constants.iter().map(|x| x.clean(cx)))
362+
.chain(self.traits.iter().map(|x| x.clean(cx)))
363+
.chain(self.impls.iter().map(|x| x.clean(cx)))
364+
.chain(self.macros.iter().map(|x| x.clean(cx)))
365+
.collect();
373366

374367
// determine if we should display the inner contents or
375368
// the outer `mod` item for the source code.
@@ -395,9 +388,7 @@ impl Clean<Item> for doctree::Module {
395388
def_id: ast_util::local_def(self.id),
396389
inner: ModuleItem(Module {
397390
is_crate: self.is_crate,
398-
items: items.iter()
399-
.flat_map(|x| x.iter().map(|x| (*x).clone()))
400-
.collect(),
391+
items: items
401392
})
402393
}
403394
}
@@ -2120,12 +2111,21 @@ impl Clean<Item> for doctree::Impl {
21202111
}
21212112
}
21222113

2123-
#[derive(Clone, RustcEncodable, RustcDecodable)]
2124-
pub struct ViewItem {
2125-
pub inner: ViewItemInner,
2114+
impl Clean<Item> for doctree::ExternCrate {
2115+
fn clean(&self, cx: &DocContext) -> Item {
2116+
Item {
2117+
name: None,
2118+
attrs: self.attrs.clean(cx),
2119+
source: self.whence.clean(cx),
2120+
def_id: ast_util::local_def(0),
2121+
visibility: self.vis.clean(cx),
2122+
stability: None,
2123+
inner: ExternCrateItem(self.name.clean(cx), self.path.clone())
2124+
}
2125+
}
21262126
}
21272127

2128-
impl Clean<Vec<Item>> for ast::ViewItem {
2128+
impl Clean<Vec<Item>> for doctree::Import {
21292129
fn clean(&self, cx: &DocContext) -> Vec<Item> {
21302130
// We consider inlining the documentation of `pub use` statements, but we
21312131
// forcefully don't inline if this is not public or if the
@@ -2136,81 +2136,63 @@ impl Clean<Vec<Item>> for ast::ViewItem {
21362136
None => false,
21372137
}
21382138
});
2139-
let convert = |&: node: &ast::ViewItem_| {
2140-
Item {
2141-
name: None,
2142-
attrs: self.attrs.clean(cx),
2143-
source: self.span.clean(cx),
2144-
def_id: ast_util::local_def(0),
2145-
visibility: self.vis.clean(cx),
2146-
stability: None,
2147-
inner: ViewItemItem(ViewItem { inner: node.clean(cx) }),
2139+
let (mut ret, inner) = match self.node {
2140+
ast::ViewPathGlob(ref p) => {
2141+
(vec![], GlobImport(resolve_use_source(cx, p.clean(cx), self.id)))
21482142
}
2149-
};
2150-
let mut ret = Vec::new();
2151-
match self.node {
2152-
ast::ViewItemUse(ref path) if !denied => {
2153-
match path.node {
2154-
ast::ViewPathGlob(..) => ret.push(convert(&self.node)),
2155-
ast::ViewPathList(ref a, ref list, ref b) => {
2156-
// Attempt to inline all reexported items, but be sure
2157-
// to keep any non-inlineable reexports so they can be
2158-
// listed in the documentation.
2159-
let remaining = list.iter().filter(|path| {
2160-
match inline::try_inline(cx, path.node.id(), None) {
2161-
Some(items) => {
2162-
ret.extend(items.into_iter()); false
2163-
}
2164-
None => true,
2143+
ast::ViewPathList(ref p, ref list) => {
2144+
// Attempt to inline all reexported items, but be sure
2145+
// to keep any non-inlineable reexports so they can be
2146+
// listed in the documentation.
2147+
let mut ret = vec![];
2148+
let remaining = if !denied {
2149+
let mut remaining = vec![];
2150+
for path in list.iter() {
2151+
match inline::try_inline(cx, path.node.id(), None) {
2152+
Some(items) => {
2153+
ret.extend(items.into_iter());
2154+
}
2155+
None => {
2156+
remaining.push(path.clean(cx));
21652157
}
2166-
}).map(|a| a.clone()).collect::<Vec<ast::PathListItem>>();
2167-
if remaining.len() > 0 {
2168-
let path = ast::ViewPathList(a.clone(),
2169-
remaining,
2170-
b.clone());
2171-
let path = syntax::codemap::dummy_spanned(path);
2172-
ret.push(convert(&ast::ViewItemUse(P(path))));
2173-
}
2174-
}
2175-
ast::ViewPathSimple(ident, _, id) => {
2176-
match inline::try_inline(cx, id, Some(ident)) {
2177-
Some(items) => ret.extend(items.into_iter()),
2178-
None => ret.push(convert(&self.node)),
21792158
}
21802159
}
2181-
}
2182-
}
2183-
ref n => ret.push(convert(n)),
2184-
}
2185-
return ret;
2186-
}
2187-
}
2188-
2189-
#[derive(Clone, RustcEncodable, RustcDecodable)]
2190-
pub enum ViewItemInner {
2191-
ExternCrate(String, Option<String>, ast::NodeId),
2192-
Import(ViewPath)
2193-
}
2194-
2195-
impl Clean<ViewItemInner> for ast::ViewItem_ {
2196-
fn clean(&self, cx: &DocContext) -> ViewItemInner {
2197-
match self {
2198-
&ast::ViewItemExternCrate(ref i, ref p, ref id) => {
2199-
let string = match *p {
2200-
None => None,
2201-
Some((ref x, _)) => Some(x.get().to_string()),
2160+
remaining
2161+
} else {
2162+
list.clean(cx)
22022163
};
2203-
ExternCrate(i.clean(cx), string, *id)
2164+
if remaining.is_empty() {
2165+
return ret;
2166+
}
2167+
(ret, ImportList(resolve_use_source(cx, p.clean(cx), self.id),
2168+
remaining))
22042169
}
2205-
&ast::ViewItemUse(ref vp) => {
2206-
Import(vp.clean(cx))
2170+
ast::ViewPathSimple(i, ref p) => {
2171+
if !denied {
2172+
match inline::try_inline(cx, self.id, Some(i)) {
2173+
Some(items) => return items,
2174+
None => {}
2175+
}
2176+
}
2177+
(vec![], SimpleImport(i.clean(cx),
2178+
resolve_use_source(cx, p.clean(cx), self.id)))
22072179
}
2208-
}
2180+
};
2181+
ret.push(Item {
2182+
name: None,
2183+
attrs: self.attrs.clean(cx),
2184+
source: self.whence.clean(cx),
2185+
def_id: ast_util::local_def(0),
2186+
visibility: self.vis.clean(cx),
2187+
stability: None,
2188+
inner: ImportItem(inner)
2189+
});
2190+
ret
22092191
}
22102192
}
22112193

22122194
#[derive(Clone, RustcEncodable, RustcDecodable)]
2213-
pub enum ViewPath {
2195+
pub enum Import {
22142196
// use source as str;
22152197
SimpleImport(String, ImportSource),
22162198
// use source::*;
@@ -2225,21 +2207,6 @@ pub struct ImportSource {
22252207
pub did: Option<ast::DefId>,
22262208
}
22272209

2228-
impl Clean<ViewPath> for ast::ViewPath {
2229-
fn clean(&self, cx: &DocContext) -> ViewPath {
2230-
match self.node {
2231-
ast::ViewPathSimple(ref i, ref p, id) =>
2232-
SimpleImport(i.clean(cx), resolve_use_source(cx, p.clean(cx), id)),
2233-
ast::ViewPathGlob(ref p, id) =>
2234-
GlobImport(resolve_use_source(cx, p.clean(cx), id)),
2235-
ast::ViewPathList(ref p, ref pl, id) => {
2236-
ImportList(resolve_use_source(cx, p.clean(cx), id),
2237-
pl.clean(cx))
2238-
}
2239-
}
2240-
}
2241-
}
2242-
22432210
#[derive(Clone, RustcEncodable, RustcDecodable)]
22442211
pub struct ViewListIdent {
22452212
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,
@@ -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

+1-1
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ impl fmt::String for UnsafetySpace {
617617
}
618618
}
619619

620-
impl fmt::String for clean::ViewPath {
620+
impl fmt::String for clean::Import {
621621
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
622622
match *self {
623623
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
#[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)