Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc JSON: Use Function everywhere and remove Method #104499

Merged
merged 2 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
}
}
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/librustdoc/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,14 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
false
}

types::ItemEnum::Method(_)
types::ItemEnum::Function(_)
| types::ItemEnum::Module(_)
| types::ItemEnum::AssocConst { .. }
| types::ItemEnum::AssocType { .. } => true,
types::ItemEnum::ExternCrate { .. }
| types::ItemEnum::Import(_)
| types::ItemEnum::StructField(_)
| types::ItemEnum::Variant(_)
| types::ItemEnum::Function(_)
| types::ItemEnum::TraitAlias(_)
| types::ItemEnum::Impl(_)
| types::ItemEnum::Typedef(_)
Expand Down
11 changes: 1 addition & 10 deletions src/rustdoc-json-types/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -210,7 +210,6 @@ pub enum ItemKind {
Constant,
Trait,
TraitAlias,
Method,
Impl,
Static,
ForeignType,
Expand Down Expand Up @@ -243,7 +242,6 @@ pub enum ItemEnum {

Trait(Trait),
TraitAlias(TraitAlias),
Method(Method),
Impl(Impl),

Typedef(Typedef),
Expand Down Expand Up @@ -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,
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-json/impls/import_from_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/tools/jsondoclint/src/item_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub(crate) enum Kind {
Constant,
Trait,
TraitAlias,
Method,
Impl,
Static,
ForeignType,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 3 additions & 9 deletions src/tools/jsondoclint/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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_ {
Expand Down