Skip to content

Commit 2a991e1

Browse files
committed
Get rid of clean::Method
Replace it instead with `(clean::Function, Option<hir::Defaultness>)`.
1 parent b3f9795 commit 2a991e1

File tree

4 files changed

+32
-42
lines changed

4 files changed

+32
-42
lines changed

src/librustdoc/clean/mod.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -883,14 +883,12 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
883883
}
884884
}
885885

886-
impl<'a> Clean<Method>
887-
for (&'a hir::FnSig<'a>, &'a hir::Generics<'a>, hir::BodyId, Option<hir::Defaultness>)
888-
{
889-
fn clean(&self, cx: &DocContext<'_>) -> Method {
886+
impl<'a> Clean<Function> for (&'a hir::FnSig<'a>, &'a hir::Generics<'a>, hir::BodyId) {
887+
fn clean(&self, cx: &DocContext<'_>) -> Function {
890888
let (generics, decl) =
891889
enter_impl_trait(cx, || (self.1.clean(cx), (&*self.0.decl, self.2).clean(cx)));
892890
let (all_types, ret_types) = get_all_types(&generics, &decl, cx);
893-
Method { decl, generics, header: self.0.header, defaultness: self.3, all_types, ret_types }
891+
Function { decl, generics, header: self.0.header, all_types, ret_types }
894892
}
895893
}
896894

@@ -1107,13 +1105,13 @@ impl Clean<Item> for hir::TraitItem<'_> {
11071105
AssocConstItem(ty.clean(cx), default.map(|e| print_const_expr(cx, e)))
11081106
}
11091107
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
1110-
let mut m = (sig, &self.generics, body, None).clean(cx);
1108+
let mut m = (sig, &self.generics, body).clean(cx);
11111109
if m.header.constness == hir::Constness::Const
11121110
&& is_unstable_const_fn(cx.tcx, local_did.to_def_id()).is_some()
11131111
{
11141112
m.header.constness = hir::Constness::NotConst;
11151113
}
1116-
MethodItem(m)
1114+
MethodItem(m, None)
11171115
}
11181116
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(ref names)) => {
11191117
let (generics, decl) = enter_impl_trait(cx, || {
@@ -1153,13 +1151,13 @@ impl Clean<Item> for hir::ImplItem<'_> {
11531151
AssocConstItem(ty.clean(cx), Some(print_const_expr(cx, expr)))
11541152
}
11551153
hir::ImplItemKind::Fn(ref sig, body) => {
1156-
let mut m = (sig, &self.generics, body, Some(self.defaultness)).clean(cx);
1154+
let mut m = (sig, &self.generics, body).clean(cx);
11571155
if m.header.constness == hir::Constness::Const
11581156
&& is_unstable_const_fn(cx.tcx, local_did.to_def_id()).is_some()
11591157
{
11601158
m.header.constness = hir::Constness::NotConst;
11611159
}
1162-
MethodItem(m)
1160+
MethodItem(m, Some(self.defaultness))
11631161
}
11641162
hir::ImplItemKind::TyAlias(ref ty) => {
11651163
let type_ = ty.clean(cx);
@@ -1235,19 +1233,21 @@ impl Clean<Item> for ty::AssocItem {
12351233
ty::ImplContainer(_) => Some(self.defaultness),
12361234
ty::TraitContainer(_) => None,
12371235
};
1238-
MethodItem(Method {
1239-
generics,
1240-
decl,
1241-
header: hir::FnHeader {
1242-
unsafety: sig.unsafety(),
1243-
abi: sig.abi(),
1244-
constness,
1245-
asyncness,
1236+
MethodItem(
1237+
Function {
1238+
generics,
1239+
decl,
1240+
header: hir::FnHeader {
1241+
unsafety: sig.unsafety(),
1242+
abi: sig.abi(),
1243+
constness,
1244+
asyncness,
1245+
},
1246+
all_types,
1247+
ret_types,
12461248
},
12471249
defaultness,
1248-
all_types,
1249-
ret_types,
1250-
})
1250+
)
12511251
} else {
12521252
TyMethodItem(Function {
12531253
generics,

src/librustdoc/clean/types.rs

+3-17
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,8 @@ impl Item {
227227

228228
crate fn is_default(&self) -> bool {
229229
match self.kind {
230-
ItemKind::MethodItem(ref meth) => {
231-
if let Some(defaultness) = meth.defaultness {
232-
defaultness.has_value() && !defaultness.is_final()
233-
} else {
234-
false
235-
}
230+
ItemKind::MethodItem(_, Some(defaultness)) => {
231+
defaultness.has_value() && !defaultness.is_final()
236232
}
237233
_ => false,
238234
}
@@ -266,7 +262,7 @@ crate enum ItemKind {
266262
/// non-default-methods).
267263
TyMethodItem(Function),
268264
/// A method with a body.
269-
MethodItem(Method),
265+
MethodItem(Function, Option<hir::Defaultness>),
270266
StructFieldItem(Type),
271267
VariantItem(Variant),
272268
/// `fn`s from an extern block
@@ -910,16 +906,6 @@ crate struct Generics {
910906
crate where_predicates: Vec<WherePredicate>,
911907
}
912908

913-
#[derive(Clone, Debug)]
914-
crate struct Method {
915-
crate generics: Generics,
916-
crate decl: FnDecl,
917-
crate header: hir::FnHeader,
918-
crate defaultness: Option<hir::Defaultness>,
919-
crate all_types: Vec<(Type, TypeKind)>,
920-
crate ret_types: Vec<(Type, TypeKind)>,
921-
}
922-
923909
#[derive(Clone, Debug)]
924910
crate struct Function {
925911
crate decl: FnDecl,

src/librustdoc/html/render/cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ crate fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
167167
crate fn get_index_search_type(item: &clean::Item) -> Option<IndexItemFunctionType> {
168168
let (all_types, ret_types) = match item.kind {
169169
clean::FunctionItem(ref f) => (&f.all_types, &f.ret_types),
170-
clean::MethodItem(ref m) => (&m.all_types, &m.ret_types),
170+
clean::MethodItem(ref m, _) => (&m.all_types, &m.ret_types),
171171
clean::TyMethodItem(ref m) => (&m.all_types, &m.ret_types),
172172
_ => return None,
173173
};

src/librustdoc/html/render/mod.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -2589,7 +2589,9 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait,
25892589
for (pos, m) in provided.iter().enumerate() {
25902590
render_assoc_item(w, m, AssocItemLink::Anchor(None), ItemType::Trait);
25912591
match m.kind {
2592-
clean::MethodItem(ref inner) if !inner.generics.where_predicates.is_empty() => {
2592+
clean::MethodItem(ref inner, _)
2593+
if !inner.generics.where_predicates.is_empty() =>
2594+
{
25932595
write!(w, ",\n {{ ... }}\n");
25942596
}
25952597
_ => {
@@ -2968,7 +2970,9 @@ fn render_assoc_item(
29682970
match item.kind {
29692971
clean::StrippedItem(..) => {}
29702972
clean::TyMethodItem(ref m) => method(w, item, m.header, &m.generics, &m.decl, link, parent),
2971-
clean::MethodItem(ref m) => method(w, item, m.header, &m.generics, &m.decl, link, parent),
2973+
clean::MethodItem(ref m, _) => {
2974+
method(w, item, m.header, &m.generics, &m.decl, link, parent)
2975+
}
29722976
clean::AssocConstItem(ref ty, ref default) => assoc_const(
29732977
w,
29742978
item,
@@ -3545,7 +3549,7 @@ fn render_deref_methods(
35453549

35463550
fn should_render_item(item: &clean::Item, deref_mut_: bool) -> bool {
35473551
let self_type_opt = match item.kind {
3548-
clean::MethodItem(ref method) => method.decl.self_type(),
3552+
clean::MethodItem(ref method, _) => method.decl.self_type(),
35493553
clean::TyMethodItem(ref method) => method.decl.self_type(),
35503554
_ => None,
35513555
};
@@ -3752,7 +3756,7 @@ fn render_impl(
37523756
(true, " hidden")
37533757
};
37543758
match item.kind {
3755-
clean::MethodItem(_) | clean::TyMethodItem(_) => {
3759+
clean::MethodItem(..) | clean::TyMethodItem(_) => {
37563760
// Only render when the method is not static or we allow static methods
37573761
if render_method_item {
37583762
let id = cx.derive_id(format!("{}.{}", item_type, name));

0 commit comments

Comments
 (0)