Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5ac2f69

Browse files
committedJul 27, 2024·
polished out the rustdoc-json-types docs
1 parent 4980bf3 commit 5ac2f69

File tree

1 file changed

+85
-45
lines changed

1 file changed

+85
-45
lines changed
 

‎src/rustdoc-json-types/lib.rs

Lines changed: 85 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ pub struct Item {
9797
pub links: FxHashMap<String, Id>,
9898
/// Stringified versions of the attributes on this item (e.g. `"#[inline]"`)
9999
pub attrs: Vec<String>,
100-
/// Information about the Item’s deprecation, if present.
100+
/// Information about the item’s deprecation, if present.
101101
pub deprecation: Option<Deprecation>,
102-
/// The type-specific fields describing this Item.
102+
/// The type-specific fields describing this item.
103103
pub inner: ItemEnum,
104104
}
105105

@@ -117,7 +117,7 @@ pub struct Span {
117117
/// Information about the deprecation of an [`Item`].
118118
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
119119
pub struct Deprecation {
120-
/// Usually a version number when this Item first became deprecated.
120+
/// Usually a version number when this [`Item`] first became deprecated.
121121
pub since: Option<String>,
122122
/// The reason for deprecation and/or what alternatives to use.
123123
pub note: Option<String>,
@@ -138,8 +138,10 @@ pub enum Visibility {
138138
Restricted {
139139
/// ID of the module to which this visibility restricts items.
140140
parent: Id,
141-
/// The path with which `parent` was referenced
142-
/// (like `"super::super"` or `"crate::foo::bar"`).
141+
/// The path with which [`parent`] was referenced
142+
/// (like `super::super` or `crate::foo::bar`).
143+
///
144+
/// [`parent`]: Visibility::Restricted::parent
143145
path: String,
144146
},
145147
}
@@ -203,7 +205,8 @@ pub enum GenericArgs {
203205
}
204206

205207
/// One argument in a list of generic arguments to a path segment.
206-
/// See [`GenericArgs`].
208+
///
209+
/// Part of [`GenericArgs`].
207210
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
208211
#[serde(rename_all = "snake_case")]
209212
pub enum GenericArg {
@@ -264,7 +267,6 @@ pub struct TypeBinding {
264267
}
265268

266269
/// The way in which an associate type/constant is bound.
267-
/// See [`TypeBinding`].
268270
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
269271
#[serde(rename_all = "snake_case")]
270272
pub enum TypeBindingKind {
@@ -299,7 +301,7 @@ pub struct Id(pub String);
299301

300302
/// The fundamental kind of an item. Unlike [`ItemEnum`], this does not carry any aditional info.
301303
///
302-
/// See [`ItemSummary`].
304+
/// Part of [`ItemSummary`].
303305
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
304306
#[serde(rename_all = "snake_case")]
305307
pub enum ItemKind {
@@ -317,7 +319,7 @@ pub enum ItemKind {
317319
Union,
318320
/// An `enum` declaration.
319321
Enum,
320-
/// A variant of a struct.
322+
/// A variant of a enum.
321323
Variant,
322324
/// A function declaration, e.g. `fn f() {}`
323325
Function,
@@ -329,39 +331,48 @@ pub enum ItemKind {
329331
/// A `trait` declaration.
330332
Trait,
331333
/// A trait alias declaration, e.g. `trait Int = Add + Sub + Mul + Div;`
334+
///
332335
/// See [the tracking issue](https://github.com/rust-lang/rust/issues/41517)
333336
TraitAlias,
334-
/// An implementation.
337+
/// An `impl` block.
335338
Impl,
336-
/// A declaration of a `static`.
339+
/// A `static` declaration.
337340
Static,
338341
/// `type`s from an `extern` block.
342+
///
339343
/// See [the tracking issue](https://github.com/rust-lang/rust/issues/43467)
340344
ForeignType,
341345
/// A macro declaration.
346+
///
342347
/// Corresponds to either `ItemEnum::Macro(_)`
343348
/// or `ItemEnum::ProcMacro(ProcMacro { kind: MacroKind::Bang })`
344349
Macro,
345350
/// A procedural macro attribute.
351+
///
346352
/// Corresponds to `ItemEnum::ProcMacro(ProcMacro { kind: MacroKind::Attr })`
347353
ProcAttribute,
348354
/// A procedural macro usable in the `#[derive()]` attribute.
355+
///
349356
/// Corresponds to `ItemEnum::ProcMacro(ProcMacro { kind: MacroKind::Derive })`
350357
ProcDerive,
351358
/// An associated constant of a trait or a type.
352359
AssocConst,
353360
/// An associated type of a trait or a type.
354361
AssocType,
355-
/// A primitive type, e.g. `u32`. Items of this kind only come from the core library.
362+
/// A primitive type, e.g. `u32`.
363+
///
364+
/// [`Item`]s of this kind only come from the core library.
356365
Primitive,
357-
/// A keyword declaration. Items of this kind only come from the come library and exist solely
366+
/// A keyword declaration.
367+
///
368+
/// [`Item`]s of this kind only come from the come library and exist solely
358369
/// to carry documentation for the respective keywords.
359370
Keyword,
360371
}
361372

362373
/// Specific fields of an item.
363374
///
364-
/// See [`Item`].
375+
/// Part of [`Item`].
365376
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
366377
#[serde(rename_all = "snake_case")]
367378
pub enum ItemEnum {
@@ -371,7 +382,7 @@ pub enum ItemEnum {
371382
ExternCrate {
372383
/// The name of the imported crate.
373384
name: String,
374-
/// If the crate is renamed, this is its name in the namespace.
385+
/// If the crate is renamed, this is its name in the crate.
375386
rename: Option<String>,
376387
},
377388
/// An import of 1 or more items into scope, using the `use` keyword.
@@ -385,7 +396,7 @@ pub enum ItemEnum {
385396
StructField(Type),
386397
/// An `enum` declaration.
387398
Enum(Enum),
388-
/// A variant of a struct.
399+
/// A variant of a enum.
389400
Variant(Variant),
390401

391402
/// A function declaration (including methods and other associated functions)
@@ -394,9 +405,10 @@ pub enum ItemEnum {
394405
/// A `trait` declaration.
395406
Trait(Trait),
396407
/// A trait alias declaration, e.g. `trait Int = Add + Sub + Mul + Div;`
408+
///
397409
/// See [the tracking issue](https://github.com/rust-lang/rust/issues/41517)
398410
TraitAlias(TraitAlias),
399-
/// An implementation.
411+
/// An `impl` block.
400412
Impl(Impl),
401413

402414
/// A type alias declaration, e.g. `type Pig = std::borrow::Cow<'static, str>;`
@@ -416,6 +428,7 @@ pub enum ItemEnum {
416428
Static(Static),
417429

418430
/// `type`s from an `extern` block.
431+
///
419432
/// See [the tracking issue](https://github.com/rust-lang/rust/issues/43467)
420433
ForeignType,
421434

@@ -425,7 +438,9 @@ pub enum ItemEnum {
425438
/// A procedural macro.
426439
ProcMacro(ProcMacro),
427440

428-
/// A primitive type, e.g. `u32`. Items of this kind only come from the core library.
441+
/// A primitive type, e.g. `u32`.
442+
///
443+
/// [`Item`]s of this kind only come from the core library.
429444
Primitive(Primitive),
430445

431446
/// An associated constant of a trait or a type.
@@ -466,10 +481,11 @@ pub enum ItemEnum {
466481
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
467482
pub struct Module {
468483
/// Whether this is the root item of a crate.
484+
///
469485
/// This item doesn't correspond to any construction in the source code and is generated by the
470486
/// compiler.
471487
pub is_crate: bool,
472-
/// Items declared inside this crate.
488+
/// [`Item`]s declared inside this module.
473489
pub items: Vec<Id>,
474490
/// If `true`, this module is not part of the public API, but it contains
475491
/// items that are re-exported as public API.
@@ -484,17 +500,20 @@ pub struct Union {
484500
/// Whether any fields have been removed from the result, due to being private or hidden.
485501
pub fields_stripped: bool,
486502
/// The list of fields in the union.
503+
///
487504
/// All of the corresponding [`Item`]s are of kind [`ItemEnum::StructField`].
488505
pub fields: Vec<Id>,
489506
/// All impls (both of traits and inherent) for this union.
507+
///
490508
/// All of the corresponding [`Item`]s are of kind [`ItemEnum::Impl`].
491509
pub impls: Vec<Id>,
492510
}
493511

494-
/// A structure.
512+
/// A `struct`.
495513
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
496514
pub struct Struct {
497-
/// The kind of struct.
515+
/// The kind of the struct (e.g. unit, tuple-like or struct-like) and the data specific to it,
516+
/// i.e. fields.
498517
pub kind: StructKind,
499518
/// The generic parameters and where clauses on this struct.
500519
pub generics: Generics,
@@ -503,7 +522,7 @@ pub struct Struct {
503522
pub impls: Vec<Id>,
504523
}
505524

506-
/// The kind of a struct and the data specific to it, e.g. fields.
525+
/// The kind of a [`Struct`] and the data specific to it, i.e. fields.
507526
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
508527
#[serde(rename_all = "snake_case")]
509528
pub enum StructKind {
@@ -532,6 +551,7 @@ pub enum StructKind {
532551
/// ```
533552
Plain {
534553
/// The list of fields in the struct.
554+
///
535555
/// All of the corresponding [`Item`]s are of kind [`ItemEnum::StructField`].
536556
fields: Vec<Id>,
537557
/// Whether any fields have been removed from the result, due to being private or hidden.
@@ -546,9 +566,11 @@ pub struct Enum {
546566
pub generics: Generics,
547567
/// Whether any variants have been removed from the result, due to being private or hidden.
548568
pub variants_stripped: bool,
549-
/// List of the IDs of the variants.
569+
/// The list of variants in the enum.
570+
///
571+
/// All of the corresponding [`Item`]s are of kind [`ItemEnum::Variant`]
550572
pub variants: Vec<Id>,
551-
/// Implementations for the enum.
573+
/// `impl`s for the enum.
552574
pub impls: Vec<Id>,
553575
}
554576

@@ -561,7 +583,7 @@ pub struct Variant {
561583
pub discriminant: Option<Discriminant>,
562584
}
563585

564-
/// The kind of an enum variant and the data specific to it, e.g. fields.
586+
/// The kind of an [`Enum`] [`Variant`] and the data specific to it, i.e. fields.
565587
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
566588
#[serde(rename_all = "snake_case")]
567589
pub enum VariantKind {
@@ -623,10 +645,9 @@ pub struct Discriminant {
623645
}
624646

625647
/// A set of fundamental properties of a function.
626-
/// See [`FnDecl`]
627648
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
628649
pub struct Header {
629-
/// Can this function be called at compile-time?
650+
/// Is this function marked as `const`?
630651
#[serde(rename = "const")]
631652
pub const_: bool,
632653
/// Is this function unsafe?
@@ -709,8 +730,7 @@ pub struct GenericParamDef {
709730
pub kind: GenericParamDefKind,
710731
}
711732

712-
/// The kind of a generic parameter.
713-
/// See [`GenericParamDef`].
733+
/// The kind of a [`GenericParamDef`].
714734
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
715735
#[serde(rename_all = "snake_case")]
716736
pub enum GenericParamDefKind {
@@ -909,7 +929,7 @@ pub enum Type {
909929
DynTrait(DynTrait),
910930
/// Parameterized types. The contained string is the name of the parameter.
911931
Generic(String),
912-
/// Built-in types, such as the integers, floating-point numbers, `bool`, and `char`.
932+
/// Built-in types, such as the integers, floating-point numbers, `bool`, `char`.
913933
Primitive(String),
914934
/// A function pointer type, e.g. `fn(u32) -> u32`, `extern "C" fn() -> *const u8`
915935
FunctionPointer(Box<FunctionPointer>),
@@ -927,6 +947,7 @@ pub enum Type {
927947
len: String,
928948
},
929949
/// A pattern type, e.g. `u32 is 1..`
950+
///
930951
/// See [the tracking issue](https://github.com/rust-lang/rust/issues/123646)
931952
Pat {
932953
/// The base type, e.g. the `u32` in `u32 is 1..`
@@ -951,9 +972,9 @@ pub enum Type {
951972
BorrowedRef {
952973
/// The name of the lifetime of the reference, if provided.
953974
lifetime: Option<String>,
954-
/// This is `true` for `&mut _` and `false` for `&_`
975+
/// This is `true` for `&mut i32` and `false` for `&i32`
955976
mutable: bool,
956-
/// The type of the pointee.
977+
/// The type of the pointee, e.g. the `i32` in `&'a mut i32`
957978
#[serde(rename = "type")]
958979
type_: Box<Type>,
959980
},
@@ -1054,7 +1075,7 @@ pub struct Trait {
10541075
pub is_unsafe: bool,
10551076
/// Whether the trait is [object safe](https://doc.rust-lang.org/reference/items/traits.html#object-safety).
10561077
pub is_object_safe: bool,
1057-
/// Items that can/must be implemented by the implementations.
1078+
/// Associated [`Item`]s that can/must be implemented by the `impl` blocks.
10581079
pub items: Vec<Id>,
10591080
/// Information about the type parameters and `where` clauses of the trait.
10601081
pub generics: Generics,
@@ -1065,6 +1086,7 @@ pub struct Trait {
10651086
}
10661087

10671088
/// A trait alias declaration, e.g. `trait Int = Add + Sub + Mul + Div;`
1089+
///
10681090
/// See [the tracking issue](https://github.com/rust-lang/rust/issues/41517)
10691091
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
10701092
pub struct TraitAlias {
@@ -1108,12 +1130,17 @@ pub struct Impl {
11081130
/// Whether this is an impl that’s implied by the compiler
11091131
/// (for autotraits, e.g. `Send` or `Sync`).
11101132
pub synthetic: bool,
1111-
/// The name of the generic parameter used for the blanket impl, if this impl was produced by
1112-
/// one. For example, for `impl<T, U> Into<U> for T` this field would be `"T"`.
1133+
/// If this is a blanket impl, the name with which [`for_`] is referred to in the original impl.
1134+
///
1135+
/// E.g., for `impl<T, U> Into<U> for T` this field would be `T`.
1136+
///
1137+
/// The contained [`Type`], if present, is always of kind [`Type::Generic`]
1138+
///
1139+
/// [`for_`]: Impl::for_
11131140
pub blanket_impl: Option<Type>,
11141141
}
11151142

1116-
/// An import of an item into scope.
1143+
/// A `use` statement.
11171144
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
11181145
#[serde(rename_all = "snake_case")]
11191146
pub struct Import {
@@ -1127,7 +1154,7 @@ pub struct Import {
11271154
/// pub use i32 as my_i32;
11281155
/// ```
11291156
pub id: Option<Id>,
1130-
/// Whether this import uses a glob: `use source::*;`
1157+
/// Whether this statement is a wildcard `use`, e.g. `use source::*;`
11311158
pub glob: bool,
11321159
}
11331160

@@ -1136,13 +1163,25 @@ pub struct Import {
11361163
pub struct ProcMacro {
11371164
/// How this macro is supposed to be called: `foo!()`, `#[foo]` or `#[derive(foo)]`
11381165
pub kind: MacroKind,
1139-
/// Helped attributes defined by a macro to be used inside it. Defined only be attribute &
1140-
/// derive macros.
1166+
/// Helper attributes defined by a macro to be used inside it.
1167+
///
1168+
/// Defined only for attribute & derive macros.
1169+
///
1170+
/// E.g. the [`Default`] derive macro defines a `#[default]` helper attribute so that one can
1171+
/// do:
1172+
///
1173+
/// ```rust
1174+
/// #[derive(Default)]
1175+
/// enum Option<T> {
1176+
/// #[default]
1177+
/// None,
1178+
/// Some(T),
1179+
/// }
1180+
/// ```
11411181
pub helpers: Vec<String>,
11421182
}
11431183

1144-
/// The way a procedural macro is declared to be used.
1145-
/// See [`ProcMacro`]
1184+
/// The way a [`ProcMacro`] is declared to be used.
11461185
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
11471186
#[serde(rename_all = "snake_case")]
11481187
pub enum MacroKind {
@@ -1170,23 +1209,24 @@ pub struct OpaqueTy {
11701209
pub generics: Generics,
11711210
}
11721211

1173-
/// A global variable declaration.
1212+
/// A `static` declaration.
11741213
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
11751214
pub struct Static {
11761215
/// The type of the static.
11771216
#[serde(rename = "type")]
11781217
pub type_: Type,
11791218
/// This is `true` for mutable statics, declared as `static mut X: T = f();`
11801219
pub mutable: bool,
1181-
/// The stringified expression for the initial value. It's not guaranteed that
1182-
/// it'll match the actual source code for the initial value.
1220+
/// The stringified expression for the initial value.
1221+
///
1222+
/// It's not guaranteed that it'll match the actual source code for the initial value.
11831223
pub expr: String,
11841224
}
11851225

11861226
/// A primitive type declaration. Declarations of this kind can only come from the core library.
11871227
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
11881228
pub struct Primitive {
1189-
/// The name of the library.
1229+
/// The name of the type.
11901230
pub name: String,
11911231
/// The implementations, inherent and of traits, on the primitive type.
11921232
pub impls: Vec<Id>,

0 commit comments

Comments
 (0)
Please sign in to comment.