1
Fork 0

Get rid of clean::Method

Replace it instead with `(clean::Function, Option<hir::Defaultness>)`.
This commit is contained in:
Joshua Nelson 2020-11-16 23:19:58 -05:00
parent b3f9795cbb
commit 2a991e18ac
4 changed files with 32 additions and 42 deletions

View file

@ -883,14 +883,12 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
} }
} }
impl<'a> Clean<Method> impl<'a> Clean<Function> for (&'a hir::FnSig<'a>, &'a hir::Generics<'a>, hir::BodyId) {
for (&'a hir::FnSig<'a>, &'a hir::Generics<'a>, hir::BodyId, Option<hir::Defaultness>) fn clean(&self, cx: &DocContext<'_>) -> Function {
{
fn clean(&self, cx: &DocContext<'_>) -> Method {
let (generics, decl) = let (generics, decl) =
enter_impl_trait(cx, || (self.1.clean(cx), (&*self.0.decl, self.2).clean(cx))); enter_impl_trait(cx, || (self.1.clean(cx), (&*self.0.decl, self.2).clean(cx)));
let (all_types, ret_types) = get_all_types(&generics, &decl, cx); let (all_types, ret_types) = get_all_types(&generics, &decl, cx);
Method { decl, generics, header: self.0.header, defaultness: self.3, all_types, ret_types } Function { decl, generics, header: self.0.header, all_types, ret_types }
} }
} }
@ -1107,13 +1105,13 @@ impl Clean<Item> for hir::TraitItem<'_> {
AssocConstItem(ty.clean(cx), default.map(|e| print_const_expr(cx, e))) AssocConstItem(ty.clean(cx), default.map(|e| print_const_expr(cx, e)))
} }
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => { hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
let mut m = (sig, &self.generics, body, None).clean(cx); let mut m = (sig, &self.generics, body).clean(cx);
if m.header.constness == hir::Constness::Const if m.header.constness == hir::Constness::Const
&& is_unstable_const_fn(cx.tcx, local_did.to_def_id()).is_some() && is_unstable_const_fn(cx.tcx, local_did.to_def_id()).is_some()
{ {
m.header.constness = hir::Constness::NotConst; m.header.constness = hir::Constness::NotConst;
} }
MethodItem(m) MethodItem(m, None)
} }
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(ref names)) => { hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(ref names)) => {
let (generics, decl) = enter_impl_trait(cx, || { let (generics, decl) = enter_impl_trait(cx, || {
@ -1153,13 +1151,13 @@ impl Clean<Item> for hir::ImplItem<'_> {
AssocConstItem(ty.clean(cx), Some(print_const_expr(cx, expr))) AssocConstItem(ty.clean(cx), Some(print_const_expr(cx, expr)))
} }
hir::ImplItemKind::Fn(ref sig, body) => { hir::ImplItemKind::Fn(ref sig, body) => {
let mut m = (sig, &self.generics, body, Some(self.defaultness)).clean(cx); let mut m = (sig, &self.generics, body).clean(cx);
if m.header.constness == hir::Constness::Const if m.header.constness == hir::Constness::Const
&& is_unstable_const_fn(cx.tcx, local_did.to_def_id()).is_some() && is_unstable_const_fn(cx.tcx, local_did.to_def_id()).is_some()
{ {
m.header.constness = hir::Constness::NotConst; m.header.constness = hir::Constness::NotConst;
} }
MethodItem(m) MethodItem(m, Some(self.defaultness))
} }
hir::ImplItemKind::TyAlias(ref ty) => { hir::ImplItemKind::TyAlias(ref ty) => {
let type_ = ty.clean(cx); let type_ = ty.clean(cx);
@ -1235,7 +1233,8 @@ impl Clean<Item> for ty::AssocItem {
ty::ImplContainer(_) => Some(self.defaultness), ty::ImplContainer(_) => Some(self.defaultness),
ty::TraitContainer(_) => None, ty::TraitContainer(_) => None,
}; };
MethodItem(Method { MethodItem(
Function {
generics, generics,
decl, decl,
header: hir::FnHeader { header: hir::FnHeader {
@ -1244,10 +1243,11 @@ impl Clean<Item> for ty::AssocItem {
constness, constness,
asyncness, asyncness,
}, },
defaultness,
all_types, all_types,
ret_types, ret_types,
}) },
defaultness,
)
} else { } else {
TyMethodItem(Function { TyMethodItem(Function {
generics, generics,

View file

@ -227,12 +227,8 @@ impl Item {
crate fn is_default(&self) -> bool { crate fn is_default(&self) -> bool {
match self.kind { match self.kind {
ItemKind::MethodItem(ref meth) => { ItemKind::MethodItem(_, Some(defaultness)) => {
if let Some(defaultness) = meth.defaultness {
defaultness.has_value() && !defaultness.is_final() defaultness.has_value() && !defaultness.is_final()
} else {
false
}
} }
_ => false, _ => false,
} }
@ -266,7 +262,7 @@ crate enum ItemKind {
/// non-default-methods). /// non-default-methods).
TyMethodItem(Function), TyMethodItem(Function),
/// A method with a body. /// A method with a body.
MethodItem(Method), MethodItem(Function, Option<hir::Defaultness>),
StructFieldItem(Type), StructFieldItem(Type),
VariantItem(Variant), VariantItem(Variant),
/// `fn`s from an extern block /// `fn`s from an extern block
@ -910,16 +906,6 @@ crate struct Generics {
crate where_predicates: Vec<WherePredicate>, crate where_predicates: Vec<WherePredicate>,
} }
#[derive(Clone, Debug)]
crate struct Method {
crate generics: Generics,
crate decl: FnDecl,
crate header: hir::FnHeader,
crate defaultness: Option<hir::Defaultness>,
crate all_types: Vec<(Type, TypeKind)>,
crate ret_types: Vec<(Type, TypeKind)>,
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
crate struct Function { crate struct Function {
crate decl: FnDecl, crate decl: FnDecl,

View file

@ -167,7 +167,7 @@ crate fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
crate fn get_index_search_type(item: &clean::Item) -> Option<IndexItemFunctionType> { crate fn get_index_search_type(item: &clean::Item) -> Option<IndexItemFunctionType> {
let (all_types, ret_types) = match item.kind { let (all_types, ret_types) = match item.kind {
clean::FunctionItem(ref f) => (&f.all_types, &f.ret_types), clean::FunctionItem(ref f) => (&f.all_types, &f.ret_types),
clean::MethodItem(ref m) => (&m.all_types, &m.ret_types), clean::MethodItem(ref m, _) => (&m.all_types, &m.ret_types),
clean::TyMethodItem(ref m) => (&m.all_types, &m.ret_types), clean::TyMethodItem(ref m) => (&m.all_types, &m.ret_types),
_ => return None, _ => return None,
}; };

View file

@ -2589,7 +2589,9 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait,
for (pos, m) in provided.iter().enumerate() { for (pos, m) in provided.iter().enumerate() {
render_assoc_item(w, m, AssocItemLink::Anchor(None), ItemType::Trait); render_assoc_item(w, m, AssocItemLink::Anchor(None), ItemType::Trait);
match m.kind { match m.kind {
clean::MethodItem(ref inner) if !inner.generics.where_predicates.is_empty() => { clean::MethodItem(ref inner, _)
if !inner.generics.where_predicates.is_empty() =>
{
write!(w, ",\n {{ ... }}\n"); write!(w, ",\n {{ ... }}\n");
} }
_ => { _ => {
@ -2968,7 +2970,9 @@ fn render_assoc_item(
match item.kind { match item.kind {
clean::StrippedItem(..) => {} clean::StrippedItem(..) => {}
clean::TyMethodItem(ref m) => method(w, item, m.header, &m.generics, &m.decl, link, parent), clean::TyMethodItem(ref m) => method(w, item, m.header, &m.generics, &m.decl, link, parent),
clean::MethodItem(ref m) => method(w, item, m.header, &m.generics, &m.decl, link, parent), clean::MethodItem(ref m, _) => {
method(w, item, m.header, &m.generics, &m.decl, link, parent)
}
clean::AssocConstItem(ref ty, ref default) => assoc_const( clean::AssocConstItem(ref ty, ref default) => assoc_const(
w, w,
item, item,
@ -3545,7 +3549,7 @@ fn render_deref_methods(
fn should_render_item(item: &clean::Item, deref_mut_: bool) -> bool { fn should_render_item(item: &clean::Item, deref_mut_: bool) -> bool {
let self_type_opt = match item.kind { let self_type_opt = match item.kind {
clean::MethodItem(ref method) => method.decl.self_type(), clean::MethodItem(ref method, _) => method.decl.self_type(),
clean::TyMethodItem(ref method) => method.decl.self_type(), clean::TyMethodItem(ref method) => method.decl.self_type(),
_ => None, _ => None,
}; };
@ -3752,7 +3756,7 @@ fn render_impl(
(true, " hidden") (true, " hidden")
}; };
match item.kind { match item.kind {
clean::MethodItem(_) | clean::TyMethodItem(_) => { clean::MethodItem(..) | clean::TyMethodItem(_) => {
// Only render when the method is not static or we allow static methods // Only render when the method is not static or we allow static methods
if render_method_item { if render_method_item {
let id = cx.derive_id(format!("{}.{}", item_type, name)); let id = cx.derive_id(format!("{}.{}", item_type, name));