Rollup merge of #104499 - Enselic:no-method-in-rustdoc-json, r=GuillaumeGomez
rustdoc JSON: Use `Function` everywhere and remove `Method` Closes #100259
This commit is contained in:
commit
4300b9e5cf
6 changed files with 14 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)),
|
StructFieldItem(f) => ItemEnum::StructField(f.into_tcx(tcx)),
|
||||||
EnumItem(e) => ItemEnum::Enum(e.into_tcx(tcx)),
|
EnumItem(e) => ItemEnum::Enum(e.into_tcx(tcx)),
|
||||||
VariantItem(v) => ItemEnum::Variant(v.into_tcx(tcx)),
|
VariantItem(v) => ItemEnum::Variant(v.into_tcx(tcx)),
|
||||||
FunctionItem(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, header.unwrap(), tcx)),
|
ForeignFunctionItem(f) => ItemEnum::Function(from_function(f, false, header.unwrap(), tcx)),
|
||||||
TraitItem(t) => ItemEnum::Trait((*t).into_tcx(tcx)),
|
TraitItem(t) => ItemEnum::Trait((*t).into_tcx(tcx)),
|
||||||
TraitAliasItem(t) => ItemEnum::TraitAlias(t.into_tcx(tcx)),
|
TraitAliasItem(t) => ItemEnum::TraitAlias(t.into_tcx(tcx)),
|
||||||
MethodItem(m, _) => ItemEnum::Method(from_function_method(m, true, header.unwrap(), tcx)),
|
MethodItem(m, _) => ItemEnum::Function(from_function(m, true, header.unwrap(), tcx)),
|
||||||
TyMethodItem(m) => ItemEnum::Method(from_function_method(m, false, header.unwrap(), tcx)),
|
TyMethodItem(m) => ItemEnum::Function(from_function(m, false, header.unwrap(), tcx)),
|
||||||
ImplItem(i) => ItemEnum::Impl((*i).into_tcx(tcx)),
|
ImplItem(i) => ItemEnum::Impl((*i).into_tcx(tcx)),
|
||||||
StaticItem(s) => ItemEnum::Static(s.into_tcx(tcx)),
|
StaticItem(s) => ItemEnum::Static(s.into_tcx(tcx)),
|
||||||
ForeignStaticItem(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(
|
pub(crate) fn from_function(
|
||||||
function: Box<clean::Function>,
|
function: Box<clean::Function>,
|
||||||
|
has_body: bool,
|
||||||
header: rustc_hir::FnHeader,
|
header: rustc_hir::FnHeader,
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
) -> Function {
|
) -> Function {
|
||||||
|
@ -626,20 +627,6 @@ pub(crate) fn from_function(
|
||||||
decl: decl.into_tcx(tcx),
|
decl: decl.into_tcx(tcx),
|
||||||
generics: generics.into_tcx(tcx),
|
generics: generics.into_tcx(tcx),
|
||||||
header: from_fn_header(&header),
|
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,
|
has_body,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -759,14 +746,13 @@ impl FromWithTcx<ItemType> for ItemKind {
|
||||||
Struct => ItemKind::Struct,
|
Struct => ItemKind::Struct,
|
||||||
Union => ItemKind::Union,
|
Union => ItemKind::Union,
|
||||||
Enum => ItemKind::Enum,
|
Enum => ItemKind::Enum,
|
||||||
Function => ItemKind::Function,
|
Function | TyMethod | Method => ItemKind::Function,
|
||||||
Typedef => ItemKind::Typedef,
|
Typedef => ItemKind::Typedef,
|
||||||
OpaqueTy => ItemKind::OpaqueTy,
|
OpaqueTy => ItemKind::OpaqueTy,
|
||||||
Static => ItemKind::Static,
|
Static => ItemKind::Static,
|
||||||
Constant => ItemKind::Constant,
|
Constant => ItemKind::Constant,
|
||||||
Trait => ItemKind::Trait,
|
Trait => ItemKind::Trait,
|
||||||
Impl => ItemKind::Impl,
|
Impl => ItemKind::Impl,
|
||||||
TyMethod | Method => ItemKind::Method,
|
|
||||||
StructField => ItemKind::StructField,
|
StructField => ItemKind::StructField,
|
||||||
Variant => ItemKind::Variant,
|
Variant => ItemKind::Variant,
|
||||||
Macro => ItemKind::Macro,
|
Macro => ItemKind::Macro,
|
||||||
|
|
|
@ -223,7 +223,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
types::ItemEnum::Method(_)
|
types::ItemEnum::Function(_)
|
||||||
| types::ItemEnum::Module(_)
|
| types::ItemEnum::Module(_)
|
||||||
| types::ItemEnum::AssocConst { .. }
|
| types::ItemEnum::AssocConst { .. }
|
||||||
| types::ItemEnum::AssocType { .. } => true,
|
| types::ItemEnum::AssocType { .. } => true,
|
||||||
|
@ -231,7 +231,6 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
|
||||||
| types::ItemEnum::Import(_)
|
| types::ItemEnum::Import(_)
|
||||||
| types::ItemEnum::StructField(_)
|
| types::ItemEnum::StructField(_)
|
||||||
| types::ItemEnum::Variant(_)
|
| types::ItemEnum::Variant(_)
|
||||||
| types::ItemEnum::Function(_)
|
|
||||||
| types::ItemEnum::TraitAlias(_)
|
| types::ItemEnum::TraitAlias(_)
|
||||||
| types::ItemEnum::Impl(_)
|
| types::ItemEnum::Impl(_)
|
||||||
| types::ItemEnum::Typedef(_)
|
| types::ItemEnum::Typedef(_)
|
||||||
|
|
|
@ -9,7 +9,7 @@ use std::path::PathBuf;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// rustdoc format-version.
|
/// 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
|
/// 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
|
/// 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,
|
Constant,
|
||||||
Trait,
|
Trait,
|
||||||
TraitAlias,
|
TraitAlias,
|
||||||
Method,
|
|
||||||
Impl,
|
Impl,
|
||||||
Static,
|
Static,
|
||||||
ForeignType,
|
ForeignType,
|
||||||
|
@ -243,7 +242,6 @@ pub enum ItemEnum {
|
||||||
|
|
||||||
Trait(Trait),
|
Trait(Trait),
|
||||||
TraitAlias(TraitAlias),
|
TraitAlias(TraitAlias),
|
||||||
Method(Method),
|
|
||||||
Impl(Impl),
|
Impl(Impl),
|
||||||
|
|
||||||
Typedef(Typedef),
|
Typedef(Typedef),
|
||||||
|
@ -415,18 +413,12 @@ pub enum Abi {
|
||||||
Other(String),
|
Other(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Represents a function (including methods and other associated functions)
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||||
pub struct Function {
|
pub struct Function {
|
||||||
pub decl: FnDecl,
|
pub decl: FnDecl,
|
||||||
pub generics: Generics,
|
pub generics: Generics,
|
||||||
pub header: Header,
|
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,
|
pub has_body: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ mod bar {
|
||||||
pub struct Baz;
|
pub struct Baz;
|
||||||
// @set impl = "$.index[*][?(@.kind=='impl')].id"
|
// @set impl = "$.index[*][?(@.kind=='impl')].id"
|
||||||
impl Baz {
|
impl Baz {
|
||||||
// @set doit = "$.index[*][?(@.kind=='method')].id"
|
// @set doit = "$.index[*][?(@.kind=='function')].id"
|
||||||
pub fn doit() {}
|
pub fn doit() {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ pub(crate) enum Kind {
|
||||||
Constant,
|
Constant,
|
||||||
Trait,
|
Trait,
|
||||||
TraitAlias,
|
TraitAlias,
|
||||||
Method,
|
|
||||||
Impl,
|
Impl,
|
||||||
Static,
|
Static,
|
||||||
ForeignType,
|
ForeignType,
|
||||||
|
@ -63,7 +62,6 @@ impl Kind {
|
||||||
// Only in traits
|
// Only in traits
|
||||||
AssocConst => false,
|
AssocConst => false,
|
||||||
AssocType => false,
|
AssocType => false,
|
||||||
Method => false,
|
|
||||||
|
|
||||||
StructField => false, // Only in structs or variants
|
StructField => false, // Only in structs or variants
|
||||||
Variant => false, // Only in enums
|
Variant => false, // Only in enums
|
||||||
|
@ -74,7 +72,7 @@ impl Kind {
|
||||||
match self {
|
match self {
|
||||||
Kind::AssocConst => true,
|
Kind::AssocConst => true,
|
||||||
Kind::AssocType => true,
|
Kind::AssocType => true,
|
||||||
Kind::Method => true,
|
Kind::Function => true,
|
||||||
|
|
||||||
Kind::Module => false,
|
Kind::Module => false,
|
||||||
Kind::ExternCrate => false,
|
Kind::ExternCrate => false,
|
||||||
|
@ -84,7 +82,6 @@ impl Kind {
|
||||||
Kind::Union => false,
|
Kind::Union => false,
|
||||||
Kind::Enum => false,
|
Kind::Enum => false,
|
||||||
Kind::Variant => false,
|
Kind::Variant => false,
|
||||||
Kind::Function => false,
|
|
||||||
Kind::Typedef => false,
|
Kind::Typedef => false,
|
||||||
Kind::OpaqueTy => false,
|
Kind::OpaqueTy => false,
|
||||||
Kind::Constant => false,
|
Kind::Constant => false,
|
||||||
|
@ -134,7 +131,6 @@ impl Kind {
|
||||||
ItemEnum::Function(_) => Function,
|
ItemEnum::Function(_) => Function,
|
||||||
ItemEnum::Trait(_) => Trait,
|
ItemEnum::Trait(_) => Trait,
|
||||||
ItemEnum::TraitAlias(_) => TraitAlias,
|
ItemEnum::TraitAlias(_) => TraitAlias,
|
||||||
ItemEnum::Method(_) => Method,
|
|
||||||
ItemEnum::Impl(_) => Impl,
|
ItemEnum::Impl(_) => Impl,
|
||||||
ItemEnum::Typedef(_) => Typedef,
|
ItemEnum::Typedef(_) => Typedef,
|
||||||
ItemEnum::OpaqueTy(_) => OpaqueTy,
|
ItemEnum::OpaqueTy(_) => OpaqueTy,
|
||||||
|
@ -164,7 +160,6 @@ impl Kind {
|
||||||
ItemKind::Import => Import,
|
ItemKind::Import => Import,
|
||||||
ItemKind::Keyword => Keyword,
|
ItemKind::Keyword => Keyword,
|
||||||
ItemKind::Macro => Macro,
|
ItemKind::Macro => Macro,
|
||||||
ItemKind::Method => Method,
|
|
||||||
ItemKind::Module => Module,
|
ItemKind::Module => Module,
|
||||||
ItemKind::OpaqueTy => OpaqueTy,
|
ItemKind::OpaqueTy => OpaqueTy,
|
||||||
ItemKind::Primitive => Primitive,
|
ItemKind::Primitive => Primitive,
|
||||||
|
|
|
@ -3,9 +3,9 @@ use std::hash::Hash;
|
||||||
|
|
||||||
use rustdoc_json_types::{
|
use rustdoc_json_types::{
|
||||||
Constant, Crate, DynTrait, Enum, FnDecl, Function, FunctionPointer, GenericArg, GenericArgs,
|
Constant, Crate, DynTrait, Enum, FnDecl, Function, FunctionPointer, GenericArg, GenericArgs,
|
||||||
GenericBound, GenericParamDef, Generics, Id, Impl, Import, ItemEnum, Method, Module, OpaqueTy,
|
GenericBound, GenericParamDef, Generics, Id, Impl, Import, ItemEnum, Module, OpaqueTy, Path,
|
||||||
Path, Primitive, ProcMacro, Static, Struct, StructKind, Term, Trait, TraitAlias, Type,
|
Primitive, ProcMacro, Static, Struct, StructKind, Term, Trait, TraitAlias, Type, TypeBinding,
|
||||||
TypeBinding, TypeBindingKind, Typedef, Union, Variant, WherePredicate,
|
TypeBindingKind, Typedef, Union, Variant, WherePredicate,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{item_kind::Kind, Error, ErrorKind};
|
use crate::{item_kind::Kind, Error, ErrorKind};
|
||||||
|
@ -67,7 +67,6 @@ impl<'a> Validator<'a> {
|
||||||
ItemEnum::Function(x) => self.check_function(x),
|
ItemEnum::Function(x) => self.check_function(x),
|
||||||
ItemEnum::Trait(x) => self.check_trait(x),
|
ItemEnum::Trait(x) => self.check_trait(x),
|
||||||
ItemEnum::TraitAlias(x) => self.check_trait_alias(x),
|
ItemEnum::TraitAlias(x) => self.check_trait_alias(x),
|
||||||
ItemEnum::Method(x) => self.check_method(x),
|
|
||||||
ItemEnum::Impl(x) => self.check_impl(x),
|
ItemEnum::Impl(x) => self.check_impl(x),
|
||||||
ItemEnum::Typedef(x) => self.check_typedef(x),
|
ItemEnum::Typedef(x) => self.check_typedef(x),
|
||||||
ItemEnum::OpaqueTy(x) => self.check_opaque_ty(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));
|
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) {
|
fn check_impl(&mut self, x: &'a Impl) {
|
||||||
self.check_generics(&x.generics);
|
self.check_generics(&x.generics);
|
||||||
if let Some(path) = &x.trait_ {
|
if let Some(path) = &x.trait_ {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue