]> git.lizzy.rs Git - rust.git/blob - src/rustdoc-json-types/lib.rs
Rollup merge of #105859 - compiler-errors:hr-lifetime-add, r=davidtwco
[rust.git] / src / rustdoc-json-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 use std::collections::HashMap;
7 use std::path::PathBuf;
8
9 use serde::{Deserialize, Serialize};
10
11 /// rustdoc format-version.
12 pub const FORMAT_VERSION: u32 = 24;
13
14 /// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information
15 /// about the language items in the local crate, as well as info about external items to allow
16 /// tools to find or link to them.
17 #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
18 pub struct Crate {
19     /// The id of the root [`Module`] item of the local crate.
20     pub root: Id,
21     /// The version string given to `--crate-version`, if any.
22     pub crate_version: Option<String>,
23     /// Whether or not the output includes private items.
24     pub includes_private: bool,
25     /// A collection of all items in the local crate as well as some external traits and their
26     /// items that are referenced locally.
27     pub index: HashMap<Id, Item>,
28     /// Maps IDs to fully qualified paths and other info helpful for generating links.
29     pub paths: HashMap<Id, ItemSummary>,
30     /// Maps `crate_id` of items to a crate name and html_root_url if it exists.
31     pub external_crates: HashMap<u32, ExternalCrate>,
32     /// A single version number to be used in the future when making backwards incompatible changes
33     /// to the JSON output.
34     pub format_version: u32,
35 }
36
37 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
38 pub struct ExternalCrate {
39     pub name: String,
40     pub html_root_url: Option<String>,
41 }
42
43 /// For external (not defined in the local crate) items, you don't get the same level of
44 /// information. This struct should contain enough to generate a link/reference to the item in
45 /// question, or can be used by a tool that takes the json output of multiple crates to find
46 /// the actual item definition with all the relevant info.
47 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
48 pub struct ItemSummary {
49     /// Can be used to look up the name and html_root_url of the crate this item came from in the
50     /// `external_crates` map.
51     pub crate_id: u32,
52     /// The list of path components for the fully qualified path of this item (e.g.
53     /// `["std", "io", "lazy", "Lazy"]` for `std::io::lazy::Lazy`).
54     ///
55     /// Note that items can appear in multiple paths, and the one chosen is implementation
56     /// defined. Currently, this is the full path to where the item was defined. Eg
57     /// [`String`] is currently `["alloc", "string", "String"]` and [`HashMap`] is
58     /// `["std", "collections", "hash", "map", "HashMap"]`, but this is subject to change.
59     pub path: Vec<String>,
60     /// Whether this item is a struct, trait, macro, etc.
61     pub kind: ItemKind,
62 }
63
64 #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
65 pub struct Item {
66     /// The unique identifier of this item. Can be used to find this item in various mappings.
67     pub id: Id,
68     /// This can be used as a key to the `external_crates` map of [`Crate`] to see which crate
69     /// this item came from.
70     pub crate_id: u32,
71     /// Some items such as impls don't have names.
72     pub name: Option<String>,
73     /// The source location of this item (absent if it came from a macro expansion or inline
74     /// assembly).
75     pub span: Option<Span>,
76     /// By default all documented items are public, but you can tell rustdoc to output private items
77     /// so this field is needed to differentiate.
78     pub visibility: Visibility,
79     /// The full markdown docstring of this item. Absent if there is no documentation at all,
80     /// Some("") if there is some documentation but it is empty (EG `#[doc = ""]`).
81     pub docs: Option<String>,
82     /// 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
83     pub links: HashMap<String, Id>,
84     /// Stringified versions of the attributes on this item (e.g. `"#[inline]"`)
85     pub attrs: Vec<String>,
86     pub deprecation: Option<Deprecation>,
87     #[serde(flatten)]
88     pub inner: ItemEnum,
89 }
90
91 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
92 pub struct Span {
93     /// The path to the source file for this span relative to the path `rustdoc` was invoked with.
94     pub filename: PathBuf,
95     /// Zero indexed Line and Column of the first character of the `Span`
96     pub begin: (usize, usize),
97     /// Zero indexed Line and Column of the last character of the `Span`
98     pub end: (usize, usize),
99 }
100
101 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
102 pub struct Deprecation {
103     pub since: Option<String>,
104     pub note: Option<String>,
105 }
106
107 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
108 #[serde(rename_all = "snake_case")]
109 pub enum Visibility {
110     Public,
111     /// For the most part items are private by default. The exceptions are associated items of
112     /// public traits and variants of public enums.
113     Default,
114     Crate,
115     /// For `pub(in path)` visibility. `parent` is the module it's restricted to and `path` is how
116     /// that module was referenced (like `"super::super"` or `"crate::foo::bar"`).
117     Restricted {
118         parent: Id,
119         path: String,
120     },
121 }
122
123 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
124 pub struct DynTrait {
125     /// All the traits implemented. One of them is the vtable, and the rest must be auto traits.
126     pub traits: Vec<PolyTrait>,
127     /// The lifetime of the whole dyn object
128     /// ```text
129     /// dyn Debug + 'static
130     ///             ^^^^^^^
131     ///             |
132     ///             this part
133     /// ```
134     pub lifetime: Option<String>,
135 }
136
137 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
138 /// A trait and potential HRTBs
139 pub struct PolyTrait {
140     #[serde(rename = "trait")]
141     pub trait_: Path,
142     /// Used for Higher-Rank Trait Bounds (HRTBs)
143     /// ```text
144     /// dyn for<'a> Fn() -> &'a i32"
145     ///     ^^^^^^^
146     ///       |
147     ///       this part
148     /// ```
149     pub generic_params: Vec<GenericParamDef>,
150 }
151
152 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
153 #[serde(rename_all = "snake_case")]
154 pub enum GenericArgs {
155     /// <'a, 32, B: Copy, C = u32>
156     AngleBracketed { args: Vec<GenericArg>, bindings: Vec<TypeBinding> },
157     /// Fn(A, B) -> C
158     Parenthesized { inputs: Vec<Type>, output: Option<Type> },
159 }
160
161 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
162 #[serde(rename_all = "snake_case")]
163 pub enum GenericArg {
164     Lifetime(String),
165     Type(Type),
166     Const(Constant),
167     Infer,
168 }
169
170 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
171 pub struct Constant {
172     #[serde(rename = "type")]
173     pub type_: Type,
174     pub expr: String,
175     pub value: Option<String>,
176     pub is_literal: bool,
177 }
178
179 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
180 pub struct TypeBinding {
181     pub name: String,
182     pub args: GenericArgs,
183     pub binding: TypeBindingKind,
184 }
185
186 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
187 #[serde(rename_all = "snake_case")]
188 pub enum TypeBindingKind {
189     Equality(Term),
190     Constraint(Vec<GenericBound>),
191 }
192
193 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
194 pub struct Id(pub String);
195
196 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
197 #[serde(rename_all = "snake_case")]
198 pub enum ItemKind {
199     Module,
200     ExternCrate,
201     Import,
202     Struct,
203     StructField,
204     Union,
205     Enum,
206     Variant,
207     Function,
208     Typedef,
209     OpaqueTy,
210     Constant,
211     Trait,
212     TraitAlias,
213     Impl,
214     Static,
215     ForeignType,
216     Macro,
217     ProcAttribute,
218     ProcDerive,
219     AssocConst,
220     AssocType,
221     Primitive,
222     Keyword,
223 }
224
225 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
226 #[serde(tag = "kind", content = "inner", rename_all = "snake_case")]
227 pub enum ItemEnum {
228     Module(Module),
229     ExternCrate {
230         name: String,
231         rename: Option<String>,
232     },
233     Import(Import),
234
235     Union(Union),
236     Struct(Struct),
237     StructField(Type),
238     Enum(Enum),
239     Variant(Variant),
240
241     Function(Function),
242
243     Trait(Trait),
244     TraitAlias(TraitAlias),
245     Impl(Impl),
246
247     Typedef(Typedef),
248     OpaqueTy(OpaqueTy),
249     Constant(Constant),
250
251     Static(Static),
252
253     /// `type`s from an extern block
254     ForeignType,
255
256     /// Declarative macro_rules! macro
257     Macro(String),
258     ProcMacro(ProcMacro),
259
260     Primitive(Primitive),
261
262     AssocConst {
263         #[serde(rename = "type")]
264         type_: Type,
265         /// e.g. `const X: usize = 5;`
266         default: Option<String>,
267     },
268     AssocType {
269         generics: Generics,
270         bounds: Vec<GenericBound>,
271         /// e.g. `type X = usize;`
272         default: Option<Type>,
273     },
274 }
275
276 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
277 pub struct Module {
278     pub is_crate: bool,
279     pub items: Vec<Id>,
280     /// If `true`, this module is not part of the public API, but it contains
281     /// items that are re-exported as public API.
282     pub is_stripped: bool,
283 }
284
285 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
286 pub struct Union {
287     pub generics: Generics,
288     pub fields_stripped: bool,
289     pub fields: Vec<Id>,
290     pub impls: Vec<Id>,
291 }
292
293 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
294 pub struct Struct {
295     pub kind: StructKind,
296     pub generics: Generics,
297     pub impls: Vec<Id>,
298 }
299
300 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
301 #[serde(rename_all = "snake_case")]
302 pub enum StructKind {
303     /// A struct with no fields and no parentheses.
304     ///
305     /// ```rust
306     /// pub struct Unit;
307     /// ```
308     Unit,
309     /// A struct with unnamed fields.
310     ///
311     /// ```rust
312     /// pub struct TupleStruct(i32);
313     /// pub struct EmptyTupleStruct();
314     /// ```
315     ///
316     /// All [`Id`]'s will point to [`ItemEnum::StructField`]. Private and
317     /// `#[doc(hidden)]` fields will be given as `None`
318     Tuple(Vec<Option<Id>>),
319     /// A struct with nammed fields.
320     ///
321     /// ```rust
322     /// pub struct PlainStruct { x: i32 }
323     /// pub struct EmptyPlainStruct {}
324     /// ```
325     Plain { fields: Vec<Id>, fields_stripped: bool },
326 }
327
328 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
329 pub struct Enum {
330     pub generics: Generics,
331     pub variants_stripped: bool,
332     pub variants: Vec<Id>,
333     pub impls: Vec<Id>,
334 }
335
336 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
337 pub struct Variant {
338     /// Whether the variant is plain, a tuple-like, or struct-like. Contains the fields.
339     pub kind: VariantKind,
340     /// The discriminant, if explicitly specified.
341     pub discriminant: Option<Discriminant>,
342 }
343
344 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
345 #[serde(rename_all = "snake_case")]
346 pub enum VariantKind {
347     /// A variant with no parentheses
348     ///
349     /// ```rust
350     /// enum Demo {
351     ///     PlainVariant,
352     ///     PlainWithDiscriminant = 1,
353     /// }
354     /// ```
355     Plain,
356     /// A variant with unnamed fields.
357     ///
358     /// Unlike most of json, `#[doc(hidden)]` fields will be given as `None`
359     /// instead of being omitted, because order matters.
360     ///
361     /// ```rust
362     /// enum Demo {
363     ///     TupleVariant(i32),
364     ///     EmptyTupleVariant(),
365     /// }
366     /// ```
367     Tuple(Vec<Option<Id>>),
368     /// A variant with named fields.
369     ///
370     /// ```rust
371     /// enum Demo {
372     ///     StructVariant { x: i32 },
373     ///     EmptyStructVariant {},
374     /// }
375     /// ```
376     Struct { fields: Vec<Id>, fields_stripped: bool },
377 }
378
379 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
380 pub struct Discriminant {
381     /// The expression that produced the discriminant.
382     ///
383     /// Unlike `value`, this preserves the original formatting (eg suffixes,
384     /// hexadecimal, and underscores), making it unsuitable to be machine
385     /// interpreted.
386     ///
387     /// In some cases, when the value is to complex, this may be `"{ _ }"`.
388     /// When this occurs is unstable, and may change without notice.
389     pub expr: String,
390     /// The numerical value of the discriminant. Stored as a string due to
391     /// JSON's poor support for large integers, and the fact that it would need
392     /// to store from [`i128::MIN`] to [`u128::MAX`].
393     pub value: String,
394 }
395
396 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
397 pub struct Header {
398     #[serde(rename = "const")]
399     pub const_: bool,
400     #[serde(rename = "unsafe")]
401     pub unsafe_: bool,
402     #[serde(rename = "async")]
403     pub async_: bool,
404     pub abi: Abi,
405 }
406
407 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
408 pub enum Abi {
409     // We only have a concrete listing here for stable ABI's because their are so many
410     // See rustc_ast_passes::feature_gate::PostExpansionVisitor::check_abi for the list
411     Rust,
412     C { unwind: bool },
413     Cdecl { unwind: bool },
414     Stdcall { unwind: bool },
415     Fastcall { unwind: bool },
416     Aapcs { unwind: bool },
417     Win64 { unwind: bool },
418     SysV64 { unwind: bool },
419     System { unwind: bool },
420     Other(String),
421 }
422
423 /// Represents a function (including methods and other associated functions)
424 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
425 pub struct Function {
426     pub decl: FnDecl,
427     pub generics: Generics,
428     pub header: Header,
429     pub has_body: bool,
430 }
431
432 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
433 pub struct Generics {
434     pub params: Vec<GenericParamDef>,
435     pub where_predicates: Vec<WherePredicate>,
436 }
437
438 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
439 pub struct GenericParamDef {
440     pub name: String,
441     pub kind: GenericParamDefKind,
442 }
443
444 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
445 #[serde(rename_all = "snake_case")]
446 pub enum GenericParamDefKind {
447     Lifetime {
448         outlives: Vec<String>,
449     },
450     Type {
451         bounds: Vec<GenericBound>,
452         default: Option<Type>,
453         /// This is normally `false`, which means that this generic parameter is
454         /// declared in the Rust source text.
455         ///
456         /// If it is `true`, this generic parameter has been introduced by the
457         /// compiler behind the scenes.
458         ///
459         /// # Example
460         ///
461         /// Consider
462         ///
463         /// ```ignore (pseudo-rust)
464         /// pub fn f(_: impl Trait) {}
465         /// ```
466         ///
467         /// The compiler will transform this behind the scenes to
468         ///
469         /// ```ignore (pseudo-rust)
470         /// pub fn f<impl Trait: Trait>(_: impl Trait) {}
471         /// ```
472         ///
473         /// In this example, the generic parameter named `impl Trait` (and which
474         /// is bound by `Trait`) is synthetic, because it was not originally in
475         /// the Rust source text.
476         synthetic: bool,
477     },
478     Const {
479         #[serde(rename = "type")]
480         type_: Type,
481         default: Option<String>,
482     },
483 }
484
485 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
486 #[serde(rename_all = "snake_case")]
487 pub enum WherePredicate {
488     BoundPredicate {
489         #[serde(rename = "type")]
490         type_: Type,
491         bounds: Vec<GenericBound>,
492         /// Used for Higher-Rank Trait Bounds (HRTBs)
493         /// ```text
494         /// where for<'a> &'a T: Iterator,"
495         ///       ^^^^^^^
496         ///       |
497         ///       this part
498         /// ```
499         generic_params: Vec<GenericParamDef>,
500     },
501     RegionPredicate {
502         lifetime: String,
503         bounds: Vec<GenericBound>,
504     },
505     EqPredicate {
506         lhs: Type,
507         rhs: Term,
508     },
509 }
510
511 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
512 #[serde(rename_all = "snake_case")]
513 pub enum GenericBound {
514     TraitBound {
515         #[serde(rename = "trait")]
516         trait_: Path,
517         /// Used for Higher-Rank Trait Bounds (HRTBs)
518         /// ```text
519         /// where F: for<'a, 'b> Fn(&'a u8, &'b u8)
520         ///          ^^^^^^^^^^^
521         ///          |
522         ///          this part
523         /// ```
524         generic_params: Vec<GenericParamDef>,
525         modifier: TraitBoundModifier,
526     },
527     Outlives(String),
528 }
529
530 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
531 #[serde(rename_all = "snake_case")]
532 pub enum TraitBoundModifier {
533     None,
534     Maybe,
535     MaybeConst,
536 }
537
538 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
539 #[serde(rename_all = "snake_case")]
540 pub enum Term {
541     Type(Type),
542     Constant(Constant),
543 }
544
545 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
546 #[serde(rename_all = "snake_case")]
547 #[serde(tag = "kind", content = "inner")]
548 pub enum Type {
549     /// Structs, enums, and unions
550     ResolvedPath(Path),
551     DynTrait(DynTrait),
552     /// Parameterized types
553     Generic(String),
554     /// Built in numberic (i*, u*, f*) types, bool, and char
555     Primitive(String),
556     /// `extern "ABI" fn`
557     FunctionPointer(Box<FunctionPointer>),
558     /// `(String, u32, Box<usize>)`
559     Tuple(Vec<Type>),
560     /// `[u32]`
561     Slice(Box<Type>),
562     /// [u32; 15]
563     Array {
564         #[serde(rename = "type")]
565         type_: Box<Type>,
566         len: String,
567     },
568     /// `impl TraitA + TraitB + ...`
569     ImplTrait(Vec<GenericBound>),
570     /// `_`
571     Infer,
572     /// `*mut u32`, `*u8`, etc.
573     RawPointer {
574         mutable: bool,
575         #[serde(rename = "type")]
576         type_: Box<Type>,
577     },
578     /// `&'a mut String`, `&str`, etc.
579     BorrowedRef {
580         lifetime: Option<String>,
581         mutable: bool,
582         #[serde(rename = "type")]
583         type_: Box<Type>,
584     },
585     /// `<Type as Trait>::Name` or associated types like `T::Item` where `T: Iterator`
586     QualifiedPath {
587         name: String,
588         args: Box<GenericArgs>,
589         self_type: Box<Type>,
590         #[serde(rename = "trait")]
591         trait_: Path,
592     },
593 }
594
595 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
596 pub struct Path {
597     pub name: String,
598     pub id: Id,
599     /// Generic arguments to the type
600     /// ```test
601     /// std::borrow::Cow<'static, str>
602     ///                 ^^^^^^^^^^^^^^
603     ///                 |
604     ///                 this part
605     /// ```
606     pub args: Option<Box<GenericArgs>>,
607 }
608
609 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
610 pub struct FunctionPointer {
611     pub decl: FnDecl,
612     /// Used for Higher-Rank Trait Bounds (HRTBs)
613     /// ```text
614     /// for<'c> fn(val: &'c i32) -> i32
615     /// ^^^^^^^
616     ///       |
617     ///       this part
618     /// ```
619     pub generic_params: Vec<GenericParamDef>,
620     pub header: Header,
621 }
622
623 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
624 pub struct FnDecl {
625     /// List of argument names and their type.
626     ///
627     /// Note that not all names will be valid identifiers, as some of
628     /// them may be patterns.
629     pub inputs: Vec<(String, Type)>,
630     pub output: Option<Type>,
631     pub c_variadic: bool,
632 }
633
634 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
635 pub struct Trait {
636     pub is_auto: bool,
637     pub is_unsafe: bool,
638     pub items: Vec<Id>,
639     pub generics: Generics,
640     pub bounds: Vec<GenericBound>,
641     pub implementations: Vec<Id>,
642 }
643
644 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
645 pub struct TraitAlias {
646     pub generics: Generics,
647     pub params: Vec<GenericBound>,
648 }
649
650 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
651 pub struct Impl {
652     pub is_unsafe: bool,
653     pub generics: Generics,
654     pub provided_trait_methods: Vec<String>,
655     #[serde(rename = "trait")]
656     pub trait_: Option<Path>,
657     #[serde(rename = "for")]
658     pub for_: Type,
659     pub items: Vec<Id>,
660     pub negative: bool,
661     pub synthetic: bool,
662     pub blanket_impl: Option<Type>,
663 }
664
665 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
666 #[serde(rename_all = "snake_case")]
667 pub struct Import {
668     /// The full path being imported.
669     pub source: String,
670     /// May be different from the last segment of `source` when renaming imports:
671     /// `use source as name;`
672     pub name: String,
673     /// The ID of the item being imported. Will be `None` in case of re-exports of primitives:
674     /// ```rust
675     /// pub use i32 as my_i32;
676     /// ```
677     pub id: Option<Id>,
678     /// Whether this import uses a glob: `use source::*;`
679     pub glob: bool,
680 }
681
682 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
683 pub struct ProcMacro {
684     pub kind: MacroKind,
685     pub helpers: Vec<String>,
686 }
687
688 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
689 #[serde(rename_all = "snake_case")]
690 pub enum MacroKind {
691     /// A bang macro `foo!()`.
692     Bang,
693     /// An attribute macro `#[foo]`.
694     Attr,
695     /// A derive macro `#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]`
696     Derive,
697 }
698
699 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
700 pub struct Typedef {
701     #[serde(rename = "type")]
702     pub type_: Type,
703     pub generics: Generics,
704 }
705
706 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
707 pub struct OpaqueTy {
708     pub bounds: Vec<GenericBound>,
709     pub generics: Generics,
710 }
711
712 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
713 pub struct Static {
714     #[serde(rename = "type")]
715     pub type_: Type,
716     pub mutable: bool,
717     pub expr: String,
718 }
719
720 #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
721 pub struct Primitive {
722     pub name: String,
723     pub impls: Vec<Id>,
724 }
725
726 #[cfg(test)]
727 mod tests;