librustdoc: Fix errors arising from the automated ~[T] conversion

This commit is contained in:
Patrick Walton 2014-02-28 17:46:09 -08:00
parent c1ed4d7d41
commit 0c6622aa0f
2 changed files with 97 additions and 55 deletions

View File

@ -29,6 +29,7 @@
use doctree;
use visit_ast;
use std::local_data;
use std::vec_ng::Vec;
pub trait Clean<T> {
fn clean(&self) -> T;
@ -39,6 +40,13 @@ fn clean(&self) -> ~[U] {
self.iter().map(|x| x.clean()).collect()
}
}
impl<T: Clean<U>, U> Clean<Vec<U>> for Vec<T> {
fn clean(&self) -> Vec<U> {
self.iter().map(|x| x.clean()).collect()
}
}
impl<T: Clean<U>, U> Clean<U> for @T {
fn clean(&self) -> U {
(**self).clean()
@ -54,10 +62,10 @@ fn clean(&self) -> Option<U> {
}
}
impl<T: Clean<U>, U> Clean<~[U]> for syntax::opt_vec::OptVec<T> {
fn clean(&self) -> ~[U] {
impl<T: Clean<U>, U> Clean<Vec<U>> for syntax::opt_vec::OptVec<T> {
fn clean(&self) -> Vec<U> {
match self {
&syntax::opt_vec::Empty => ~[],
&syntax::opt_vec::Empty => Vec::new(),
&syntax::opt_vec::Vec(ref v) => v.clean()
}
}
@ -196,6 +204,25 @@ fn clean(&self) -> Item {
} else {
~""
};
let mut foreigns = ~[];
for subforeigns in self.foreigns.clean().move_iter() {
for foreign in subforeigns.move_iter() {
foreigns.push(foreign)
}
}
let items: ~[~[Item]] = ~[
self.structs.clean().move_iter().collect(),
self.enums.clean().move_iter().collect(),
self.fns.clean().move_iter().collect(),
foreigns,
self.mods.clean().move_iter().collect(),
self.typedefs.clean().move_iter().collect(),
self.statics.clean().move_iter().collect(),
self.traits.clean().move_iter().collect(),
self.impls.clean().move_iter().collect(),
self.view_items.clean().move_iter().collect(),
self.macros.clean().move_iter().collect()
];
Item {
name: Some(name),
attrs: self.attrs.clean(),
@ -204,12 +231,7 @@ fn clean(&self) -> Item {
id: self.id,
inner: ModuleItem(Module {
is_crate: self.is_crate,
items: [self.structs.clean(), self.enums.clean(),
self.fns.clean(), self.foreigns.clean().concat_vec(),
self.mods.clean(), self.typedefs.clean(),
self.statics.clean(), self.traits.clean(),
self.impls.clean(), self.view_items.clean(),
self.macros.clean()].concat_vec()
items: items.concat_vec(),
})
}
}
@ -227,7 +249,7 @@ fn clean(&self) -> Attribute {
match self.node {
ast::MetaWord(ref s) => Word(s.get().to_owned()),
ast::MetaList(ref s, ref l) => {
List(s.get().to_owned(), l.clean())
List(s.get().to_owned(), l.clean().move_iter().collect())
}
ast::MetaNameValue(ref s, ref v) => {
NameValue(s.get().to_owned(), lit_to_str(v))
@ -276,7 +298,7 @@ fn clean(&self) -> TyParam {
TyParam {
name: self.ident.clean(),
id: self.id,
bounds: self.bounds.clean(),
bounds: self.bounds.clean().move_iter().collect(),
}
}
}
@ -323,8 +345,8 @@ pub struct Generics {
impl Clean<Generics> for ast::Generics {
fn clean(&self) -> Generics {
Generics {
lifetimes: self.lifetimes.clean(),
type_params: self.ty_params.clean(),
lifetimes: self.lifetimes.clean().move_iter().collect(),
type_params: self.ty_params.clean().move_iter().collect(),
}
}
}
@ -353,7 +375,7 @@ fn clean(&self) -> Item {
};
Item {
name: Some(self.ident.clean()),
attrs: self.attrs.clean(),
attrs: self.attrs.clean().move_iter().collect(),
source: self.span.clean(),
id: self.id.clone(),
visibility: self.vis.clean(),
@ -391,7 +413,7 @@ fn clean(&self) -> Item {
};
Item {
name: Some(self.ident.clean()),
attrs: self.attrs.clean(),
attrs: self.attrs.clean().move_iter().collect(),
source: self.span.clean(),
id: self.id,
visibility: None,
@ -464,12 +486,12 @@ fn clean(&self) -> ClosureDecl {
ClosureDecl {
sigil: self.sigil,
region: self.region.clean(),
lifetimes: self.lifetimes.clean(),
lifetimes: self.lifetimes.clean().move_iter().collect(),
decl: self.decl.clean(),
onceness: self.onceness,
purity: self.purity,
bounds: match self.bounds {
Some(ref x) => x.clean(),
Some(ref x) => x.clean().move_iter().collect(),
None => ~[]
},
}
@ -673,8 +695,11 @@ fn clean(&self) -> Type {
TyFixedLengthVec(ty, ref e) => FixedVector(~ty.clean(),
e.span.to_src()),
TyTup(ref tys) => Tuple(tys.iter().map(|x| x.clean()).collect()),
TyPath(ref p, ref tpbs, id) =>
resolve_type(p.clean(), tpbs.clean(), id),
TyPath(ref p, ref tpbs, id) => {
resolve_type(p.clean(),
tpbs.clean().map(|x| x.move_iter().collect()),
id)
}
TyClosure(ref c) => Closure(~c.clean()),
TyBareFn(ref barefn) => BareFunction(~barefn.clean()),
TyBot => Bottom,
@ -696,7 +721,7 @@ fn clean(&self) -> Item {
};
Item {
name: name.clean(),
attrs: self.node.attrs.clean(),
attrs: self.node.attrs.clean().move_iter().collect(),
source: self.span.clean(),
visibility: vis,
id: self.node.id,
@ -755,7 +780,7 @@ impl Clean<VariantStruct> for syntax::ast::StructDef {
fn clean(&self) -> VariantStruct {
VariantStruct {
struct_type: doctree::struct_type_from_def(self),
fields: self.fields.clean(),
fields: self.fields.clean().move_iter().collect(),
fields_stripped: false,
}
}
@ -862,7 +887,7 @@ impl Clean<Path> for ast::Path {
fn clean(&self) -> Path {
Path {
global: self.global,
segments: self.segments.clean()
segments: self.segments.clean().move_iter().collect(),
}
}
}
@ -878,8 +903,8 @@ impl Clean<PathSegment> for ast::PathSegment {
fn clean(&self) -> PathSegment {
PathSegment {
name: self.identifier.clean(),
lifetimes: self.lifetimes.clean(),
types: self.types.clean()
lifetimes: self.lifetimes.clean().move_iter().collect(),
types: self.types.clean().move_iter().collect()
}
}
}
@ -941,7 +966,7 @@ fn clean(&self) -> BareFunctionDecl {
BareFunctionDecl {
purity: self.purity,
generics: Generics {
lifetimes: self.lifetimes.clean(),
lifetimes: self.lifetimes.clean().move_iter().collect(),
type_params: ~[],
},
decl: self.decl.clean(),
@ -1028,7 +1053,7 @@ impl Clean<Item> for ast::ViewItem {
fn clean(&self) -> Item {
Item {
name: None,
attrs: self.attrs.clean(),
attrs: self.attrs.clean().move_iter().collect(),
source: self.span.clean(),
id: 0,
visibility: self.vis.clean(),
@ -1055,7 +1080,9 @@ fn clean(&self) -> ViewItemInner {
};
ExternMod(i.clean(), string, *id)
}
&ast::ViewItemUse(ref vp) => Import(vp.clean())
&ast::ViewItemUse(ref vp) => {
Import(vp.clean().move_iter().collect())
}
}
}
}
@ -1083,8 +1110,10 @@ fn clean(&self) -> ViewPath {
SimpleImport(i.clean(), resolve_use_source(p.clean(), id)),
ast::ViewPathGlob(ref p, id) =>
GlobImport(resolve_use_source(p.clean(), id)),
ast::ViewPathList(ref p, ref pl, id) =>
ImportList(resolve_use_source(p.clean(), id), pl.clean()),
ast::ViewPathList(ref p, ref pl, id) => {
ImportList(resolve_use_source(p.clean(), id),
pl.clean().move_iter().collect())
}
}
}
}
@ -1104,8 +1133,8 @@ fn clean(&self) -> ViewListIdent {
}
}
impl Clean<~[Item]> for ast::ForeignMod {
fn clean(&self) -> ~[Item] {
impl Clean<Vec<Item>> for ast::ForeignMod {
fn clean(&self) -> Vec<Item> {
self.items.clean()
}
}
@ -1130,7 +1159,7 @@ fn clean(&self) -> Item {
};
Item {
name: Some(self.ident.clean()),
attrs: self.attrs.clean(),
attrs: self.attrs.clean().move_iter().collect(),
source: self.span.clean(),
id: self.id,
visibility: self.vis.clean(),

View File

@ -11,6 +11,7 @@
//! Rust AST Visitor. Extracts useful information and massages it into a form
//! usable for clean
use std::vec_ng::Vec;
use syntax::abi::AbiSet;
use syntax::ast;
use syntax::ast_util;
@ -39,11 +40,17 @@ pub fn new<'b>(cx: &'b core::DocContext,
}
pub fn visit(&mut self, krate: &ast::Crate) {
self.attrs = krate.attrs.clone();
self.attrs = krate.attrs.iter().map(|x| (*x).clone()).collect();
self.module = self.visit_mod_contents(krate.span, krate.attrs.clone(),
ast::Public, ast::CRATE_NODE_ID,
&krate.module, None);
self.module = self.visit_mod_contents(krate.span,
krate.attrs
.iter()
.map(|x| *x)
.collect(),
ast::Public,
ast::CRATE_NODE_ID,
&krate.module,
None);
self.module.is_crate = true;
}
@ -56,9 +63,9 @@ pub fn visit_struct_def(&mut self, item: &ast::Item, sd: @ast::StructDef,
struct_type: struct_type,
name: item.ident,
vis: item.vis,
attrs: item.attrs.clone(),
attrs: item.attrs.iter().map(|x| *x).collect(),
generics: generics.clone(),
fields: sd.fields.clone(),
fields: sd.fields.iter().map(|x| (*x).clone()).collect(),
where: item.span
}
}
@ -70,7 +77,7 @@ pub fn visit_enum_def(&mut self, it: &ast::Item, def: &ast::EnumDef,
for x in def.variants.iter() {
vars.push(Variant {
name: x.node.name,
attrs: x.node.attrs.clone(),
attrs: x.node.attrs.iter().map(|x| *x).collect(),
vis: x.node.vis,
id: x.node.id,
kind: x.node.kind.clone(),
@ -82,7 +89,7 @@ pub fn visit_enum_def(&mut self, it: &ast::Item, def: &ast::EnumDef,
variants: vars,
vis: it.vis,
generics: params.clone(),
attrs: it.attrs.clone(),
attrs: it.attrs.iter().map(|x| *x).collect(),
id: it.id,
where: it.span,
}
@ -95,7 +102,7 @@ pub fn visit_fn(&mut self, item: &ast::Item, fd: &ast::FnDecl,
Function {
id: item.id,
vis: item.vis,
attrs: item.attrs.clone(),
attrs: item.attrs.iter().map(|x| *x).collect(),
decl: fd.clone(),
name: item.ident,
where: item.span,
@ -130,11 +137,11 @@ pub fn visit_view_item(&mut self, item: &ast::ViewItem, om: &mut Module) {
ast::ViewItemUse(ref paths) => {
// rustc no longer supports "use foo, bar;"
assert_eq!(paths.len(), 1);
match self.visit_view_path(paths[0], om) {
match self.visit_view_path(*paths.get(0), om) {
None => return,
Some(path) => {
ast::ViewItem {
node: ast::ViewItemUse(~[path]),
node: ast::ViewItemUse(vec!(path)),
.. item.clone()
}
}
@ -152,7 +159,7 @@ fn visit_view_path(&mut self, path: @ast::ViewPath,
if self.resolve_id(id, false, om) { return None }
}
ast::ViewPathList(ref p, ref paths, ref b) => {
let mut mine = ~[];
let mut mine = Vec::new();
for path in paths.iter() {
if !self.resolve_id(path.node.id, false, om) {
mine.push(path.clone());
@ -217,9 +224,15 @@ pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) {
debug!("Visiting item {:?}", item);
match item.node {
ast::ItemMod(ref m) => {
om.mods.push(self.visit_mod_contents(item.span, item.attrs.clone(),
item.vis, item.id, m,
Some(item.ident)));
om.mods.push(self.visit_mod_contents(item.span,
item.attrs
.iter()
.map(|x| *x)
.collect(),
item.vis,
item.id,
m,
Some(item.ident)));
},
ast::ItemEnum(ref ed, ref gen) =>
om.enums.push(self.visit_enum_def(item, ed, gen)),
@ -233,7 +246,7 @@ pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) {
gen: gen.clone(),
name: item.ident,
id: item.id,
attrs: item.attrs.clone(),
attrs: item.attrs.iter().map(|x| *x).collect(),
where: item.span,
vis: item.vis,
};
@ -246,7 +259,7 @@ pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) {
expr: exp.clone(),
id: item.id,
name: item.ident,
attrs: item.attrs.clone(),
attrs: item.attrs.iter().map(|x| *x).collect(),
where: item.span,
vis: item.vis,
};
@ -255,11 +268,11 @@ pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) {
ast::ItemTrait(ref gen, ref tr, ref met) => {
let t = Trait {
name: item.ident,
methods: met.clone(),
methods: met.iter().map(|x| (*x).clone()).collect(),
generics: gen.clone(),
parents: tr.clone(),
parents: tr.iter().map(|x| (*x).clone()).collect(),
id: item.id,
attrs: item.attrs.clone(),
attrs: item.attrs.iter().map(|x| *x).collect(),
where: item.span,
vis: item.vis,
};
@ -270,8 +283,8 @@ pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) {
generics: gen.clone(),
trait_: tr.clone(),
for_: ty,
methods: meths.clone(),
attrs: item.attrs.clone(),
methods: meths.iter().map(|x| *x).collect(),
attrs: item.attrs.iter().map(|x| *x).collect(),
id: item.id,
where: item.span,
vis: item.vis,
@ -284,7 +297,7 @@ pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) {
ast::ItemMac(ref _m) => {
om.macros.push(Macro {
id: item.id,
attrs: item.attrs.clone(),
attrs: item.attrs.iter().map(|x| *x).collect(),
name: item.ident,
where: item.span,
})