rustdoc JSON: Use Function
everywhere and remove Method
This commit is contained in:
parent
6d651a295e
commit
8b5bfaf662
6 changed files with 13 additions and 48 deletions
|
@ -257,12 +257,12 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
|
|||
StructFieldItem(f) => ItemEnum::StructField(f.into_tcx(tcx)),
|
||||
EnumItem(e) => ItemEnum::Enum(e.into_tcx(tcx)),
|
||||
VariantItem(v) => ItemEnum::Variant(v.into_tcx(tcx)),
|
||||
FunctionItem(f) => ItemEnum::Function(from_function(f, header.unwrap(), tcx)),
|
||||
ForeignFunctionItem(f) => ItemEnum::Function(from_function(f, header.unwrap(), tcx)),
|
||||
FunctionItem(f) => ItemEnum::Function(from_function(f, true, header.unwrap(), tcx)),
|
||||
ForeignFunctionItem(f) => ItemEnum::Function(from_function(f, false, header.unwrap(), tcx)),
|
||||
TraitItem(t) => ItemEnum::Trait((*t).into_tcx(tcx)),
|
||||
TraitAliasItem(t) => ItemEnum::TraitAlias(t.into_tcx(tcx)),
|
||||
MethodItem(m, _) => ItemEnum::Method(from_function_method(m, true, header.unwrap(), tcx)),
|
||||
TyMethodItem(m) => ItemEnum::Method(from_function_method(m, false, header.unwrap(), tcx)),
|
||||
MethodItem(m, _) => ItemEnum::Function(from_function(m, true, header.unwrap(), tcx)),
|
||||
TyMethodItem(m) => ItemEnum::Function(from_function(m, false, header.unwrap(), tcx)),
|
||||
ImplItem(i) => ItemEnum::Impl((*i).into_tcx(tcx)),
|
||||
StaticItem(s) => ItemEnum::Static(s.into_tcx(tcx)),
|
||||
ForeignStaticItem(s) => ItemEnum::Static(s.into_tcx(tcx)),
|
||||
|
@ -618,6 +618,7 @@ impl FromWithTcx<clean::Impl> for Impl {
|
|||
|
||||
pub(crate) fn from_function(
|
||||
function: Box<clean::Function>,
|
||||
has_body: bool,
|
||||
header: rustc_hir::FnHeader,
|
||||
tcx: TyCtxt<'_>,
|
||||
) -> Function {
|
||||
|
@ -626,20 +627,6 @@ pub(crate) fn from_function(
|
|||
decl: decl.into_tcx(tcx),
|
||||
generics: generics.into_tcx(tcx),
|
||||
header: from_fn_header(&header),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn from_function_method(
|
||||
function: Box<clean::Function>,
|
||||
has_body: bool,
|
||||
header: rustc_hir::FnHeader,
|
||||
tcx: TyCtxt<'_>,
|
||||
) -> Method {
|
||||
let clean::Function { decl, generics } = *function;
|
||||
Method {
|
||||
decl: decl.into_tcx(tcx),
|
||||
generics: generics.into_tcx(tcx),
|
||||
header: from_fn_header(&header),
|
||||
has_body,
|
||||
}
|
||||
}
|
||||
|
@ -759,14 +746,13 @@ impl FromWithTcx<ItemType> for ItemKind {
|
|||
Struct => ItemKind::Struct,
|
||||
Union => ItemKind::Union,
|
||||
Enum => ItemKind::Enum,
|
||||
Function => ItemKind::Function,
|
||||
Function | TyMethod | Method => ItemKind::Function,
|
||||
Typedef => ItemKind::Typedef,
|
||||
OpaqueTy => ItemKind::OpaqueTy,
|
||||
Static => ItemKind::Static,
|
||||
Constant => ItemKind::Constant,
|
||||
Trait => ItemKind::Trait,
|
||||
Impl => ItemKind::Impl,
|
||||
TyMethod | Method => ItemKind::Method,
|
||||
StructField => ItemKind::StructField,
|
||||
Variant => ItemKind::Variant,
|
||||
Macro => ItemKind::Macro,
|
||||
|
|
|
@ -223,7 +223,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
|
|||
false
|
||||
}
|
||||
|
||||
types::ItemEnum::Method(_)
|
||||
types::ItemEnum::Function(_)
|
||||
| types::ItemEnum::Module(_)
|
||||
| types::ItemEnum::AssocConst { .. }
|
||||
| types::ItemEnum::AssocType { .. } => true,
|
||||
|
@ -231,7 +231,6 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
|
|||
| types::ItemEnum::Import(_)
|
||||
| types::ItemEnum::StructField(_)
|
||||
| types::ItemEnum::Variant(_)
|
||||
| types::ItemEnum::Function(_)
|
||||
| types::ItemEnum::TraitAlias(_)
|
||||
| types::ItemEnum::Impl(_)
|
||||
| types::ItemEnum::Typedef(_)
|
||||
|
|
|
@ -9,7 +9,7 @@ use std::path::PathBuf;
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// rustdoc format-version.
|
||||
pub const FORMAT_VERSION: u32 = 22;
|
||||
pub const FORMAT_VERSION: u32 = 23;
|
||||
|
||||
/// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information
|
||||
/// about the language items in the local crate, as well as info about external items to allow
|
||||
|
@ -210,7 +210,6 @@ pub enum ItemKind {
|
|||
Constant,
|
||||
Trait,
|
||||
TraitAlias,
|
||||
Method,
|
||||
Impl,
|
||||
Static,
|
||||
ForeignType,
|
||||
|
@ -243,7 +242,6 @@ pub enum ItemEnum {
|
|||
|
||||
Trait(Trait),
|
||||
TraitAlias(TraitAlias),
|
||||
Method(Method),
|
||||
Impl(Impl),
|
||||
|
||||
Typedef(Typedef),
|
||||
|
@ -420,13 +418,6 @@ pub struct Function {
|
|||
pub decl: FnDecl,
|
||||
pub generics: Generics,
|
||||
pub header: Header,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub struct Method {
|
||||
pub decl: FnDecl,
|
||||
pub generics: Generics,
|
||||
pub header: Header,
|
||||
pub has_body: bool,
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ mod bar {
|
|||
pub struct Baz;
|
||||
// @set impl = "$.index[*][?(@.kind=='impl')].id"
|
||||
impl Baz {
|
||||
// @set doit = "$.index[*][?(@.kind=='method')].id"
|
||||
// @set doit = "$.index[*][?(@.kind=='function')].id"
|
||||
pub fn doit() {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ pub(crate) enum Kind {
|
|||
Constant,
|
||||
Trait,
|
||||
TraitAlias,
|
||||
Method,
|
||||
Impl,
|
||||
Static,
|
||||
ForeignType,
|
||||
|
@ -63,7 +62,6 @@ impl Kind {
|
|||
// Only in traits
|
||||
AssocConst => false,
|
||||
AssocType => false,
|
||||
Method => false,
|
||||
|
||||
StructField => false, // Only in structs or variants
|
||||
Variant => false, // Only in enums
|
||||
|
@ -74,7 +72,7 @@ impl Kind {
|
|||
match self {
|
||||
Kind::AssocConst => true,
|
||||
Kind::AssocType => true,
|
||||
Kind::Method => true,
|
||||
Kind::Function => true,
|
||||
|
||||
Kind::Module => false,
|
||||
Kind::ExternCrate => false,
|
||||
|
@ -84,7 +82,6 @@ impl Kind {
|
|||
Kind::Union => false,
|
||||
Kind::Enum => false,
|
||||
Kind::Variant => false,
|
||||
Kind::Function => false,
|
||||
Kind::Typedef => false,
|
||||
Kind::OpaqueTy => false,
|
||||
Kind::Constant => false,
|
||||
|
@ -134,7 +131,6 @@ impl Kind {
|
|||
ItemEnum::Function(_) => Function,
|
||||
ItemEnum::Trait(_) => Trait,
|
||||
ItemEnum::TraitAlias(_) => TraitAlias,
|
||||
ItemEnum::Method(_) => Method,
|
||||
ItemEnum::Impl(_) => Impl,
|
||||
ItemEnum::Typedef(_) => Typedef,
|
||||
ItemEnum::OpaqueTy(_) => OpaqueTy,
|
||||
|
@ -164,7 +160,6 @@ impl Kind {
|
|||
ItemKind::Import => Import,
|
||||
ItemKind::Keyword => Keyword,
|
||||
ItemKind::Macro => Macro,
|
||||
ItemKind::Method => Method,
|
||||
ItemKind::Module => Module,
|
||||
ItemKind::OpaqueTy => OpaqueTy,
|
||||
ItemKind::Primitive => Primitive,
|
||||
|
|
|
@ -3,9 +3,9 @@ use std::hash::Hash;
|
|||
|
||||
use rustdoc_json_types::{
|
||||
Constant, Crate, DynTrait, Enum, FnDecl, Function, FunctionPointer, GenericArg, GenericArgs,
|
||||
GenericBound, GenericParamDef, Generics, Id, Impl, Import, ItemEnum, Method, Module, OpaqueTy,
|
||||
Path, Primitive, ProcMacro, Static, Struct, StructKind, Term, Trait, TraitAlias, Type,
|
||||
TypeBinding, TypeBindingKind, Typedef, Union, Variant, WherePredicate,
|
||||
GenericBound, GenericParamDef, Generics, Id, Impl, Import, ItemEnum, Module, OpaqueTy, Path,
|
||||
Primitive, ProcMacro, Static, Struct, StructKind, Term, Trait, TraitAlias, Type, TypeBinding,
|
||||
TypeBindingKind, Typedef, Union, Variant, WherePredicate,
|
||||
};
|
||||
|
||||
use crate::{item_kind::Kind, Error, ErrorKind};
|
||||
|
@ -67,7 +67,6 @@ impl<'a> Validator<'a> {
|
|||
ItemEnum::Function(x) => self.check_function(x),
|
||||
ItemEnum::Trait(x) => self.check_trait(x),
|
||||
ItemEnum::TraitAlias(x) => self.check_trait_alias(x),
|
||||
ItemEnum::Method(x) => self.check_method(x),
|
||||
ItemEnum::Impl(x) => self.check_impl(x),
|
||||
ItemEnum::Typedef(x) => self.check_typedef(x),
|
||||
ItemEnum::OpaqueTy(x) => self.check_opaque_ty(x),
|
||||
|
@ -176,11 +175,6 @@ impl<'a> Validator<'a> {
|
|||
x.params.iter().for_each(|i| self.check_generic_bound(i));
|
||||
}
|
||||
|
||||
fn check_method(&mut self, x: &'a Method) {
|
||||
self.check_fn_decl(&x.decl);
|
||||
self.check_generics(&x.generics);
|
||||
}
|
||||
|
||||
fn check_impl(&mut self, x: &'a Impl) {
|
||||
self.check_generics(&x.generics);
|
||||
if let Some(path) = &x.trait_ {
|
||||
|
|
Loading…
Add table
Reference in a new issue