Skip to content

Commit 8b5bfaf

Browse files
committed
rustdoc JSON: Use Function everywhere and remove Method
1 parent 6d651a2 commit 8b5bfaf

File tree

6 files changed

+13
-48
lines changed

6 files changed

+13
-48
lines changed

src/librustdoc/json/conversions.rs

+6-20
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,12 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
257257
StructFieldItem(f) => ItemEnum::StructField(f.into_tcx(tcx)),
258258
EnumItem(e) => ItemEnum::Enum(e.into_tcx(tcx)),
259259
VariantItem(v) => ItemEnum::Variant(v.into_tcx(tcx)),
260-
FunctionItem(f) => ItemEnum::Function(from_function(f, header.unwrap(), tcx)),
261-
ForeignFunctionItem(f) => ItemEnum::Function(from_function(f, header.unwrap(), tcx)),
260+
FunctionItem(f) => ItemEnum::Function(from_function(f, true, header.unwrap(), tcx)),
261+
ForeignFunctionItem(f) => ItemEnum::Function(from_function(f, false, header.unwrap(), tcx)),
262262
TraitItem(t) => ItemEnum::Trait((*t).into_tcx(tcx)),
263263
TraitAliasItem(t) => ItemEnum::TraitAlias(t.into_tcx(tcx)),
264-
MethodItem(m, _) => ItemEnum::Method(from_function_method(m, true, header.unwrap(), tcx)),
265-
TyMethodItem(m) => ItemEnum::Method(from_function_method(m, false, header.unwrap(), tcx)),
264+
MethodItem(m, _) => ItemEnum::Function(from_function(m, true, header.unwrap(), tcx)),
265+
TyMethodItem(m) => ItemEnum::Function(from_function(m, false, header.unwrap(), tcx)),
266266
ImplItem(i) => ItemEnum::Impl((*i).into_tcx(tcx)),
267267
StaticItem(s) => ItemEnum::Static(s.into_tcx(tcx)),
268268
ForeignStaticItem(s) => ItemEnum::Static(s.into_tcx(tcx)),
@@ -618,6 +618,7 @@ impl FromWithTcx<clean::Impl> for Impl {
618618

619619
pub(crate) fn from_function(
620620
function: Box<clean::Function>,
621+
has_body: bool,
621622
header: rustc_hir::FnHeader,
622623
tcx: TyCtxt<'_>,
623624
) -> Function {
@@ -626,20 +627,6 @@ pub(crate) fn from_function(
626627
decl: decl.into_tcx(tcx),
627628
generics: generics.into_tcx(tcx),
628629
header: from_fn_header(&header),
629-
}
630-
}
631-
632-
pub(crate) fn from_function_method(
633-
function: Box<clean::Function>,
634-
has_body: bool,
635-
header: rustc_hir::FnHeader,
636-
tcx: TyCtxt<'_>,
637-
) -> Method {
638-
let clean::Function { decl, generics } = *function;
639-
Method {
640-
decl: decl.into_tcx(tcx),
641-
generics: generics.into_tcx(tcx),
642-
header: from_fn_header(&header),
643630
has_body,
644631
}
645632
}
@@ -759,14 +746,13 @@ impl FromWithTcx<ItemType> for ItemKind {
759746
Struct => ItemKind::Struct,
760747
Union => ItemKind::Union,
761748
Enum => ItemKind::Enum,
762-
Function => ItemKind::Function,
749+
Function | TyMethod | Method => ItemKind::Function,
763750
Typedef => ItemKind::Typedef,
764751
OpaqueTy => ItemKind::OpaqueTy,
765752
Static => ItemKind::Static,
766753
Constant => ItemKind::Constant,
767754
Trait => ItemKind::Trait,
768755
Impl => ItemKind::Impl,
769-
TyMethod | Method => ItemKind::Method,
770756
StructField => ItemKind::StructField,
771757
Variant => ItemKind::Variant,
772758
Macro => ItemKind::Macro,

src/librustdoc/json/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,14 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
223223
false
224224
}
225225

226-
types::ItemEnum::Method(_)
226+
types::ItemEnum::Function(_)
227227
| types::ItemEnum::Module(_)
228228
| types::ItemEnum::AssocConst { .. }
229229
| types::ItemEnum::AssocType { .. } => true,
230230
types::ItemEnum::ExternCrate { .. }
231231
| types::ItemEnum::Import(_)
232232
| types::ItemEnum::StructField(_)
233233
| types::ItemEnum::Variant(_)
234-
| types::ItemEnum::Function(_)
235234
| types::ItemEnum::TraitAlias(_)
236235
| types::ItemEnum::Impl(_)
237236
| types::ItemEnum::Typedef(_)

src/rustdoc-json-types/lib.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::path::PathBuf;
99
use serde::{Deserialize, Serialize};
1010

1111
/// rustdoc format-version.
12-
pub const FORMAT_VERSION: u32 = 22;
12+
pub const FORMAT_VERSION: u32 = 23;
1313

1414
/// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information
1515
/// about the language items in the local crate, as well as info about external items to allow
@@ -210,7 +210,6 @@ pub enum ItemKind {
210210
Constant,
211211
Trait,
212212
TraitAlias,
213-
Method,
214213
Impl,
215214
Static,
216215
ForeignType,
@@ -243,7 +242,6 @@ pub enum ItemEnum {
243242

244243
Trait(Trait),
245244
TraitAlias(TraitAlias),
246-
Method(Method),
247245
Impl(Impl),
248246

249247
Typedef(Typedef),
@@ -420,13 +418,6 @@ pub struct Function {
420418
pub decl: FnDecl,
421419
pub generics: Generics,
422420
pub header: Header,
423-
}
424-
425-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
426-
pub struct Method {
427-
pub decl: FnDecl,
428-
pub generics: Generics,
429-
pub header: Header,
430421
pub has_body: bool,
431422
}
432423

src/test/rustdoc-json/impls/import_from_private.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod bar {
88
pub struct Baz;
99
// @set impl = "$.index[*][?(@.kind=='impl')].id"
1010
impl Baz {
11-
// @set doit = "$.index[*][?(@.kind=='method')].id"
11+
// @set doit = "$.index[*][?(@.kind=='function')].id"
1212
pub fn doit() {}
1313
}
1414
}

src/tools/jsondoclint/src/item_kind.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub(crate) enum Kind {
1717
Constant,
1818
Trait,
1919
TraitAlias,
20-
Method,
2120
Impl,
2221
Static,
2322
ForeignType,
@@ -63,7 +62,6 @@ impl Kind {
6362
// Only in traits
6463
AssocConst => false,
6564
AssocType => false,
66-
Method => false,
6765

6866
StructField => false, // Only in structs or variants
6967
Variant => false, // Only in enums
@@ -74,7 +72,7 @@ impl Kind {
7472
match self {
7573
Kind::AssocConst => true,
7674
Kind::AssocType => true,
77-
Kind::Method => true,
75+
Kind::Function => true,
7876

7977
Kind::Module => false,
8078
Kind::ExternCrate => false,
@@ -84,7 +82,6 @@ impl Kind {
8482
Kind::Union => false,
8583
Kind::Enum => false,
8684
Kind::Variant => false,
87-
Kind::Function => false,
8885
Kind::Typedef => false,
8986
Kind::OpaqueTy => false,
9087
Kind::Constant => false,
@@ -134,7 +131,6 @@ impl Kind {
134131
ItemEnum::Function(_) => Function,
135132
ItemEnum::Trait(_) => Trait,
136133
ItemEnum::TraitAlias(_) => TraitAlias,
137-
ItemEnum::Method(_) => Method,
138134
ItemEnum::Impl(_) => Impl,
139135
ItemEnum::Typedef(_) => Typedef,
140136
ItemEnum::OpaqueTy(_) => OpaqueTy,
@@ -164,7 +160,6 @@ impl Kind {
164160
ItemKind::Import => Import,
165161
ItemKind::Keyword => Keyword,
166162
ItemKind::Macro => Macro,
167-
ItemKind::Method => Method,
168163
ItemKind::Module => Module,
169164
ItemKind::OpaqueTy => OpaqueTy,
170165
ItemKind::Primitive => Primitive,

src/tools/jsondoclint/src/validator.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use std::hash::Hash;
33

44
use rustdoc_json_types::{
55
Constant, Crate, DynTrait, Enum, FnDecl, Function, FunctionPointer, GenericArg, GenericArgs,
6-
GenericBound, GenericParamDef, Generics, Id, Impl, Import, ItemEnum, Method, Module, OpaqueTy,
7-
Path, Primitive, ProcMacro, Static, Struct, StructKind, Term, Trait, TraitAlias, Type,
8-
TypeBinding, TypeBindingKind, Typedef, Union, Variant, WherePredicate,
6+
GenericBound, GenericParamDef, Generics, Id, Impl, Import, ItemEnum, Module, OpaqueTy, Path,
7+
Primitive, ProcMacro, Static, Struct, StructKind, Term, Trait, TraitAlias, Type, TypeBinding,
8+
TypeBindingKind, Typedef, Union, Variant, WherePredicate,
99
};
1010

1111
use crate::{item_kind::Kind, Error, ErrorKind};
@@ -67,7 +67,6 @@ impl<'a> Validator<'a> {
6767
ItemEnum::Function(x) => self.check_function(x),
6868
ItemEnum::Trait(x) => self.check_trait(x),
6969
ItemEnum::TraitAlias(x) => self.check_trait_alias(x),
70-
ItemEnum::Method(x) => self.check_method(x),
7170
ItemEnum::Impl(x) => self.check_impl(x),
7271
ItemEnum::Typedef(x) => self.check_typedef(x),
7372
ItemEnum::OpaqueTy(x) => self.check_opaque_ty(x),
@@ -176,11 +175,6 @@ impl<'a> Validator<'a> {
176175
x.params.iter().for_each(|i| self.check_generic_bound(i));
177176
}
178177

179-
fn check_method(&mut self, x: &'a Method) {
180-
self.check_fn_decl(&x.decl);
181-
self.check_generics(&x.generics);
182-
}
183-
184178
fn check_impl(&mut self, x: &'a Impl) {
185179
self.check_generics(&x.generics);
186180
if let Some(path) = &x.trait_ {

0 commit comments

Comments
 (0)