提交 0c6622aa 编写于 作者: P Patrick Walton

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

上级 c1ed4d7d
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
use doctree; use doctree;
use visit_ast; use visit_ast;
use std::local_data; use std::local_data;
use std::vec_ng::Vec;
pub trait Clean<T> { pub trait Clean<T> {
fn clean(&self) -> T; fn clean(&self) -> T;
...@@ -39,6 +40,13 @@ fn clean(&self) -> ~[U] { ...@@ -39,6 +40,13 @@ fn clean(&self) -> ~[U] {
self.iter().map(|x| x.clean()).collect() 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 { impl<T: Clean<U>, U> Clean<U> for @T {
fn clean(&self) -> U { fn clean(&self) -> U {
(**self).clean() (**self).clean()
...@@ -54,10 +62,10 @@ fn clean(&self) -> Option<U> { ...@@ -54,10 +62,10 @@ fn clean(&self) -> Option<U> {
} }
} }
impl<T: Clean<U>, U> Clean<~[U]> for syntax::opt_vec::OptVec<T> { impl<T: Clean<U>, U> Clean<Vec<U>> for syntax::opt_vec::OptVec<T> {
fn clean(&self) -> ~[U] { fn clean(&self) -> Vec<U> {
match self { match self {
&syntax::opt_vec::Empty => ~[], &syntax::opt_vec::Empty => Vec::new(),
&syntax::opt_vec::Vec(ref v) => v.clean() &syntax::opt_vec::Vec(ref v) => v.clean()
} }
} }
...@@ -196,6 +204,25 @@ fn clean(&self) -> Item { ...@@ -196,6 +204,25 @@ fn clean(&self) -> Item {
} else { } 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 { Item {
name: Some(name), name: Some(name),
attrs: self.attrs.clean(), attrs: self.attrs.clean(),
...@@ -204,12 +231,7 @@ fn clean(&self) -> Item { ...@@ -204,12 +231,7 @@ fn clean(&self) -> Item {
id: self.id, id: self.id,
inner: ModuleItem(Module { inner: ModuleItem(Module {
is_crate: self.is_crate, is_crate: self.is_crate,
items: [self.structs.clean(), self.enums.clean(), items: items.concat_vec(),
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()
}) })
} }
} }
...@@ -227,7 +249,7 @@ fn clean(&self) -> Attribute { ...@@ -227,7 +249,7 @@ fn clean(&self) -> Attribute {
match self.node { match self.node {
ast::MetaWord(ref s) => Word(s.get().to_owned()), ast::MetaWord(ref s) => Word(s.get().to_owned()),
ast::MetaList(ref s, ref l) => { 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) => { ast::MetaNameValue(ref s, ref v) => {
NameValue(s.get().to_owned(), lit_to_str(v)) NameValue(s.get().to_owned(), lit_to_str(v))
...@@ -276,7 +298,7 @@ fn clean(&self) -> TyParam { ...@@ -276,7 +298,7 @@ fn clean(&self) -> TyParam {
TyParam { TyParam {
name: self.ident.clean(), name: self.ident.clean(),
id: self.id, id: self.id,
bounds: self.bounds.clean(), bounds: self.bounds.clean().move_iter().collect(),
} }
} }
} }
...@@ -323,8 +345,8 @@ pub struct Generics { ...@@ -323,8 +345,8 @@ pub struct Generics {
impl Clean<Generics> for ast::Generics { impl Clean<Generics> for ast::Generics {
fn clean(&self) -> Generics { fn clean(&self) -> Generics {
Generics { Generics {
lifetimes: self.lifetimes.clean(), lifetimes: self.lifetimes.clean().move_iter().collect(),
type_params: self.ty_params.clean(), type_params: self.ty_params.clean().move_iter().collect(),
} }
} }
} }
...@@ -353,7 +375,7 @@ fn clean(&self) -> Item { ...@@ -353,7 +375,7 @@ fn clean(&self) -> Item {
}; };
Item { Item {
name: Some(self.ident.clean()), name: Some(self.ident.clean()),
attrs: self.attrs.clean(), attrs: self.attrs.clean().move_iter().collect(),
source: self.span.clean(), source: self.span.clean(),
id: self.id.clone(), id: self.id.clone(),
visibility: self.vis.clean(), visibility: self.vis.clean(),
...@@ -391,7 +413,7 @@ fn clean(&self) -> Item { ...@@ -391,7 +413,7 @@ fn clean(&self) -> Item {
}; };
Item { Item {
name: Some(self.ident.clean()), name: Some(self.ident.clean()),
attrs: self.attrs.clean(), attrs: self.attrs.clean().move_iter().collect(),
source: self.span.clean(), source: self.span.clean(),
id: self.id, id: self.id,
visibility: None, visibility: None,
...@@ -464,12 +486,12 @@ fn clean(&self) -> ClosureDecl { ...@@ -464,12 +486,12 @@ fn clean(&self) -> ClosureDecl {
ClosureDecl { ClosureDecl {
sigil: self.sigil, sigil: self.sigil,
region: self.region.clean(), region: self.region.clean(),
lifetimes: self.lifetimes.clean(), lifetimes: self.lifetimes.clean().move_iter().collect(),
decl: self.decl.clean(), decl: self.decl.clean(),
onceness: self.onceness, onceness: self.onceness,
purity: self.purity, purity: self.purity,
bounds: match self.bounds { bounds: match self.bounds {
Some(ref x) => x.clean(), Some(ref x) => x.clean().move_iter().collect(),
None => ~[] None => ~[]
}, },
} }
...@@ -673,8 +695,11 @@ fn clean(&self) -> Type { ...@@ -673,8 +695,11 @@ fn clean(&self) -> Type {
TyFixedLengthVec(ty, ref e) => FixedVector(~ty.clean(), TyFixedLengthVec(ty, ref e) => FixedVector(~ty.clean(),
e.span.to_src()), e.span.to_src()),
TyTup(ref tys) => Tuple(tys.iter().map(|x| x.clean()).collect()), TyTup(ref tys) => Tuple(tys.iter().map(|x| x.clean()).collect()),
TyPath(ref p, ref tpbs, id) => TyPath(ref p, ref tpbs, id) => {
resolve_type(p.clean(), tpbs.clean(), id), resolve_type(p.clean(),
tpbs.clean().map(|x| x.move_iter().collect()),
id)
}
TyClosure(ref c) => Closure(~c.clean()), TyClosure(ref c) => Closure(~c.clean()),
TyBareFn(ref barefn) => BareFunction(~barefn.clean()), TyBareFn(ref barefn) => BareFunction(~barefn.clean()),
TyBot => Bottom, TyBot => Bottom,
...@@ -696,7 +721,7 @@ fn clean(&self) -> Item { ...@@ -696,7 +721,7 @@ fn clean(&self) -> Item {
}; };
Item { Item {
name: name.clean(), name: name.clean(),
attrs: self.node.attrs.clean(), attrs: self.node.attrs.clean().move_iter().collect(),
source: self.span.clean(), source: self.span.clean(),
visibility: vis, visibility: vis,
id: self.node.id, id: self.node.id,
...@@ -755,7 +780,7 @@ impl Clean<VariantStruct> for syntax::ast::StructDef { ...@@ -755,7 +780,7 @@ impl Clean<VariantStruct> for syntax::ast::StructDef {
fn clean(&self) -> VariantStruct { fn clean(&self) -> VariantStruct {
VariantStruct { VariantStruct {
struct_type: doctree::struct_type_from_def(self), struct_type: doctree::struct_type_from_def(self),
fields: self.fields.clean(), fields: self.fields.clean().move_iter().collect(),
fields_stripped: false, fields_stripped: false,
} }
} }
...@@ -862,7 +887,7 @@ impl Clean<Path> for ast::Path { ...@@ -862,7 +887,7 @@ impl Clean<Path> for ast::Path {
fn clean(&self) -> Path { fn clean(&self) -> Path {
Path { Path {
global: self.global, global: self.global,
segments: self.segments.clean() segments: self.segments.clean().move_iter().collect(),
} }
} }
} }
...@@ -878,8 +903,8 @@ impl Clean<PathSegment> for ast::PathSegment { ...@@ -878,8 +903,8 @@ impl Clean<PathSegment> for ast::PathSegment {
fn clean(&self) -> PathSegment { fn clean(&self) -> PathSegment {
PathSegment { PathSegment {
name: self.identifier.clean(), name: self.identifier.clean(),
lifetimes: self.lifetimes.clean(), lifetimes: self.lifetimes.clean().move_iter().collect(),
types: self.types.clean() types: self.types.clean().move_iter().collect()
} }
} }
} }
...@@ -941,7 +966,7 @@ fn clean(&self) -> BareFunctionDecl { ...@@ -941,7 +966,7 @@ fn clean(&self) -> BareFunctionDecl {
BareFunctionDecl { BareFunctionDecl {
purity: self.purity, purity: self.purity,
generics: Generics { generics: Generics {
lifetimes: self.lifetimes.clean(), lifetimes: self.lifetimes.clean().move_iter().collect(),
type_params: ~[], type_params: ~[],
}, },
decl: self.decl.clean(), decl: self.decl.clean(),
...@@ -1028,7 +1053,7 @@ impl Clean<Item> for ast::ViewItem { ...@@ -1028,7 +1053,7 @@ impl Clean<Item> for ast::ViewItem {
fn clean(&self) -> Item { fn clean(&self) -> Item {
Item { Item {
name: None, name: None,
attrs: self.attrs.clean(), attrs: self.attrs.clean().move_iter().collect(),
source: self.span.clean(), source: self.span.clean(),
id: 0, id: 0,
visibility: self.vis.clean(), visibility: self.vis.clean(),
...@@ -1055,7 +1080,9 @@ fn clean(&self) -> ViewItemInner { ...@@ -1055,7 +1080,9 @@ fn clean(&self) -> ViewItemInner {
}; };
ExternMod(i.clean(), string, *id) 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 { ...@@ -1083,8 +1110,10 @@ fn clean(&self) -> ViewPath {
SimpleImport(i.clean(), resolve_use_source(p.clean(), id)), SimpleImport(i.clean(), resolve_use_source(p.clean(), id)),
ast::ViewPathGlob(ref p, id) => ast::ViewPathGlob(ref p, id) =>
GlobImport(resolve_use_source(p.clean(), id)), GlobImport(resolve_use_source(p.clean(), id)),
ast::ViewPathList(ref p, ref pl, id) => ast::ViewPathList(ref p, ref pl, id) => {
ImportList(resolve_use_source(p.clean(), id), pl.clean()), ImportList(resolve_use_source(p.clean(), id),
pl.clean().move_iter().collect())
}
} }
} }
} }
...@@ -1104,8 +1133,8 @@ fn clean(&self) -> ViewListIdent { ...@@ -1104,8 +1133,8 @@ fn clean(&self) -> ViewListIdent {
} }
} }
impl Clean<~[Item]> for ast::ForeignMod { impl Clean<Vec<Item>> for ast::ForeignMod {
fn clean(&self) -> ~[Item] { fn clean(&self) -> Vec<Item> {
self.items.clean() self.items.clean()
} }
} }
...@@ -1130,7 +1159,7 @@ fn clean(&self) -> Item { ...@@ -1130,7 +1159,7 @@ fn clean(&self) -> Item {
}; };
Item { Item {
name: Some(self.ident.clean()), name: Some(self.ident.clean()),
attrs: self.attrs.clean(), attrs: self.attrs.clean().move_iter().collect(),
source: self.span.clean(), source: self.span.clean(),
id: self.id, id: self.id,
visibility: self.vis.clean(), visibility: self.vis.clean(),
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
//! Rust AST Visitor. Extracts useful information and massages it into a form //! Rust AST Visitor. Extracts useful information and massages it into a form
//! usable for clean //! usable for clean
use std::vec_ng::Vec;
use syntax::abi::AbiSet; use syntax::abi::AbiSet;
use syntax::ast; use syntax::ast;
use syntax::ast_util; use syntax::ast_util;
...@@ -39,11 +40,17 @@ pub fn new<'b>(cx: &'b core::DocContext, ...@@ -39,11 +40,17 @@ pub fn new<'b>(cx: &'b core::DocContext,
} }
pub fn visit(&mut self, krate: &ast::Crate) { 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(), self.module = self.visit_mod_contents(krate.span,
ast::Public, ast::CRATE_NODE_ID, krate.attrs
&krate.module, None); .iter()
.map(|x| *x)
.collect(),
ast::Public,
ast::CRATE_NODE_ID,
&krate.module,
None);
self.module.is_crate = true; self.module.is_crate = true;
} }
...@@ -56,9 +63,9 @@ pub fn visit_struct_def(&mut self, item: &ast::Item, sd: @ast::StructDef, ...@@ -56,9 +63,9 @@ pub fn visit_struct_def(&mut self, item: &ast::Item, sd: @ast::StructDef,
struct_type: struct_type, struct_type: struct_type,
name: item.ident, name: item.ident,
vis: item.vis, vis: item.vis,
attrs: item.attrs.clone(), attrs: item.attrs.iter().map(|x| *x).collect(),
generics: generics.clone(), generics: generics.clone(),
fields: sd.fields.clone(), fields: sd.fields.iter().map(|x| (*x).clone()).collect(),
where: item.span where: item.span
} }
} }
...@@ -70,7 +77,7 @@ pub fn visit_enum_def(&mut self, it: &ast::Item, def: &ast::EnumDef, ...@@ -70,7 +77,7 @@ pub fn visit_enum_def(&mut self, it: &ast::Item, def: &ast::EnumDef,
for x in def.variants.iter() { for x in def.variants.iter() {
vars.push(Variant { vars.push(Variant {
name: x.node.name, name: x.node.name,
attrs: x.node.attrs.clone(), attrs: x.node.attrs.iter().map(|x| *x).collect(),
vis: x.node.vis, vis: x.node.vis,
id: x.node.id, id: x.node.id,
kind: x.node.kind.clone(), kind: x.node.kind.clone(),
...@@ -82,7 +89,7 @@ pub fn visit_enum_def(&mut self, it: &ast::Item, def: &ast::EnumDef, ...@@ -82,7 +89,7 @@ pub fn visit_enum_def(&mut self, it: &ast::Item, def: &ast::EnumDef,
variants: vars, variants: vars,
vis: it.vis, vis: it.vis,
generics: params.clone(), generics: params.clone(),
attrs: it.attrs.clone(), attrs: it.attrs.iter().map(|x| *x).collect(),
id: it.id, id: it.id,
where: it.span, where: it.span,
} }
...@@ -95,7 +102,7 @@ pub fn visit_fn(&mut self, item: &ast::Item, fd: &ast::FnDecl, ...@@ -95,7 +102,7 @@ pub fn visit_fn(&mut self, item: &ast::Item, fd: &ast::FnDecl,
Function { Function {
id: item.id, id: item.id,
vis: item.vis, vis: item.vis,
attrs: item.attrs.clone(), attrs: item.attrs.iter().map(|x| *x).collect(),
decl: fd.clone(), decl: fd.clone(),
name: item.ident, name: item.ident,
where: item.span, where: item.span,
...@@ -130,11 +137,11 @@ pub fn visit_view_item(&mut self, item: &ast::ViewItem, om: &mut Module) { ...@@ -130,11 +137,11 @@ pub fn visit_view_item(&mut self, item: &ast::ViewItem, om: &mut Module) {
ast::ViewItemUse(ref paths) => { ast::ViewItemUse(ref paths) => {
// rustc no longer supports "use foo, bar;" // rustc no longer supports "use foo, bar;"
assert_eq!(paths.len(), 1); assert_eq!(paths.len(), 1);
match self.visit_view_path(paths[0], om) { match self.visit_view_path(*paths.get(0), om) {
None => return, None => return,
Some(path) => { Some(path) => {
ast::ViewItem { ast::ViewItem {
node: ast::ViewItemUse(~[path]), node: ast::ViewItemUse(vec!(path)),
.. item.clone() .. item.clone()
} }
} }
...@@ -152,7 +159,7 @@ fn visit_view_path(&mut self, path: @ast::ViewPath, ...@@ -152,7 +159,7 @@ fn visit_view_path(&mut self, path: @ast::ViewPath,
if self.resolve_id(id, false, om) { return None } if self.resolve_id(id, false, om) { return None }
} }
ast::ViewPathList(ref p, ref paths, ref b) => { ast::ViewPathList(ref p, ref paths, ref b) => {
let mut mine = ~[]; let mut mine = Vec::new();
for path in paths.iter() { for path in paths.iter() {
if !self.resolve_id(path.node.id, false, om) { if !self.resolve_id(path.node.id, false, om) {
mine.push(path.clone()); mine.push(path.clone());
...@@ -217,9 +224,15 @@ pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) { ...@@ -217,9 +224,15 @@ pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) {
debug!("Visiting item {:?}", item); debug!("Visiting item {:?}", item);
match item.node { match item.node {
ast::ItemMod(ref m) => { ast::ItemMod(ref m) => {
om.mods.push(self.visit_mod_contents(item.span, item.attrs.clone(), om.mods.push(self.visit_mod_contents(item.span,
item.vis, item.id, m, item.attrs
Some(item.ident))); .iter()
.map(|x| *x)
.collect(),
item.vis,
item.id,
m,
Some(item.ident)));
}, },
ast::ItemEnum(ref ed, ref gen) => ast::ItemEnum(ref ed, ref gen) =>
om.enums.push(self.visit_enum_def(item, ed, 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) { ...@@ -233,7 +246,7 @@ pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) {
gen: gen.clone(), gen: gen.clone(),
name: item.ident, name: item.ident,
id: item.id, id: item.id,
attrs: item.attrs.clone(), attrs: item.attrs.iter().map(|x| *x).collect(),
where: item.span, where: item.span,
vis: item.vis, vis: item.vis,
}; };
...@@ -246,7 +259,7 @@ pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) { ...@@ -246,7 +259,7 @@ pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) {
expr: exp.clone(), expr: exp.clone(),
id: item.id, id: item.id,
name: item.ident, name: item.ident,
attrs: item.attrs.clone(), attrs: item.attrs.iter().map(|x| *x).collect(),
where: item.span, where: item.span,
vis: item.vis, vis: item.vis,
}; };
...@@ -255,11 +268,11 @@ pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) { ...@@ -255,11 +268,11 @@ pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) {
ast::ItemTrait(ref gen, ref tr, ref met) => { ast::ItemTrait(ref gen, ref tr, ref met) => {
let t = Trait { let t = Trait {
name: item.ident, name: item.ident,
methods: met.clone(), methods: met.iter().map(|x| (*x).clone()).collect(),
generics: gen.clone(), generics: gen.clone(),
parents: tr.clone(), parents: tr.iter().map(|x| (*x).clone()).collect(),
id: item.id, id: item.id,
attrs: item.attrs.clone(), attrs: item.attrs.iter().map(|x| *x).collect(),
where: item.span, where: item.span,
vis: item.vis, vis: item.vis,
}; };
...@@ -270,8 +283,8 @@ pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) { ...@@ -270,8 +283,8 @@ pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) {
generics: gen.clone(), generics: gen.clone(),
trait_: tr.clone(), trait_: tr.clone(),
for_: ty, for_: ty,
methods: meths.clone(), methods: meths.iter().map(|x| *x).collect(),
attrs: item.attrs.clone(), attrs: item.attrs.iter().map(|x| *x).collect(),
id: item.id, id: item.id,
where: item.span, where: item.span,
vis: item.vis, vis: item.vis,
...@@ -284,7 +297,7 @@ pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) { ...@@ -284,7 +297,7 @@ pub fn visit_item(&mut self, item: &ast::Item, om: &mut Module) {
ast::ItemMac(ref _m) => { ast::ItemMac(ref _m) => {
om.macros.push(Macro { om.macros.push(Macro {
id: item.id, id: item.id,
attrs: item.attrs.clone(), attrs: item.attrs.iter().map(|x| *x).collect(),
name: item.ident, name: item.ident,
where: item.span, where: item.span,
}) })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册