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