@@ -7,10 +7,16 @@ use rustc_hash::FxHashMap;
7
7
use serde:: { Deserialize , Serialize } ;
8
8
use std:: path:: PathBuf ;
9
9
10
- /// rustdoc format-version.
10
+ /// The version of JSON output that this crate represents.
11
+ ///
12
+ /// This integer is incremented with every breaking change to the API,
13
+ /// and is returned along with the JSON blob as [`Crate::format_version`].
14
+ /// Consuming code should assert that this value matches the format version(s) that it supports.
11
15
pub const FORMAT_VERSION : u32 = 32 ;
12
16
13
- /// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information
17
+ /// The root of the emitted JSON blob.
18
+ ///
19
+ /// It contains all type/documentation information
14
20
/// about the language items in the local crate, as well as info about external items to allow
15
21
/// tools to find or link to them.
16
22
#[ derive( Clone , Debug , PartialEq , Eq , Serialize , Deserialize ) ]
@@ -33,13 +39,18 @@ pub struct Crate {
33
39
pub format_version : u32 ,
34
40
}
35
41
42
+ /// Metadata of a crate, either the same crate on which `rustdoc` was invoked, or its dependency.
36
43
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
37
44
pub struct ExternalCrate {
45
+ /// The name of the crate.
38
46
pub name : String ,
47
+ /// The root URL at which the crate's documentation lives.
39
48
pub html_root_url : Option < String > ,
40
49
}
41
50
42
- /// For external (not defined in the local crate) items, you don't get the same level of
51
+ /// Information about an external (not defined in the local crate) [`Item`].
52
+ ///
53
+ /// For external items, you don't get the same level of
43
54
/// information. This struct should contain enough to generate a link/reference to the item in
44
55
/// question, or can be used by a tool that takes the json output of multiple crates to find
45
56
/// the actual item definition with all the relevant info.
@@ -60,6 +71,10 @@ pub struct ItemSummary {
60
71
pub kind : ItemKind ,
61
72
}
62
73
74
+ /// Anything that can hold documentation - modules, structs, enums, functions, traits, etc.
75
+ ///
76
+ /// The `Item` data type holds fields that can apply to any of these,
77
+ /// and leaves kind-specific details (like function args or enum variants) to the `inner` field.
63
78
#[ derive( Clone , Debug , PartialEq , Eq , Serialize , Deserialize ) ]
64
79
pub struct Item {
65
80
/// The unique identifier of this item. Can be used to find this item in various mappings.
@@ -82,10 +97,13 @@ pub struct Item {
82
97
pub links : FxHashMap < String , Id > ,
83
98
/// Stringified versions of the attributes on this item (e.g. `"#[inline]"`)
84
99
pub attrs : Vec < String > ,
100
+ /// Information about the item’s deprecation, if present.
85
101
pub deprecation : Option < Deprecation > ,
102
+ /// The type-specific fields describing this item.
86
103
pub inner : ItemEnum ,
87
104
}
88
105
106
+ /// A range of source code.
89
107
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
90
108
pub struct Span {
91
109
/// The path to the source file for this span relative to the path `rustdoc` was invoked with.
@@ -96,28 +114,39 @@ pub struct Span {
96
114
pub end : ( usize , usize ) ,
97
115
}
98
116
117
+ /// Information about the deprecation of an [`Item`].
99
118
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
100
119
pub struct Deprecation {
120
+ /// Usually a version number when this [`Item`] first became deprecated.
101
121
pub since : Option < String > ,
122
+ /// The reason for deprecation and/or what alternatives to use.
102
123
pub note : Option < String > ,
103
124
}
104
125
126
+ /// Visibility of an [`Item`].
105
127
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
106
128
#[ serde( rename_all = "snake_case" ) ]
107
129
pub enum Visibility {
130
+ /// Explicitly public visibility set with `pub`.
108
131
Public ,
109
132
/// For the most part items are private by default. The exceptions are associated items of
110
133
/// public traits and variants of public enums.
111
134
Default ,
135
+ /// Explicitly crate-wide visibility set with `pub(crate)`
112
136
Crate ,
113
- /// For `pub(in path)` visibility. `parent` is the module it's restricted to and `path` is how
114
- /// that module was referenced (like `"super::super"` or `"crate::foo::bar"`).
137
+ /// For `pub(in path)` visibility.
115
138
Restricted {
139
+ /// ID of the module to which this visibility restricts items.
116
140
parent : Id ,
141
+ /// The path with which [`parent`] was referenced
142
+ /// (like `super::super` or `crate::foo::bar`).
143
+ ///
144
+ /// [`parent`]: Visibility::Restricted::parent
117
145
path : String ,
118
146
} ,
119
147
}
120
148
149
+ /// Dynamic trait object type (`dyn Trait`).
121
150
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
122
151
pub struct DynTrait {
123
152
/// All the traits implemented. One of them is the vtable, and the rest must be auto traits.
@@ -132,64 +161,133 @@ pub struct DynTrait {
132
161
pub lifetime : Option < String > ,
133
162
}
134
163
135
- #[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
136
164
/// A trait and potential HRTBs
165
+ #[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
137
166
pub struct PolyTrait {
167
+ /// The path to the trait.
138
168
#[ serde( rename = "trait" ) ]
139
169
pub trait_ : Path ,
140
170
/// Used for Higher-Rank Trait Bounds (HRTBs)
141
171
/// ```text
142
172
/// dyn for<'a> Fn() -> &'a i32"
143
173
/// ^^^^^^^
144
- /// |
145
- /// this part
146
174
/// ```
147
175
pub generic_params : Vec < GenericParamDef > ,
148
176
}
149
177
178
+ /// A set of generic arguments provided to a path segment, e.g.
179
+ ///
180
+ /// ```text
181
+ /// std::option::Option::<u32>::None
182
+ /// ^^^^^
183
+ /// ```
150
184
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
151
185
#[ serde( rename_all = "snake_case" ) ]
152
186
pub enum GenericArgs {
153
- /// <'a, 32, B: Copy, C = u32>
154
- AngleBracketed { args : Vec < GenericArg > , bindings : Vec < TypeBinding > } ,
155
- /// Fn(A, B) -> C
156
- Parenthesized { inputs : Vec < Type > , output : Option < Type > } ,
187
+ /// `<'a, 32, B: Copy, C = u32>`
188
+ AngleBracketed {
189
+ /// The list of each argument on this type.
190
+ /// ```text
191
+ /// <'a, 32, B: Copy, C = u32>
192
+ /// ^^^^^^
193
+ /// ```
194
+ args : Vec < GenericArg > ,
195
+ /// Associated type or constant bindings (e.g. `Item=i32` or `Item: Clone`) for this type.
196
+ bindings : Vec < TypeBinding > ,
197
+ } ,
198
+ /// `Fn(A, B) -> C`
199
+ Parenthesized {
200
+ /// The input types, enclosed in parentheses.
201
+ inputs : Vec < Type > ,
202
+ /// The output type provided after the `->`, if present.
203
+ output : Option < Type > ,
204
+ } ,
157
205
}
158
206
207
+ /// One argument in a list of generic arguments to a path segment.
208
+ ///
209
+ /// Part of [`GenericArgs`].
159
210
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
160
211
#[ serde( rename_all = "snake_case" ) ]
161
212
pub enum GenericArg {
213
+ /// A lifetime argument.
214
+ /// ```text
215
+ /// std::borrow::Cow<'static, str>
216
+ /// ^^^^^^^
217
+ /// ```
162
218
Lifetime ( String ) ,
219
+ /// A type argument.
220
+ /// ```text
221
+ /// std::borrow::Cow<'static, str>
222
+ /// ^^^
223
+ /// ```
163
224
Type ( Type ) ,
225
+ /// A constant as a generic argument.
226
+ /// ```text
227
+ /// core::array::IntoIter<u32, { 640 * 1024 }>
228
+ /// ^^^^^^^^^^^^^^
229
+ /// ```
164
230
Const ( Constant ) ,
231
+ /// A generic argument that's explicitly set to be inferred.
232
+ /// ```text
233
+ /// std::vec::Vec::<_>::new()
234
+ /// ^
235
+ /// ```
165
236
Infer ,
166
237
}
167
238
239
+ /// A constant.
168
240
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
169
241
pub struct Constant {
242
+ /// The stringified expression of this constant. Note that its mapping to the original
243
+ /// source code is unstable and it's not guaranteed that it'll match the source code.
170
244
pub expr : String ,
245
+ /// The value of the evaluated expression for this constant, which is only computed for numeric
246
+ /// types.
171
247
pub value : Option < String > ,
248
+ /// Whether this constant is a bool, numeric, string, or char literal.
172
249
pub is_literal : bool ,
173
250
}
174
251
252
+ /// Describes a bound applied to an associated type/constant.
253
+ ///
254
+ /// Example:
255
+ /// ```text
256
+ /// IntoIterator<Item = u32, IntoIter: Clone>
257
+ /// ^^^^^^^^^^ ^^^^^^^^^^^^^^^
258
+ /// ```
175
259
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
176
260
pub struct TypeBinding {
261
+ /// The name of the associated type/constant.
177
262
pub name : String ,
263
+ /// Arguments provided to the associated type/constant.
178
264
pub args : GenericArgs ,
265
+ /// The kind of bound applied to the associated type/constant.
179
266
pub binding : TypeBindingKind ,
180
267
}
181
268
269
+ /// The way in which an associate type/constant is bound.
182
270
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
183
271
#[ serde( rename_all = "snake_case" ) ]
184
272
pub enum TypeBindingKind {
273
+ /// The required value/type is specified exactly. e.g.
274
+ /// ```text
275
+ /// Iterator<Item = u32, IntoIter: DoubleEndedIterator>
276
+ /// ^^^^^^^^^^
277
+ /// ```
185
278
Equality ( Term ) ,
279
+ /// The type is required to satisfy a set of bounds.
280
+ /// ```text
281
+ /// Iterator<Item = u32, IntoIter: DoubleEndedIterator>
282
+ /// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
283
+ /// ```
186
284
Constraint ( Vec < GenericBound > ) ,
187
285
}
188
286
189
287
/// An opaque identifier for an item.
190
288
///
191
- /// It can be used to lookup in [Crate::index] or [Crate::paths] to resolve it
192
- /// to an [Item].
289
+ /// It can be used to lookup in [` Crate::index` ] or [` Crate::paths` ] to resolve it
290
+ /// to an [` Item` ].
193
291
///
194
292
/// Id's are only valid within a single JSON blob. They cannot be used to
195
293
/// resolve references between the JSON output's for different crates.
@@ -201,115 +299,230 @@ pub enum TypeBindingKind {
201
299
// FIXME(aDotInTheVoid): Consider making this non-public in rustdoc-types.
202
300
pub struct Id ( pub String ) ;
203
301
302
+ /// The fundamental kind of an item. Unlike [`ItemEnum`], this does not carry any aditional info.
303
+ ///
304
+ /// Part of [`ItemSummary`].
204
305
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
205
306
#[ serde( rename_all = "snake_case" ) ]
206
307
pub enum ItemKind {
308
+ /// A module declaration, e.g. `mod foo;` or `mod foo {}`
207
309
Module ,
310
+ /// A crate imported via the `extern crate` syntax.
208
311
ExternCrate ,
312
+ /// An import of 1 or more items into scope, using the `use` keyword.
209
313
Import ,
314
+ /// A `struct` declaration.
210
315
Struct ,
316
+ /// A field of a struct.
211
317
StructField ,
318
+ /// A `union` declaration.
212
319
Union ,
320
+ /// An `enum` declaration.
213
321
Enum ,
322
+ /// A variant of a enum.
214
323
Variant ,
324
+ /// A function declaration, e.g. `fn f() {}`
215
325
Function ,
326
+ /// A type alias declaration, e.g. `type Pig = std::borrow::Cow<'static, str>;`
216
327
TypeAlias ,
217
328
OpaqueTy ,
329
+ /// The declaration of a constant, e.g. `const GREETING: &str = "Hi :3";`
218
330
Constant ,
331
+ /// A `trait` declaration.
219
332
Trait ,
333
+ /// A trait alias declaration, e.g. `trait Int = Add + Sub + Mul + Div;`
334
+ ///
335
+ /// See [the tracking issue](https://github.com/rust-lang/rust/issues/41517)
220
336
TraitAlias ,
337
+ /// An `impl` block.
221
338
Impl ,
339
+ /// A `static` declaration.
222
340
Static ,
341
+ /// `type`s from an `extern` block.
342
+ ///
343
+ /// See [the tracking issue](https://github.com/rust-lang/rust/issues/43467)
223
344
ForeignType ,
345
+ /// A macro declaration.
346
+ ///
347
+ /// Corresponds to either `ItemEnum::Macro(_)`
348
+ /// or `ItemEnum::ProcMacro(ProcMacro { kind: MacroKind::Bang })`
224
349
Macro ,
350
+ /// A procedural macro attribute.
351
+ ///
352
+ /// Corresponds to `ItemEnum::ProcMacro(ProcMacro { kind: MacroKind::Attr })`
225
353
ProcAttribute ,
354
+ /// A procedural macro usable in the `#[derive()]` attribute.
355
+ ///
356
+ /// Corresponds to `ItemEnum::ProcMacro(ProcMacro { kind: MacroKind::Derive })`
226
357
ProcDerive ,
358
+ /// An associated constant of a trait or a type.
227
359
AssocConst ,
360
+ /// An associated type of a trait or a type.
228
361
AssocType ,
362
+ /// A primitive type, e.g. `u32`.
363
+ ///
364
+ /// [`Item`]s of this kind only come from the core library.
229
365
Primitive ,
366
+ /// A keyword declaration.
367
+ ///
368
+ /// [`Item`]s of this kind only come from the come library and exist solely
369
+ /// to carry documentation for the respective keywords.
230
370
Keyword ,
231
371
}
232
372
373
+ /// Specific fields of an item.
374
+ ///
375
+ /// Part of [`Item`].
233
376
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
234
377
#[ serde( rename_all = "snake_case" ) ]
235
378
pub enum ItemEnum {
379
+ /// A module declaration, e.g. `mod foo;` or `mod foo {}`
236
380
Module ( Module ) ,
381
+ /// A crate imported via the `extern crate` syntax.
237
382
ExternCrate {
383
+ /// The name of the imported crate.
238
384
name : String ,
385
+ /// If the crate is renamed, this is its name in the crate.
239
386
rename : Option < String > ,
240
387
} ,
388
+ /// An import of 1 or more items into scope, using the `use` keyword.
241
389
Import ( Import ) ,
242
390
391
+ /// A `union` declaration.
243
392
Union ( Union ) ,
393
+ /// A `struct` declaration.
244
394
Struct ( Struct ) ,
395
+ /// A field of a struct.
245
396
StructField ( Type ) ,
397
+ /// An `enum` declaration.
246
398
Enum ( Enum ) ,
399
+ /// A variant of a enum.
247
400
Variant ( Variant ) ,
248
401
402
+ /// A function declaration (including methods and other associated functions)
249
403
Function ( Function ) ,
250
404
405
+ /// A `trait` declaration.
251
406
Trait ( Trait ) ,
407
+ /// A trait alias declaration, e.g. `trait Int = Add + Sub + Mul + Div;`
408
+ ///
409
+ /// See [the tracking issue](https://github.com/rust-lang/rust/issues/41517)
252
410
TraitAlias ( TraitAlias ) ,
411
+ /// An `impl` block.
253
412
Impl ( Impl ) ,
254
413
414
+ /// A type alias declaration, e.g. `type Pig = std::borrow::Cow<'static, str>;`
255
415
TypeAlias ( TypeAlias ) ,
256
416
OpaqueTy ( OpaqueTy ) ,
417
+ /// The declaration of a constant, e.g. `const GREETING: &str = "Hi :3";`
257
418
Constant {
419
+ /// The type of the constant.
258
420
#[ serde( rename = "type" ) ]
259
421
type_ : Type ,
422
+ /// The declared constant itself.
260
423
#[ serde( rename = "const" ) ]
261
424
const_ : Constant ,
262
425
} ,
263
426
427
+ /// A declaration of a `static`.
264
428
Static ( Static ) ,
265
429
266
- /// `type`s from an extern block
430
+ /// `type`s from an `extern` block.
431
+ ///
432
+ /// See [the tracking issue](https://github.com/rust-lang/rust/issues/43467)
267
433
ForeignType ,
268
434
269
- /// Declarative macro_rules! macro
435
+ /// A macro_rules! declarative macro. Contains a single string with the source
436
+ /// representation of the macro with the patterns stripped.
270
437
Macro ( String ) ,
438
+ /// A procedural macro.
271
439
ProcMacro ( ProcMacro ) ,
272
440
441
+ /// A primitive type, e.g. `u32`.
442
+ ///
443
+ /// [`Item`]s of this kind only come from the core library.
273
444
Primitive ( Primitive ) ,
274
445
446
+ /// An associated constant of a trait or a type.
275
447
AssocConst {
448
+ /// The type of the constant.
276
449
#[ serde( rename = "type" ) ]
277
450
type_ : Type ,
278
- /// e.g. `const X: usize = 5;`
451
+ /// The stringified expression for the default value, if provided, e.g.
452
+ /// ```rust
453
+ /// const X: usize = 640 * 1024;
454
+ /// // ^^^^^^^^^^
455
+ /// ```
279
456
default : Option < String > ,
280
457
} ,
458
+ /// An associated type of a trait or a type.
281
459
AssocType {
460
+ /// The generic parameters and where clauses on ahis associated type.
282
461
generics : Generics ,
462
+ /// The bounds for this associated type. e.g.
463
+ /// ```rust
464
+ /// trait IntoIterator {
465
+ /// type Item;
466
+ /// type IntoIter: Iterator<Item = Self::Item>;
467
+ /// // ^^^^^^^^^^^^^^^^^^^^^^^^^^^
468
+ /// }
469
+ /// ```
283
470
bounds : Vec < GenericBound > ,
284
- /// e.g. `type X = usize;`
471
+ /// The default for this type, if provided, e.g.
472
+ /// ```rust
473
+ /// type X = usize;
474
+ /// // ^^^^^
475
+ /// ```
285
476
default : Option < Type > ,
286
477
} ,
287
478
}
288
479
480
+ /// A module declaration, e.g. `mod foo;` or `mod foo {}`.
289
481
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
290
482
pub struct Module {
483
+ /// Whether this is the root item of a crate.
484
+ ///
485
+ /// This item doesn't correspond to any construction in the source code and is generated by the
486
+ /// compiler.
291
487
pub is_crate : bool ,
488
+ /// [`Item`]s declared inside this module.
292
489
pub items : Vec < Id > ,
293
490
/// If `true`, this module is not part of the public API, but it contains
294
491
/// items that are re-exported as public API.
295
492
pub is_stripped : bool ,
296
493
}
297
494
495
+ /// A `union`.
298
496
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
299
497
pub struct Union {
498
+ /// The generic parameters and where clauses on this union.
300
499
pub generics : Generics ,
500
+ /// Whether any fields have been removed from the result, due to being private or hidden.
301
501
pub fields_stripped : bool ,
502
+ /// The list of fields in the union.
503
+ ///
504
+ /// All of the corresponding [`Item`]s are of kind [`ItemEnum::StructField`].
302
505
pub fields : Vec < Id > ,
506
+ /// All impls (both of traits and inherent) for this union.
507
+ ///
508
+ /// All of the corresponding [`Item`]s are of kind [`ItemEnum::Impl`].
303
509
pub impls : Vec < Id > ,
304
510
}
305
511
512
+ /// A `struct`.
306
513
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
307
514
pub struct 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.
308
517
pub kind : StructKind ,
518
+ /// The generic parameters and where clauses on this struct.
309
519
pub generics : Generics ,
520
+ /// All impls (both of traits and inherent) for this struct.
521
+ /// All of the corresponding [`Item`]s are of kind [`ItemEnum::Impl`].
310
522
pub impls : Vec < Id > ,
311
523
}
312
524
525
+ /// The kind of a [`Struct`] and the data specific to it, i.e. fields.
313
526
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
314
527
#[ serde( rename_all = "snake_case" ) ]
315
528
pub enum StructKind {
@@ -321,31 +534,47 @@ pub enum StructKind {
321
534
Unit ,
322
535
/// A struct with unnamed fields.
323
536
///
537
+ /// All [`Id`]'s will point to [`ItemEnum::StructField`].
538
+ /// Unlike most of JSON, private and `#[doc(hidden)]` fields will be given as `None`
539
+ /// instead of being omitted, because order matters.
540
+ ///
324
541
/// ```rust
325
542
/// pub struct TupleStruct(i32);
326
543
/// pub struct EmptyTupleStruct();
327
544
/// ```
328
- ///
329
- /// All [`Id`]'s will point to [`ItemEnum::StructField`]. Private and
330
- /// `#[doc(hidden)]` fields will be given as `None`
331
545
Tuple ( Vec < Option < Id > > ) ,
332
546
/// A struct with named fields.
333
547
///
334
548
/// ```rust
335
549
/// pub struct PlainStruct { x: i32 }
336
550
/// pub struct EmptyPlainStruct {}
337
551
/// ```
338
- Plain { fields : Vec < Id > , fields_stripped : bool } ,
552
+ Plain {
553
+ /// The list of fields in the struct.
554
+ ///
555
+ /// All of the corresponding [`Item`]s are of kind [`ItemEnum::StructField`].
556
+ fields : Vec < Id > ,
557
+ /// Whether any fields have been removed from the result, due to being private or hidden.
558
+ fields_stripped : bool ,
559
+ } ,
339
560
}
340
561
562
+ /// An `enum`.
341
563
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
342
564
pub struct Enum {
565
+ /// Information about the type parameters and `where` clauses of the enum.
343
566
pub generics : Generics ,
567
+ /// Whether any variants have been removed from the result, due to being private or hidden.
344
568
pub variants_stripped : bool ,
569
+ /// The list of variants in the enum.
570
+ ///
571
+ /// All of the corresponding [`Item`]s are of kind [`ItemEnum::Variant`]
345
572
pub variants : Vec < Id > ,
573
+ /// `impl`s for the enum.
346
574
pub impls : Vec < Id > ,
347
575
}
348
576
577
+ /// A variant of an enum.
349
578
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
350
579
pub struct Variant {
351
580
/// Whether the variant is plain, a tuple-like, or struct-like. Contains the fields.
@@ -354,6 +583,7 @@ pub struct Variant {
354
583
pub discriminant : Option < Discriminant > ,
355
584
}
356
585
586
+ /// The kind of an [`Enum`] [`Variant`] and the data specific to it, i.e. fields.
357
587
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
358
588
#[ serde( rename_all = "snake_case" ) ]
359
589
pub enum VariantKind {
@@ -368,7 +598,8 @@ pub enum VariantKind {
368
598
Plain ,
369
599
/// A variant with unnamed fields.
370
600
///
371
- /// Unlike most of json, `#[doc(hidden)]` fields will be given as `None`
601
+ /// All [`Id`]'s will point to [`ItemEnum::StructField`].
602
+ /// Unlike most of JSON, `#[doc(hidden)]` fields will be given as `None`
372
603
/// instead of being omitted, because order matters.
373
604
///
374
605
/// ```rust
@@ -386,9 +617,16 @@ pub enum VariantKind {
386
617
/// EmptyStructVariant {},
387
618
/// }
388
619
/// ```
389
- Struct { fields : Vec < Id > , fields_stripped : bool } ,
620
+ Struct {
621
+ /// The list of variants in the enum.
622
+ /// All of the corresponding [`Item`]s are of kind [`ItemEnum::Variant`].
623
+ fields : Vec < Id > ,
624
+ /// Whether any variants have been removed from the result, due to being private or hidden.
625
+ fields_stripped : bool ,
626
+ } ,
390
627
}
391
628
629
+ /// The value that distinguishes a variant in an [`Enum`] from other variants.
392
630
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
393
631
pub struct Discriminant {
394
632
/// The expression that produced the discriminant.
@@ -406,62 +644,123 @@ pub struct Discriminant {
406
644
pub value : String ,
407
645
}
408
646
647
+ /// A set of fundamental properties of a function.
409
648
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
410
649
pub struct Header {
650
+ /// Is this function marked as `const`?
411
651
#[ serde( rename = "const" ) ]
412
652
pub const_ : bool ,
653
+ /// Is this function unsafe?
413
654
#[ serde( rename = "unsafe" ) ]
414
655
pub unsafe_ : bool ,
656
+ /// Is this function async?
415
657
#[ serde( rename = "async" ) ]
416
658
pub async_ : bool ,
659
+ /// The ABI used by the function.
417
660
pub abi : Abi ,
418
661
}
419
662
663
+ /// The ABI (Application Binary Interface) used by a function.
664
+ ///
665
+ /// If a variant has an `unwind` field, this means the ABI that it represents can be specified in 2
666
+ /// ways: `extern "_"` and `extern "_-unwind"`, and a value of `true` for that field signifies the
667
+ /// latter variant.
668
+ ///
669
+ /// See the [Rustonomicon section](https://doc.rust-lang.org/nightly/nomicon/ffi.html#ffi-and-unwinding)
670
+ /// on unwinding for more info.
420
671
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
421
672
pub enum Abi {
422
673
// We only have a concrete listing here for stable ABI's because their are so many
423
674
// See rustc_ast_passes::feature_gate::PostExpansionVisitor::check_abi for the list
675
+ /// The default ABI, but that can also be written explicitly with `extern "Rust"`.
424
676
Rust ,
677
+ /// Can be specified as `extern "C"` or, as a shorthand, just `extern`.
425
678
C { unwind : bool } ,
679
+ /// Can be specified as `extern "cdecl"`.
426
680
Cdecl { unwind : bool } ,
681
+ /// Can be specified as `extern "stdcall"`.
427
682
Stdcall { unwind : bool } ,
683
+ /// Can be specified as `extern "fastcall"`.
428
684
Fastcall { unwind : bool } ,
685
+ /// Can be specified as `extern "aapcs"`.
429
686
Aapcs { unwind : bool } ,
687
+ /// Can be specified as `extern "win64"`.
430
688
Win64 { unwind : bool } ,
689
+ /// Can be specifed as `extern "sysv64"`.
431
690
SysV64 { unwind : bool } ,
691
+ /// Can be specified as `extern "system"`.
432
692
System { unwind : bool } ,
693
+ /// Any other ABI, including unstable ones.
433
694
Other ( String ) ,
434
695
}
435
696
436
- /// Represents a function (including methods and other associated functions)
697
+ /// A function declaration (including methods and other associated functions).
437
698
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
438
699
pub struct Function {
700
+ /// Information about the function signature, or declaration.
439
701
pub decl : FnDecl ,
702
+ /// Information about the function’s type parameters and `where` clauses.
440
703
pub generics : Generics ,
704
+ /// Information about core properties of the function, e.g. whether it's `const`, its ABI, etc.
441
705
pub header : Header ,
706
+ /// Whether the function has a body, i.e. an implementation.
442
707
pub has_body : bool ,
443
708
}
444
709
710
+ /// Generic parameters accepted by an item and `where` clauses imposed on it and the parameters.
445
711
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
446
712
pub struct Generics {
713
+ /// A list of generic parameter definitions (e.g. `<T: Clone + Hash, U: Copy>`).
447
714
pub params : Vec < GenericParamDef > ,
715
+ /// A list of where predicates (e.g. `where T: Iterator, T::Item: Copy`).
448
716
pub where_predicates : Vec < WherePredicate > ,
449
717
}
450
718
719
+ /// One generic parameter accepted by an item.
451
720
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
452
721
pub struct GenericParamDef {
722
+ /// Name of the parameter.
723
+ /// ```rust
724
+ /// fn f<'resource, Resource>(x: &'resource Resource) {}
725
+ /// // ^^^^^^^^ ^^^^^^^^
726
+ /// ```
453
727
pub name : String ,
728
+ /// The kind of the parameter and data specific to a particular parameter kind, e.g. type
729
+ /// bounds.
454
730
pub kind : GenericParamDefKind ,
455
731
}
456
732
733
+ /// The kind of a [`GenericParamDef`].
457
734
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
458
735
#[ serde( rename_all = "snake_case" ) ]
459
736
pub enum GenericParamDefKind {
737
+ /// Denotes a lifetime parameter.
460
738
Lifetime {
739
+ /// Lifetimes that this lifetime parameter is required to outlive.
740
+ ///
741
+ /// ```rust
742
+ /// fn f<'a, 'b, 'resource: 'a + 'b>(a: &'a str, b: &'b str, res: &'resource str) {}
743
+ /// // ^^^^^^^
744
+ /// ```
461
745
outlives : Vec < String > ,
462
746
} ,
747
+
748
+ /// Denotes a type parameter.
463
749
Type {
750
+ /// Bounds applied directly to the type. Note that the bounds from `where` clauses
751
+ /// that constrain this parameter won't appear here.
752
+ ///
753
+ /// ```rust
754
+ /// fn default2<T: Default>() -> [T; 2] where T: Clone { todo!() }
755
+ /// // ^^^^^^^
756
+ /// ```
464
757
bounds : Vec < GenericBound > ,
758
+ /// The default type for this parameter, if provided, e.g.
759
+ ///
760
+ /// ```rust
761
+ /// trait PartialEq<Rhs = Self> {}
762
+ /// // ^^^^
763
+ /// ```
465
764
default : Option < Type > ,
466
765
/// This is normally `false`, which means that this generic parameter is
467
766
/// declared in the Rust source text.
@@ -488,43 +787,75 @@ pub enum GenericParamDefKind {
488
787
/// the Rust source text.
489
788
synthetic : bool ,
490
789
} ,
790
+
791
+ /// Denotes a constant parameter.
491
792
Const {
793
+ /// The type of the constant as declared.
492
794
#[ serde( rename = "type" ) ]
493
795
type_ : Type ,
796
+ /// The stringified expression for the default value, if provided. It's not guaranteed that
797
+ /// it'll match the actual source code for the default value.
494
798
default : Option < String > ,
495
799
} ,
496
800
}
497
801
802
+ /// One `where` clause.
803
+ /// ```rust
804
+ /// fn default<T>() -> T where T: Default { T::default() }
805
+ /// // ^^^^^^^^^^
806
+ /// ```
498
807
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
499
808
#[ serde( rename_all = "snake_case" ) ]
500
809
pub enum WherePredicate {
810
+ /// A type is expected to comply with a set of bounds
501
811
BoundPredicate {
812
+ /// The type that's being constrained.
813
+ ///
814
+ /// ```rust
815
+ /// fn f<T>(x: T) where for<'a> &'a T: Iterator {}
816
+ /// // ^
817
+ /// ```
502
818
#[ serde( rename = "type" ) ]
503
819
type_ : Type ,
820
+ /// The set of bounds that constrain the type.
821
+ ///
822
+ /// ```rust
823
+ /// fn f<T>(x: T) where for<'a> &'a T: Iterator {}
824
+ /// // ^^^^^^^^
825
+ /// ```
504
826
bounds : Vec < GenericBound > ,
505
827
/// Used for Higher-Rank Trait Bounds (HRTBs)
506
- /// ```text
507
- /// where for<'a> &'a T: Iterator,"
508
- /// ^^^^^^^
509
- /// |
510
- /// this part
828
+ /// ```rust
829
+ /// fn f<T>(x: T) where for<'a> &'a T: Iterator {}
830
+ /// // ^^^^^^^
511
831
/// ```
512
832
generic_params : Vec < GenericParamDef > ,
513
833
} ,
834
+
835
+ /// A lifetime is expected to outlive other lifetimes.
514
836
LifetimePredicate {
837
+ /// The name of the lifetime.
515
838
lifetime : String ,
839
+ /// The lifetimes that must be encompassed by the lifetime.
516
840
outlives : Vec < String > ,
517
841
} ,
842
+
843
+ /// A type must exactly equal another type.
518
844
EqPredicate {
845
+ /// The left side of the equation.
519
846
lhs : Type ,
847
+ /// The right side of the equation.
520
848
rhs : Term ,
521
849
} ,
522
850
}
523
851
852
+ /// Either a trait bound or a lifetime bound.
524
853
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
525
854
#[ serde( rename_all = "snake_case" ) ]
526
855
pub enum GenericBound {
856
+ /// A trait bound.
527
857
TraitBound {
858
+ /// The full path to the trait.
528
859
#[ serde( rename = "trait" ) ]
529
860
trait_ : Path ,
530
861
/// Used for Higher-Rank Trait Bounds (HRTBs)
@@ -535,157 +866,277 @@ pub enum GenericBound {
535
866
/// this part
536
867
/// ```
537
868
generic_params : Vec < GenericParamDef > ,
869
+ /// The context for which a trait is supposed to be used, e.g. `const
538
870
modifier : TraitBoundModifier ,
539
871
} ,
872
+ /// A lifetime bound, e.g.
873
+ /// ```rust
874
+ /// fn f<'a, T>(x: &'a str, y: &T) where T: 'a {}
875
+ /// // ^^^
876
+ /// ```
540
877
Outlives ( String ) ,
541
878
/// `use<'a, T>` precise-capturing bound syntax
542
879
Use ( Vec < String > ) ,
543
880
}
544
881
882
+ /// A set of modifiers applied to a trait.
545
883
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
546
884
#[ serde( rename_all = "snake_case" ) ]
547
885
pub enum TraitBoundModifier {
886
+ /// Marks the absence of a modifier.
548
887
None ,
888
+ /// Indicates that the trait bound relaxes a trait bound applied to a parameter by default,
889
+ /// e.g. `T: Sized?`, the `Sized` trait is required for all generic type parameters by default
890
+ /// unless specified otherwise with this modifier.
549
891
Maybe ,
892
+ /// Indicates that the trait bound must be applicable in both a run-time and a compile-time
893
+ /// context.
550
894
MaybeConst ,
551
895
}
552
896
897
+ /// Either a type or a constant, usually stored as the right-hand side of an equation in places like
898
+ /// [`TypeBinding`]
553
899
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
554
900
#[ serde( rename_all = "snake_case" ) ]
555
901
pub enum Term {
902
+ /// A type.
903
+ ///
904
+ /// ```rust
905
+ /// fn f(x: impl IntoIterator<Item = u32>) {}
906
+ /// // ^^^
907
+ /// ```
556
908
Type ( Type ) ,
909
+ /// A constant.
910
+ ///
911
+ /// ```ignore (incomplete feature in the snippet)
912
+ /// trait Foo {
913
+ /// const BAR: usize;
914
+ /// }
915
+ ///
916
+ /// fn f(x: impl Foo<BAR = 42>) {}
917
+ /// // ^^
918
+ /// ```
557
919
Constant ( Constant ) ,
558
920
}
559
921
922
+ /// A type.
560
923
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
561
924
#[ serde( rename_all = "snake_case" ) ]
562
925
pub enum Type {
563
- /// Structs, enums, and unions
926
+ /// Structs, enums, unions and type aliases, e.g. `std::option::Option<u32>`
564
927
ResolvedPath ( Path ) ,
928
+ /// Dynamic trait object type (`dyn Trait`).
565
929
DynTrait ( DynTrait ) ,
566
- /// Parameterized types
930
+ /// Parameterized types. The contained string is the name of the parameter.
567
931
Generic ( String ) ,
568
- /// Built in numeric (i*, u*, f*) types, bool, and char
932
+ /// Built- in numeric types (e.g. `u32`, `f32`), ` bool`, ` char`.
569
933
Primitive ( String ) ,
570
- /// ` extern "ABI " fn`
934
+ /// A function pointer type, e.g. `fn(u32) -> u32`, ` extern "C " fn() -> *const u8 `
571
935
FunctionPointer ( Box < FunctionPointer > ) ,
572
- /// `(String, u32, Box<usize>)`
936
+ /// A tuple type, e.g. `(String, u32, Box<usize>)`
573
937
Tuple ( Vec < Type > ) ,
574
- /// `[u32]`
938
+ /// An unsized slice type, e.g. `[u32]`.
575
939
Slice ( Box < Type > ) ,
576
- /// [u32; 15]
940
+ /// An array type, e.g. ` [u32; 15]`
577
941
Array {
942
+ /// The type of the contained element.
578
943
#[ serde( rename = "type" ) ]
579
944
type_ : Box < Type > ,
945
+ /// The stringified expression that is the length of the array.
946
+ ///
947
+ /// Keep in mind that it's not guaranteed to match the actual source code of the expression.
580
948
len : String ,
581
949
} ,
582
- /// `u32 is 1..`
950
+ /// A pattern type, e.g. `u32 is 1..`
951
+ ///
952
+ /// See [the tracking issue](https://github.com/rust-lang/rust/issues/123646)
583
953
Pat {
954
+ /// The base type, e.g. the `u32` in `u32 is 1..`
584
955
#[ serde( rename = "type" ) ]
585
956
type_ : Box < Type > ,
586
957
#[ doc( hidden) ]
587
958
__pat_unstable_do_not_use : String ,
588
959
} ,
589
- /// `impl TraitA + TraitB + ...`
960
+ /// An opaque type that satisfies a set of bounds, `impl TraitA + TraitB + ...`
590
961
ImplTrait ( Vec < GenericBound > ) ,
591
- /// `_`
962
+ /// A type that's left to be inferred, `_`
592
963
Infer ,
593
- /// `*mut u32`, `*u8`, etc.
964
+ /// A raw pointer type, e.g. `*mut u32`, `*const u8`, etc.
594
965
RawPointer {
966
+ /// This is `true` for `*mut _` and `false` for `*const _`.
595
967
mutable : bool ,
968
+ /// The type of the pointee.
596
969
#[ serde( rename = "type" ) ]
597
970
type_ : Box < Type > ,
598
971
} ,
599
972
/// `&'a mut String`, `&str`, etc.
600
973
BorrowedRef {
974
+ /// The name of the lifetime of the reference, if provided.
601
975
lifetime : Option < String > ,
976
+ /// This is `true` for `&mut i32` and `false` for `&i32`
602
977
mutable : bool ,
978
+ /// The type of the pointee, e.g. the `i32` in `&'a mut i32`
603
979
#[ serde( rename = "type" ) ]
604
980
type_ : Box < Type > ,
605
981
} ,
606
982
/// Associated types like `<Type as Trait>::Name` and `T::Item` where
607
983
/// `T: Iterator` or inherent associated types like `Struct::Name`.
608
984
QualifiedPath {
985
+ /// The name of the associated type in the parent type.
986
+ ///
987
+ /// ```ignore (incomplete expresssion)
988
+ /// <core::array::IntoIter<u32, 42> as Iterator>::Item
989
+ /// // ^^^^
990
+ /// ```
609
991
name : String ,
992
+ /// The generic arguments provided to the associated type.
993
+ ///
994
+ /// ```ignore (incomplete expression)
995
+ /// <core::slice::IterMut<'static, u32> as BetterIterator>::Item<'static>
996
+ /// // ^^^^^^^^^
997
+ /// ```
610
998
args : Box < GenericArgs > ,
999
+ /// The type with which this type is associated.
1000
+ ///
1001
+ /// ```ignore (incomplete expression)
1002
+ /// <core::array::IntoIter<u32, 42> as Iterator>::Item
1003
+ /// // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1004
+ /// ```
611
1005
self_type : Box < Type > ,
612
1006
/// `None` iff this is an *inherent* associated type.
613
1007
#[ serde( rename = "trait" ) ]
614
1008
trait_ : Option < Path > ,
615
1009
} ,
616
1010
}
617
1011
1012
+ /// A type that has a simple path to it. This is the kind of type of structs, unions, enums, etc.
618
1013
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
619
1014
pub struct Path {
1015
+ /// The name of the type as declared, e.g. in
1016
+ ///
1017
+ /// ```rust
1018
+ /// mod foo {
1019
+ /// struct Bar;
1020
+ /// }
1021
+ /// ```
1022
+ ///
1023
+ /// for `foo::Bar`, this field will be `Bar`.
620
1024
pub name : String ,
1025
+ /// The ID of the type.
621
1026
pub id : Id ,
622
- /// Generic arguments to the type
623
- /// ```test
1027
+ /// Generic arguments to the type.
1028
+ ///
1029
+ /// ```ignore (incomplete expression)
624
1030
/// std::borrow::Cow<'static, str>
625
- /// ^^^^^^^^^^^^^^
626
- /// |
627
- /// this part
1031
+ /// // ^^^^^^^^^^^^^^
628
1032
/// ```
629
1033
pub args : Option < Box < GenericArgs > > ,
630
1034
}
631
1035
1036
+ /// A type that is a function pointer.
632
1037
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
633
1038
pub struct FunctionPointer {
1039
+ /// The signature of the function.
634
1040
pub decl : FnDecl ,
635
1041
/// Used for Higher-Rank Trait Bounds (HRTBs)
636
- /// ```text
637
- /// for<'c> fn(val: &'c i32) -> i32
638
- /// ^^^^^^^
639
- /// |
640
- /// this part
1042
+ ///
1043
+ /// ```ignore (incomplete expression)
1044
+ /// for<'c> fn(val: &'c i32) -> i32
1045
+ /// // ^^^^^^^
641
1046
/// ```
642
1047
pub generic_params : Vec < GenericParamDef > ,
1048
+ /// The core properties of the function, such as the ABI it conforms to, whether it's unsafe, etc.
643
1049
pub header : Header ,
644
1050
}
645
1051
1052
+ /// The signature of a function.
646
1053
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
647
1054
pub struct FnDecl {
648
1055
/// List of argument names and their type.
649
1056
///
650
1057
/// Note that not all names will be valid identifiers, as some of
651
1058
/// them may be patterns.
652
1059
pub inputs : Vec < ( String , Type ) > ,
1060
+ /// The output type, if specified.
653
1061
pub output : Option < Type > ,
1062
+ /// Whether the function accepts an arbitrary amount of trailing arguments the C way.
1063
+ ///
1064
+ /// ```ignore (incomplete code)
1065
+ /// fn printf(fmt: &str, ...);
1066
+ /// ```
654
1067
pub c_variadic : bool ,
655
1068
}
656
1069
1070
+ /// A `trait` declaration.
657
1071
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
658
1072
pub struct Trait {
1073
+ /// Whether the trait is marked `auto` and is thus implemented automatically
1074
+ /// for all aplicable types.
659
1075
pub is_auto : bool ,
1076
+ /// Whether the trait is marked as `unsafe`.
660
1077
pub is_unsafe : bool ,
1078
+ /// Whether the trait is [object safe](https://doc.rust-lang.org/reference/items/traits.html#object-safety).
661
1079
pub is_object_safe : bool ,
1080
+ /// Associated [`Item`]s that can/must be implemented by the `impl` blocks.
662
1081
pub items : Vec < Id > ,
1082
+ /// Information about the type parameters and `where` clauses of the trait.
663
1083
pub generics : Generics ,
1084
+ /// Constraints that must be met by the implementor of the trait.
664
1085
pub bounds : Vec < GenericBound > ,
1086
+ /// The implementations of the trait.
665
1087
pub implementations : Vec < Id > ,
666
1088
}
667
1089
1090
+ /// A trait alias declaration, e.g. `trait Int = Add + Sub + Mul + Div;`
1091
+ ///
1092
+ /// See [the tracking issue](https://github.com/rust-lang/rust/issues/41517)
668
1093
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
669
1094
pub struct TraitAlias {
1095
+ /// Information about the type parameters and `where` clauses of the alias.
670
1096
pub generics : Generics ,
1097
+ /// The bounds that are associated with the alias.
671
1098
pub params : Vec < GenericBound > ,
672
1099
}
673
1100
1101
+ /// An `impl` block.
674
1102
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
675
1103
pub struct Impl {
1104
+ /// Whether this impl is for an unsafe trait.
676
1105
pub is_unsafe : bool ,
1106
+ /// Information about the impl’s type parameters and `where` clauses.
677
1107
pub generics : Generics ,
1108
+ /// The list of the names of all the trait methods that weren't mentioned in this impl but
1109
+ /// were provided by the trait itself.
1110
+ ///
1111
+ /// For example, for this impl of the [`PartialEq`] trait:
1112
+ /// ```rust
1113
+ /// struct Foo;
1114
+ ///
1115
+ /// impl PartialEq for Foo {
1116
+ /// fn eq(&self, other: &Self) -> bool { todo!() }
1117
+ /// }
1118
+ /// ```
1119
+ /// This field will be `["ne"]`, as it has a default implementation defined for it.
678
1120
pub provided_trait_methods : Vec < String > ,
1121
+ /// The trait being implemented or `None` if the impl is inherent, which means
1122
+ /// `impl Struct {}` as opposed to `impl Trait for Struct {}`.
679
1123
#[ serde( rename = "trait" ) ]
680
1124
pub trait_ : Option < Path > ,
1125
+ /// The type that the impl block is for.
681
1126
#[ serde( rename = "for" ) ]
682
1127
pub for_ : Type ,
1128
+ /// The list of associated items contained in this impl block.
683
1129
pub items : Vec < Id > ,
1130
+ /// Whether this is a negative impl (e.g. `!Sized` or `!Send`).
684
1131
pub negative : bool ,
1132
+ /// Whether this is an impl that’s implied by the compiler
1133
+ /// (for autotraits, e.g. `Send` or `Sync`).
685
1134
pub synthetic : bool ,
1135
+ // FIXME: document this
686
1136
pub blanket_impl : Option < Type > ,
687
1137
}
688
1138
1139
+ /// A `use` statement.
689
1140
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
690
1141
#[ serde( rename_all = "snake_case" ) ]
691
1142
pub struct Import {
@@ -699,16 +1150,34 @@ pub struct Import {
699
1150
/// pub use i32 as my_i32;
700
1151
/// ```
701
1152
pub id : Option < Id > ,
702
- /// Whether this import uses a glob: `use source::*;`
1153
+ /// Whether this statement is a wildcard `use`, e.g. `use source::*;`
703
1154
pub glob : bool ,
704
1155
}
705
1156
1157
+ /// A procedural macro.
706
1158
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
707
1159
pub struct ProcMacro {
1160
+ /// How this macro is supposed to be called: `foo!()`, `#[foo]` or `#[derive(foo)]`
708
1161
pub kind : MacroKind ,
1162
+ /// Helper attributes defined by a macro to be used inside it.
1163
+ ///
1164
+ /// Defined only for attribute & derive macros.
1165
+ ///
1166
+ /// E.g. the [`Default`] derive macro defines a `#[default]` helper attribute so that one can
1167
+ /// do:
1168
+ ///
1169
+ /// ```rust
1170
+ /// #[derive(Default)]
1171
+ /// enum Option<T> {
1172
+ /// #[default]
1173
+ /// None,
1174
+ /// Some(T),
1175
+ /// }
1176
+ /// ```
709
1177
pub helpers : Vec < String > ,
710
1178
}
711
1179
1180
+ /// The way a [`ProcMacro`] is declared to be used.
712
1181
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
713
1182
#[ serde( rename_all = "snake_case" ) ]
714
1183
pub enum MacroKind {
@@ -720,10 +1189,13 @@ pub enum MacroKind {
720
1189
Derive ,
721
1190
}
722
1191
1192
+ /// A type alias declaration, e.g. `type Pig = std::borrow::Cow<'static, str>;`
723
1193
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
724
1194
pub struct TypeAlias {
1195
+ /// The type referred to by this alias.
725
1196
#[ serde( rename = "type" ) ]
726
1197
pub type_ : Type ,
1198
+ /// Information about the type parameters and `where` clauses of the alias.
727
1199
pub generics : Generics ,
728
1200
}
729
1201
@@ -733,17 +1205,26 @@ pub struct OpaqueTy {
733
1205
pub generics : Generics ,
734
1206
}
735
1207
1208
+ /// A `static` declaration.
736
1209
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
737
1210
pub struct Static {
1211
+ /// The type of the static.
738
1212
#[ serde( rename = "type" ) ]
739
1213
pub type_ : Type ,
1214
+ /// This is `true` for mutable statics, declared as `static mut X: T = f();`
740
1215
pub mutable : bool ,
1216
+ /// The stringified expression for the initial value.
1217
+ ///
1218
+ /// It's not guaranteed that it'll match the actual source code for the initial value.
741
1219
pub expr : String ,
742
1220
}
743
1221
1222
+ /// A primitive type declaration. Declarations of this kind can only come from the core library.
744
1223
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
745
1224
pub struct Primitive {
1225
+ /// The name of the type.
746
1226
pub name : String ,
1227
+ /// The implementations, inherent and of traits, on the primitive type.
747
1228
pub impls : Vec < Id > ,
748
1229
}
749
1230
0 commit comments