From 17d40c6057c88f4c432b0d7bac88e1b84cb7e67f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:03:36 +0200 Subject: Adding upstream version 1.65.0+dfsg1. Signed-off-by: Daniel Baumann --- src/rustdoc-json-types/lib.rs | 160 +++++++++++++++++++++++++++++++++------- src/rustdoc-json-types/tests.rs | 4 +- 2 files changed, 133 insertions(+), 31 deletions(-) (limited to 'src/rustdoc-json-types') diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 761e94c7e..fb1830426 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -9,7 +9,7 @@ use std::path::PathBuf; use serde::{Deserialize, Serialize}; /// rustdoc format-version. -pub const FORMAT_VERSION: u32 = 16; +pub const FORMAT_VERSION: u32 = 21; /// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information /// about the language items in the local crate, as well as info about external items to allow @@ -115,6 +115,35 @@ pub enum Visibility { }, } +#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] +pub struct DynTrait { + /// All the traits implemented. One of them is the vtable, and the rest must be auto traits. + pub traits: Vec, + /// The lifetime of the whole dyn object + /// ```text + /// dyn Debug + 'static + /// ^^^^^^^ + /// | + /// this part + /// ``` + pub lifetime: Option, +} + +#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] +/// A trait and potential HRTBs +pub struct PolyTrait { + #[serde(rename = "trait")] + pub trait_: Path, + /// Used for Higher-Rank Trait Bounds (HRTBs) + /// ```text + /// dyn for<'a> Fn() -> &'a i32" + /// ^^^^^^^ + /// | + /// this part + /// ``` + pub generic_params: Vec, +} + #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum GenericArgs { @@ -260,13 +289,39 @@ pub struct Union { #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct Struct { - pub struct_type: StructType, + pub kind: StructKind, pub generics: Generics, - pub fields_stripped: bool, - pub fields: Vec, pub impls: Vec, } +#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum StructKind { + /// A struct with no fields and no parentheses. + /// + /// ```rust + /// pub struct Unit; + /// ``` + Unit, + /// A struct with unnamed fields. + /// + /// ```rust + /// pub struct TupleStruct(i32); + /// pub struct EmptyTupleStruct(); + /// ``` + /// + /// All [`Id`]'s will point to [`ItemEnum::StructField`]. Private and + /// `#[doc(hidden)]` fields will be given as `None` + Tuple(Vec>), + /// A struct with nammed fields. + /// + /// ```rust + /// pub struct PlainStruct { x: i32 } + /// pub struct EmptyPlainStruct {} + /// ``` + Plain { fields: Vec, fields_stripped: bool }, +} + #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct Enum { pub generics: Generics, @@ -279,17 +334,53 @@ pub struct Enum { #[serde(rename_all = "snake_case")] #[serde(tag = "variant_kind", content = "variant_inner")] pub enum Variant { - Plain, - Tuple(Vec), - Struct(Vec), + /// A variant with no parentheses, and possible discriminant. + /// + /// ```rust + /// enum Demo { + /// PlainVariant, + /// PlainWithDiscriminant = 1, + /// } + /// ``` + Plain(Option), + /// A variant with unnamed fields. + /// + /// Unlike most of json, `#[doc(hidden)]` fields will be given as `None` + /// instead of being ommited, because order matters. + /// + /// ```rust + /// enum Demo { + /// TupleVariant(i32), + /// EmptyTupleVariant(), + /// } + /// ``` + Tuple(Vec>), + /// A variant with named fields. + /// + /// ```rust + /// enum Demo { + /// StructVariant { x: i32 }, + /// EmptyStructVariant {}, + /// } + /// ``` + Struct { fields: Vec, fields_stripped: bool }, } #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] -#[serde(rename_all = "snake_case")] -pub enum StructType { - Plain, - Tuple, - Unit, +pub struct Discriminant { + /// The expression that produced the discriminant. + /// + /// Unlike `value`, this preserves the original formatting (eg suffixes, + /// hexadecimal, and underscores), making it unsuitable to be machine + /// interpreted. + /// + /// In some cases, when the value is to complex, this may be `"{ _ }"`. + /// When this occurs is unstable, and may change without notice. + pub expr: String, + /// The numerical value of the discriminant. Stored as a string due to + /// JSON's poor support for large integers, and the fact that it would need + /// to store from [`i128::MIN`] to [`u128::MAX`]. + pub value: String, } #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] @@ -395,7 +486,7 @@ pub enum WherePredicate { type_: Type, bounds: Vec, /// Used for Higher-Rank Trait Bounds (HRTBs) - /// ```plain + /// ```text /// where for<'a> &'a T: Iterator," /// ^^^^^^^ /// | @@ -418,9 +509,9 @@ pub enum WherePredicate { pub enum GenericBound { TraitBound { #[serde(rename = "trait")] - trait_: Type, + trait_: Path, /// Used for Higher-Rank Trait Bounds (HRTBs) - /// ```plain + /// ```text /// where F: for<'a, 'b> Fn(&'a u8, &'b u8) /// ^^^^^^^^^^^ /// | @@ -451,16 +542,12 @@ pub enum Term { #[serde(rename_all = "snake_case")] #[serde(tag = "kind", content = "inner")] pub enum Type { - /// Structs, enums, and traits - ResolvedPath { - name: String, - id: Id, - args: Option>, - param_names: Vec, - }, + /// Structs, enums, and unions + ResolvedPath(Path), + DynTrait(DynTrait), /// Parameterized types Generic(String), - /// Fixed-size numeric types (plus int/usize/float), char, arrays, slices, and tuples + /// Built in numberic (i*, u*, f*) types, bool, and char Primitive(String), /// `extern "ABI" fn` FunctionPointer(Box), @@ -497,15 +584,29 @@ pub enum Type { args: Box, self_type: Box, #[serde(rename = "trait")] - trait_: Box, + trait_: Path, }, } +#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] +pub struct Path { + pub name: String, + pub id: Id, + /// Generic arguments to the type + /// ```test + /// std::borrow::Cow<'static, str> + /// ^^^^^^^^^^^^^^ + /// | + /// this part + /// ``` + pub args: Option>, +} + #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct FunctionPointer { pub decl: FnDecl, /// Used for Higher-Rank Trait Bounds (HRTBs) - /// ```plain + /// ```text /// for<'c> fn(val: &'c i32) -> i32 /// ^^^^^^^ /// | @@ -544,7 +645,7 @@ pub struct Impl { pub generics: Generics, pub provided_trait_methods: Vec, #[serde(rename = "trait")] - pub trait_: Option, + pub trait_: Option, #[serde(rename = "for")] pub for_: Type, pub items: Vec, @@ -561,8 +662,11 @@ pub struct Import { /// May be different from the last segment of `source` when renaming imports: /// `use source as name;` pub name: String, - /// The ID of the item being imported. - pub id: Option, // FIXME is this actually ever None? + /// The ID of the item being imported. Will be `None` in case of re-exports of primitives: + /// ```rust + /// pub use i32 as my_i32; + /// ``` + pub id: Option, /// Whether this import uses a glob: `use source::*;` pub glob: bool, } diff --git a/src/rustdoc-json-types/tests.rs b/src/rustdoc-json-types/tests.rs index e7f6447ed..399ff54b2 100644 --- a/src/rustdoc-json-types/tests.rs +++ b/src/rustdoc-json-types/tests.rs @@ -3,10 +3,8 @@ use super::*; #[test] fn test_struct_info_roundtrip() { let s = ItemEnum::Struct(Struct { - struct_type: StructType::Plain, generics: Generics { params: vec![], where_predicates: vec![] }, - fields_stripped: false, - fields: vec![], + kind: StructKind::Plain { fields: vec![], fields_stripped: false }, impls: vec![], }); -- cgit v1.2.3