Skip to content

Commit bd38b65

Browse files
committed
[WIP] Add FunctionItem
1 parent 5ba37bc commit bd38b65

File tree

2 files changed

+20
-34
lines changed

2 files changed

+20
-34
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ impl Clean<Vec<Item>> for hir::Item<'_> {
256256
value: print_evaluated_const(cx, def_id),
257257
is_literal: is_literal_expr(cx, body_id.hir_id),
258258
})),
259+
ItemKind::Fn(ref sig, ref generics, body) => NotInlined(clean_function(self, sig, &generics, body, cx)),
259260
ItemKind::Union(ref variant_data, ref generics) => NotInlined(UnionItem(Union {
260261
struct_type: doctree::struct_type_from_def(&variant_data),
261262
generics: generics.clean(cx),
@@ -962,32 +963,26 @@ impl<'a> Clean<Function> for (&'a hir::FnSig<'a>, &'a hir::Generics<'a>, hir::Bo
962963
}
963964
}
964965

965-
impl Clean<Item> for doctree::Function<'_> {
966-
fn clean(&self, cx: &DocContext<'_>) -> Item {
967-
let (generics, decl) =
968-
enter_impl_trait(cx, || (self.generics.clean(cx), (self.decl, self.body).clean(cx)));
966+
fn clean_function(item: &hir::Item<'_>, sig: &hir::FnSig<'_>, generics: &hir::Generics<'_>, body: hir::BodyId, cx: &DocContext<'_>) -> ItemKind {
967+
let (generics, decl) =
968+
enter_impl_trait(cx, || (generics.clean(cx), (sig.decl, body).clean(cx)));
969969

970-
let did = cx.tcx.hir().local_def_id(self.id).to_def_id();
971-
let constness = if is_const_fn(cx.tcx, did) && !is_unstable_const_fn(cx.tcx, did).is_some()
972-
{
973-
hir::Constness::Const
974-
} else {
975-
hir::Constness::NotConst
976-
};
977-
let (all_types, ret_types) = get_all_types(&generics, &decl, cx);
978-
Item::from_def_id_and_parts(
979-
did,
980-
Some(self.name),
981-
FunctionItem(Function {
982-
decl,
983-
generics,
984-
header: hir::FnHeader { constness, ..self.header },
985-
all_types,
986-
ret_types,
987-
}),
988-
cx,
989-
)
990-
}
970+
let did = cx.tcx.hir().local_def_id(item.hir_id);
971+
let constness = if is_const_fn(cx.tcx, did.to_def_id())
972+
&& !is_unstable_const_fn(cx.tcx, did.to_def_id()).is_some()
973+
{
974+
hir::Constness::Const
975+
} else {
976+
hir::Constness::NotConst
977+
};
978+
let (all_types, ret_types) = get_all_types(&generics, &decl, cx);
979+
FunctionItem(Function {
980+
decl,
981+
generics,
982+
header: hir::FnHeader { constness, ..sig.header },
983+
all_types,
984+
ret_types,
985+
})
991986
}
992987

993988
impl<'a> Clean<Arguments> for (&'a [hir::Ty<'a>], &'a [Ident]) {

src/librustdoc/doctree.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@ crate struct Variant<'hir> {
3939
crate def: &'hir hir::VariantData<'hir>,
4040
}
4141

42-
crate struct Function<'hir> {
43-
crate decl: &'hir hir::FnDecl<'hir>,
44-
crate id: hir::HirId,
45-
crate name: Symbol,
46-
crate header: hir::FnHeader,
47-
crate generics: &'hir hir::Generics<'hir>,
48-
crate body: hir::BodyId,
49-
}
50-
5142
crate struct Typedef<'hir> {
5243
crate ty: &'hir hir::Ty<'hir>,
5344
crate gen: &'hir hir::Generics<'hir>,

0 commit comments

Comments
 (0)