rustdoc: Inline names of function arguments

This commit is contained in:
Alex Crichton 2014-05-23 18:47:01 -07:00
parent 6ee9109c8b
commit 9181c35ee9
2 changed files with 44 additions and 31 deletions

View File

@ -774,23 +774,27 @@ fn encode_info_for_method(ecx: &EncodeContext,
} else {
encode_symbol(ecx, ebml_w, m.def_id.node);
}
encode_method_argument_names(ebml_w, &*ast_method.decl);
}
ebml_w.start_tag(tag_method_argument_names);
for arg in ast_method.decl.inputs.iter() {
ebml_w.start_tag(tag_method_argument_name);
match arg.pat.node {
ast::PatIdent(_, ref name, _) => {
let name = name.segments.last().unwrap().identifier;
let name = token::get_ident(name);
ebml_w.writer.write(name.get().as_bytes());
}
_ => {}
ebml_w.end_tag();
}
fn encode_method_argument_names(ebml_w: &mut Encoder,
decl: &ast::FnDecl) {
ebml_w.start_tag(tag_method_argument_names);
for arg in decl.inputs.iter() {
ebml_w.start_tag(tag_method_argument_name);
match arg.pat.node {
ast::PatIdent(_, ref name, _) => {
let name = name.segments.last().unwrap().identifier;
let name = token::get_ident(name);
ebml_w.writer.write(name.get().as_bytes());
}
ebml_w.end_tag();
_ => {}
}
ebml_w.end_tag();
}
ebml_w.end_tag();
}
@ -910,7 +914,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_visibility(ebml_w, vis);
ebml_w.end_tag();
}
ItemFn(_, fn_style, _, ref generics, _) => {
ItemFn(ref decl, fn_style, _, ref generics, _) => {
add_to_index(item, ebml_w, index);
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, def_id);
@ -926,6 +930,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_symbol(ecx, ebml_w, item.id);
}
encode_visibility(ebml_w, vis);
encode_method_argument_names(ebml_w, &**decl);
ebml_w.end_tag();
}
ItemMod(ref m) => {

View File

@ -722,18 +722,35 @@ impl Clean<FnDecl> for ast::FnDecl {
}
}
impl Clean<FnDecl> for ty::FnSig {
impl<'a> Clean<FnDecl> for (ast::DefId, &'a ty::FnSig) {
fn clean(&self) -> FnDecl {
let cx = super::ctxtkey.get().unwrap();
let tcx = match cx.maybe_typed {
core::Typed(ref tcx) => tcx,
core::NotTyped(_) => fail!(),
};
let (did, sig) = *self;
let mut names = if did.node != 0 {
csearch::get_method_arg_names(&tcx.sess.cstore, did).move_iter()
} else {
Vec::new().move_iter()
}.peekable();
if names.peek().map(|s| s.as_slice()) == Some("self") {
let _ = names.next();
}
if did.node == 0 {
let _ = names.len();
}
FnDecl {
output: self.output.clean(),
output: sig.output.clean(),
cf: Return,
attrs: Vec::new(), // FIXME: this is likely wrong
attrs: Vec::new(),
inputs: Arguments {
values: self.inputs.iter().map(|t| {
values: sig.inputs.iter().map(|t| {
Argument {
type_: t.clean(),
id: 0,
name: "".to_strbuf(), // FIXME: where are the names?
name: names.next().unwrap_or("".to_strbuf()),
}
}).collect(),
},
@ -868,15 +885,6 @@ impl Clean<TraitMethod> for ty::Method {
(s, sig)
}
};
let mut names = csearch::get_method_arg_names(&tcx.sess.cstore,
self.def_id).move_iter();
if self_ != SelfStatic {
names.next();
}
let mut decl = sig.clean();
for (name, slot) in names.zip(decl.inputs.values.mut_iter()) {
slot.name = name;
}
m(Item {
name: Some(self.ident.clean()),
@ -888,7 +896,7 @@ impl Clean<TraitMethod> for ty::Method {
fn_style: self.fty.fn_style,
generics: self.generics.clean(),
self_: self_,
decl: decl,
decl: (self.def_id, &sig).clean(),
})
})
}
@ -1005,13 +1013,13 @@ impl Clean<Type> for ty::t {
generics: Generics {
lifetimes: Vec::new(), type_params: Vec::new()
},
decl: fty.sig.clean(),
decl: (ast_util::local_def(0), &fty.sig).clean(),
abi: fty.abi.to_str().to_strbuf(),
}),
ty::ty_closure(ref fty) => {
let decl = box ClosureDecl {
lifetimes: Vec::new(), // FIXME: this looks wrong...
decl: fty.sig.clean(),
decl: (ast_util::local_def(0), &fty.sig).clean(),
onceness: fty.onceness,
fn_style: fty.fn_style,
bounds: fty.bounds.iter().map(|i| i.clean()).collect(),
@ -1855,7 +1863,7 @@ fn build_external_function(tcx: &ty::ctxt,
let t = ty::lookup_item_type(tcx, did);
Function {
decl: match ty::get(t.ty).sty {
ty::ty_bare_fn(ref f) => f.sig.clean(),
ty::ty_bare_fn(ref f) => (did, &f.sig).clean(),
_ => fail!("bad function"),
},
generics: t.generics.clean(),