rustdoc: Make fold require Clone instead of Copy
This commit is contained in:
parent
b21e9d52de
commit
19f5f91c04
10 changed files with 110 additions and 41 deletions
|
@ -39,6 +39,10 @@ pub enum Srv = {
|
|||
ch: comm::Chan<Msg>
|
||||
};
|
||||
|
||||
impl Srv: Clone {
|
||||
fn clone(&self) -> Srv { copy *self }
|
||||
}
|
||||
|
||||
pub fn from_str<T>(source: ~str, owner: SrvOwner<T>) -> T {
|
||||
run(owner, source, parse::from_str_sess)
|
||||
}
|
||||
|
|
|
@ -61,6 +61,10 @@ pub type Config = {
|
|||
pandoc_cmd: Option<~str>
|
||||
};
|
||||
|
||||
impl Config: Clone {
|
||||
fn clone(&self) -> Config { copy *self }
|
||||
}
|
||||
|
||||
fn opt_output_dir() -> ~str { ~"output-dir" }
|
||||
fn opt_output_format() -> ~str { ~"output-format" }
|
||||
fn opt_output_style() -> ~str { ~"output-style" }
|
||||
|
|
|
@ -1,5 +1,25 @@
|
|||
pub enum Fold<T> = Fold_<T>;
|
||||
|
||||
impl<T: Clone> Fold<T>: Clone {
|
||||
fn clone(&self) -> Fold<T> {
|
||||
Fold({
|
||||
ctxt: self.ctxt.clone(),
|
||||
fold_doc: copy self.fold_doc,
|
||||
fold_crate: copy self.fold_crate,
|
||||
fold_item: copy self.fold_item,
|
||||
fold_mod: copy self.fold_mod,
|
||||
fold_nmod: copy self.fold_nmod,
|
||||
fold_fn: copy self.fold_fn,
|
||||
fold_const: copy self.fold_const,
|
||||
fold_enum: copy self.fold_enum,
|
||||
fold_trait: copy self.fold_trait,
|
||||
fold_impl: copy self.fold_impl,
|
||||
fold_type: copy self.fold_type,
|
||||
fold_struct: copy self.fold_struct
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type FoldDoc<T> = fn~(fold: &Fold<T>, +doc: doc::Doc) -> doc::Doc;
|
||||
type FoldCrate<T> = fn~(fold: &Fold<T>, +doc: doc::CrateDoc) -> doc::CrateDoc;
|
||||
type FoldItem<T> = fn~(fold: &Fold<T>, +doc: doc::ItemDoc) -> doc::ItemDoc;
|
||||
|
@ -33,7 +53,7 @@ type Fold_<T> = {
|
|||
|
||||
// This exists because fn types don't infer correctly as record
|
||||
// initializers, but they do as function arguments
|
||||
fn mk_fold<T:Copy>(
|
||||
fn mk_fold<T:Clone>(
|
||||
+ctxt: T,
|
||||
+fold_doc: FoldDoc<T>,
|
||||
+fold_crate: FoldCrate<T>,
|
||||
|
@ -49,7 +69,7 @@ fn mk_fold<T:Copy>(
|
|||
+fold_struct: FoldStruct<T>
|
||||
) -> Fold<T> {
|
||||
Fold({
|
||||
ctxt: ctxt,
|
||||
ctxt: move ctxt,
|
||||
fold_doc: move fold_doc,
|
||||
fold_crate: move fold_crate,
|
||||
fold_item: move fold_item,
|
||||
|
@ -65,9 +85,9 @@ fn mk_fold<T:Copy>(
|
|||
})
|
||||
}
|
||||
|
||||
pub fn default_any_fold<T:Send Copy>(+ctxt: T) -> Fold<T> {
|
||||
pub fn default_any_fold<T:Send Clone>(+ctxt: T) -> Fold<T> {
|
||||
mk_fold(
|
||||
ctxt,
|
||||
move ctxt,
|
||||
|f, d| default_seq_fold_doc(f, d),
|
||||
|f, d| default_seq_fold_crate(f, d),
|
||||
|f, d| default_seq_fold_item(f, d),
|
||||
|
@ -83,9 +103,9 @@ pub fn default_any_fold<T:Send Copy>(+ctxt: T) -> Fold<T> {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn default_seq_fold<T:Copy>(+ctxt: T) -> Fold<T> {
|
||||
pub fn default_seq_fold<T:Clone>(+ctxt: T) -> Fold<T> {
|
||||
mk_fold(
|
||||
ctxt,
|
||||
move ctxt,
|
||||
|f, d| default_seq_fold_doc(f, d),
|
||||
|f, d| default_seq_fold_crate(f, d),
|
||||
|f, d| default_seq_fold_item(f, d),
|
||||
|
@ -101,9 +121,9 @@ pub fn default_seq_fold<T:Copy>(+ctxt: T) -> Fold<T> {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn default_par_fold<T:Send Copy>(+ctxt: T) -> Fold<T> {
|
||||
pub fn default_par_fold<T:Send Clone>(+ctxt: T) -> Fold<T> {
|
||||
mk_fold(
|
||||
ctxt,
|
||||
move ctxt,
|
||||
|f, d| default_seq_fold_doc(f, d),
|
||||
|f, d| default_seq_fold_crate(f, d),
|
||||
|f, d| default_seq_fold_item(f, d),
|
||||
|
@ -151,11 +171,11 @@ pub fn default_seq_fold_item<T>(
|
|||
doc
|
||||
}
|
||||
|
||||
pub fn default_any_fold_mod<T:Send Copy>(
|
||||
pub fn default_any_fold_mod<T:Send Clone>(
|
||||
fold: &Fold<T>,
|
||||
+doc: doc::ModDoc
|
||||
) -> doc::ModDoc {
|
||||
let fold_copy = copy *fold;
|
||||
let fold_copy = fold.clone();
|
||||
doc::ModDoc_({
|
||||
item: fold.fold_item(fold, doc.item),
|
||||
items: par::map(doc.items, |ItemTag, move fold_copy| {
|
||||
|
@ -178,11 +198,11 @@ pub fn default_seq_fold_mod<T>(
|
|||
})
|
||||
}
|
||||
|
||||
pub fn default_par_fold_mod<T:Send Copy>(
|
||||
pub fn default_par_fold_mod<T:Send Clone>(
|
||||
fold: &Fold<T>,
|
||||
+doc: doc::ModDoc
|
||||
) -> doc::ModDoc {
|
||||
let fold_copy = copy *fold;
|
||||
let fold_copy = fold.clone();
|
||||
doc::ModDoc_({
|
||||
item: fold.fold_item(fold, doc.item),
|
||||
items: par::map(doc.items, |ItemTag, move fold_copy| {
|
||||
|
@ -192,11 +212,11 @@ pub fn default_par_fold_mod<T:Send Copy>(
|
|||
})
|
||||
}
|
||||
|
||||
pub fn default_any_fold_nmod<T:Send Copy>(
|
||||
pub fn default_any_fold_nmod<T:Send Clone>(
|
||||
fold: &Fold<T>,
|
||||
+doc: doc::NmodDoc
|
||||
) -> doc::NmodDoc {
|
||||
let fold_copy = copy *fold;
|
||||
let fold_copy = fold.clone();
|
||||
{
|
||||
item: fold.fold_item(fold, doc.item),
|
||||
fns: par::map(doc.fns, |FnDoc, move fold_copy| {
|
||||
|
@ -219,11 +239,11 @@ pub fn default_seq_fold_nmod<T>(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn default_par_fold_nmod<T:Send Copy>(
|
||||
pub fn default_par_fold_nmod<T:Send Clone>(
|
||||
fold: &Fold<T>,
|
||||
+doc: doc::NmodDoc
|
||||
) -> doc::NmodDoc {
|
||||
let fold_copy = copy *fold;
|
||||
let fold_copy = fold.clone();
|
||||
{
|
||||
item: fold.fold_item(fold, doc.item),
|
||||
fns: par::map(doc.fns, |FnDoc, move fold_copy| {
|
||||
|
|
|
@ -7,6 +7,7 @@ individual modules, pages for the crate, indexes, etc.
|
|||
|
||||
use doc::{ItemUtils, PageUtils};
|
||||
use syntax::ast;
|
||||
use util::NominalOp;
|
||||
|
||||
pub fn mk_pass(output_style: config::OutputStyle) -> Pass {
|
||||
{
|
||||
|
@ -39,6 +40,8 @@ fn run(
|
|||
type PagePort = comm::Port<Option<doc::Page>>;
|
||||
type PageChan = comm::Chan<Option<doc::Page>>;
|
||||
|
||||
type NominalPageChan = NominalOp<PageChan>;
|
||||
|
||||
fn make_doc_from_pages(page_port: PagePort) -> doc::Doc {
|
||||
let mut pages = ~[];
|
||||
loop {
|
||||
|
@ -59,7 +62,7 @@ fn find_pages(doc: doc::Doc, page_chan: PageChan) {
|
|||
fold_crate: fold_crate,
|
||||
fold_mod: fold_mod,
|
||||
fold_nmod: fold_nmod,
|
||||
.. *fold::default_any_fold(page_chan)
|
||||
.. *fold::default_any_fold(NominalOp { op: page_chan })
|
||||
});
|
||||
fold.fold_doc(&fold, doc);
|
||||
|
||||
|
@ -67,7 +70,7 @@ fn find_pages(doc: doc::Doc, page_chan: PageChan) {
|
|||
}
|
||||
|
||||
fn fold_crate(
|
||||
fold: &fold::Fold<PageChan>,
|
||||
fold: &fold::Fold<NominalPageChan>,
|
||||
+doc: doc::CrateDoc
|
||||
) -> doc::CrateDoc {
|
||||
|
||||
|
@ -78,13 +81,13 @@ fn fold_crate(
|
|||
.. doc
|
||||
});
|
||||
|
||||
comm::send(fold.ctxt, Some(page));
|
||||
comm::send(fold.ctxt.op, Some(page));
|
||||
|
||||
doc
|
||||
}
|
||||
|
||||
fn fold_mod(
|
||||
fold: &fold::Fold<PageChan>,
|
||||
fold: &fold::Fold<NominalPageChan>,
|
||||
+doc: doc::ModDoc
|
||||
) -> doc::ModDoc {
|
||||
|
||||
|
@ -94,7 +97,7 @@ fn fold_mod(
|
|||
|
||||
let doc = strip_mod(doc);
|
||||
let page = doc::ItemPage(doc::ModTag(doc));
|
||||
comm::send(fold.ctxt, Some(page));
|
||||
comm::send(fold.ctxt.op, Some(page));
|
||||
}
|
||||
|
||||
doc
|
||||
|
@ -114,12 +117,12 @@ fn strip_mod(doc: doc::ModDoc) -> doc::ModDoc {
|
|||
}
|
||||
|
||||
fn fold_nmod(
|
||||
fold: &fold::Fold<PageChan>,
|
||||
fold: &fold::Fold<NominalPageChan>,
|
||||
+doc: doc::NmodDoc
|
||||
) -> doc::NmodDoc {
|
||||
let doc = fold::default_seq_fold_nmod(fold, doc);
|
||||
let page = doc::ItemPage(doc::NmodTag(doc));
|
||||
comm::send(fold.ctxt, Some(page));
|
||||
comm::send(fold.ctxt.op, Some(page));
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,14 +10,18 @@ pub fn mk_pass() -> Pass {
|
|||
}
|
||||
}
|
||||
|
||||
type Ctxt = {
|
||||
struct Ctxt {
|
||||
srv: astsrv::Srv,
|
||||
mut path: ~[~str]
|
||||
};
|
||||
}
|
||||
|
||||
impl Ctxt: Clone {
|
||||
fn clone(&self) -> Ctxt { copy *self }
|
||||
}
|
||||
|
||||
#[allow(non_implicitly_copyable_typarams)]
|
||||
fn run(srv: astsrv::Srv, +doc: doc::Doc) -> doc::Doc {
|
||||
let ctxt = {
|
||||
let ctxt = Ctxt {
|
||||
srv: srv,
|
||||
mut path: ~[]
|
||||
};
|
||||
|
|
|
@ -44,7 +44,7 @@ fn is_visible(srv: astsrv::Srv, doc: doc::ItemDoc) -> bool {
|
|||
ast_map::node_item(item, _) => {
|
||||
item.vis == ast::public
|
||||
}
|
||||
_ => util::unreachable()
|
||||
_ => core::util::unreachable()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,3 +52,4 @@ mod page_pass;
|
|||
mod sectionalize_pass;
|
||||
mod escape_pass;
|
||||
mod prune_private_pass;
|
||||
mod util;
|
|
@ -2,14 +2,17 @@
|
|||
|
||||
use doc::ItemUtils;
|
||||
use std::sort;
|
||||
use util::NominalOp;
|
||||
|
||||
pub type ItemLtEq = pure fn~(v1: &doc::ItemTag, v2: &doc::ItemTag) -> bool;
|
||||
pub type ItemLtEqOp = pure fn~(v1: &doc::ItemTag, v2: &doc::ItemTag) -> bool;
|
||||
|
||||
pub fn mk_pass(name: ~str, +lteq: ItemLtEq) -> Pass {
|
||||
type ItemLtEq = NominalOp<ItemLtEqOp>;
|
||||
|
||||
pub fn mk_pass(name: ~str, +lteq: ItemLtEqOp) -> Pass {
|
||||
{
|
||||
name: name,
|
||||
f: fn~(move lteq, srv: astsrv::Srv, +doc: doc::Doc) -> doc::Doc {
|
||||
run(srv, doc, copy lteq)
|
||||
run(srv, doc, NominalOp { op: copy lteq })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +37,7 @@ fn fold_mod(
|
|||
) -> doc::ModDoc {
|
||||
let doc = fold::default_any_fold_mod(fold, doc);
|
||||
doc::ModDoc_({
|
||||
items: sort::merge_sort(doc.items, fold.ctxt),
|
||||
items: sort::merge_sort(doc.items, fold.ctxt.op),
|
||||
.. *doc
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//! Generic pass for performing an operation on all descriptions
|
||||
|
||||
use doc::ItemUtils;
|
||||
use util::NominalOp;
|
||||
|
||||
pub fn mk_pass(name: ~str, +op: fn~(~str) -> ~str) -> Pass {
|
||||
{
|
||||
|
@ -19,6 +20,9 @@ fn run(
|
|||
+doc: doc::Doc,
|
||||
+op: Op
|
||||
) -> doc::Doc {
|
||||
let op = NominalOp {
|
||||
op: move op
|
||||
};
|
||||
let fold = fold::Fold({
|
||||
fold_item: fold_item,
|
||||
fold_enum: fold_enum,
|
||||
|
@ -29,11 +33,14 @@ fn run(
|
|||
fold.fold_doc(&fold, doc)
|
||||
}
|
||||
|
||||
fn maybe_apply_op(op: Op, s: Option<~str>) -> Option<~str> {
|
||||
s.map(|s| op(*s) )
|
||||
fn maybe_apply_op(op: NominalOp<Op>, s: Option<~str>) -> Option<~str> {
|
||||
s.map(|s| op.op(*s) )
|
||||
}
|
||||
|
||||
fn fold_item(fold: &fold::Fold<Op>, +doc: doc::ItemDoc) -> doc::ItemDoc {
|
||||
fn fold_item(
|
||||
fold: &fold::Fold<NominalOp<Op>>,
|
||||
+doc: doc::ItemDoc
|
||||
) -> doc::ItemDoc {
|
||||
let doc = fold::default_seq_fold_item(fold, doc);
|
||||
|
||||
{
|
||||
|
@ -44,14 +51,19 @@ fn fold_item(fold: &fold::Fold<Op>, +doc: doc::ItemDoc) -> doc::ItemDoc {
|
|||
}
|
||||
}
|
||||
|
||||
fn apply_to_sections(op: Op, sections: ~[doc::Section]) -> ~[doc::Section] {
|
||||
fn apply_to_sections(
|
||||
op: NominalOp<Op>,
|
||||
sections: ~[doc::Section]
|
||||
) -> ~[doc::Section] {
|
||||
par::map(sections, |section, copy op| {
|
||||
header: op(section.header),
|
||||
body: op(section.body)
|
||||
header: op.op(section.header),
|
||||
body: op.op(section.body)
|
||||
})
|
||||
}
|
||||
|
||||
fn fold_enum(fold: &fold::Fold<Op>, +doc: doc::EnumDoc) -> doc::EnumDoc {
|
||||
fn fold_enum(
|
||||
fold: &fold::Fold<NominalOp<Op>>,
|
||||
+doc: doc::EnumDoc) -> doc::EnumDoc {
|
||||
let doc = fold::default_seq_fold_enum(fold, doc);
|
||||
let fold_copy = copy *fold;
|
||||
|
||||
|
@ -66,7 +78,10 @@ fn fold_enum(fold: &fold::Fold<Op>, +doc: doc::EnumDoc) -> doc::EnumDoc {
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_trait(fold: &fold::Fold<Op>, +doc: doc::TraitDoc) -> doc::TraitDoc {
|
||||
fn fold_trait(
|
||||
fold: &fold::Fold<NominalOp<Op>>,
|
||||
+doc: doc::TraitDoc
|
||||
) -> doc::TraitDoc {
|
||||
let doc = fold::default_seq_fold_trait(fold, doc);
|
||||
|
||||
{
|
||||
|
@ -75,7 +90,10 @@ fn fold_trait(fold: &fold::Fold<Op>, +doc: doc::TraitDoc) -> doc::TraitDoc {
|
|||
}
|
||||
}
|
||||
|
||||
fn apply_to_methods(op: Op, docs: ~[doc::MethodDoc]) -> ~[doc::MethodDoc] {
|
||||
fn apply_to_methods(
|
||||
op: NominalOp<Op>,
|
||||
docs: ~[doc::MethodDoc]
|
||||
) -> ~[doc::MethodDoc] {
|
||||
do par::map(docs) |doc, copy op| {
|
||||
{
|
||||
brief: maybe_apply_op(op, doc.brief),
|
||||
|
@ -86,7 +104,10 @@ fn apply_to_methods(op: Op, docs: ~[doc::MethodDoc]) -> ~[doc::MethodDoc] {
|
|||
}
|
||||
}
|
||||
|
||||
fn fold_impl(fold: &fold::Fold<Op>, +doc: doc::ImplDoc) -> doc::ImplDoc {
|
||||
fn fold_impl(
|
||||
fold: &fold::Fold<NominalOp<Op>>,
|
||||
+doc: doc::ImplDoc
|
||||
) -> doc::ImplDoc {
|
||||
let doc = fold::default_seq_fold_impl(fold, doc);
|
||||
|
||||
{
|
||||
|
|
9
src/librustdoc/util.rs
Normal file
9
src/librustdoc/util.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
// Just a named container for our op, so it can have impls
|
||||
pub struct NominalOp<T> {
|
||||
op: T
|
||||
}
|
||||
|
||||
impl<T: Copy> NominalOp<T>: Clone {
|
||||
fn clone(&self) -> NominalOp<T> { copy *self }
|
||||
}
|
||||
|
Loading…
Add table
Reference in a new issue