diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 3ade40940bc97..cb972aaa7f912 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -14,7 +14,7 @@ use rustc_middle::{bug, ty}; use rustc_span::{Pos, Symbol, kw}; use rustdoc_json_types::*; -use crate::clean::{self, ItemId}; +use crate::clean; use crate::formats::FormatRenderer; use crate::formats::item_type::ItemType; use crate::json::JsonRenderer; @@ -107,7 +107,7 @@ impl JsonRenderer<'_> { } } - fn ids(&self, items: impl IntoIterator) -> Vec { + fn ids(&self, items: impl IntoIterator) -> Vec { items .into_iter() .filter(|x| !x.is_stripped() && !x.is_keyword()) @@ -118,7 +118,7 @@ impl JsonRenderer<'_> { fn ids_keeping_stripped( &self, items: impl IntoIterator, - ) -> Vec> { + ) -> Vec> { items .into_iter() .map(|i| (!i.is_stripped() && !i.is_keyword()).then(|| self.id_from_item(&i))) @@ -470,7 +470,7 @@ impl FromClean for WherePredicate { EqPredicate { lhs, rhs } => WherePredicate::EqPredicate { // The LHS currently has type `Type` but it should be a `QualifiedPath` since it may // refer to an associated const. However, `EqPredicate` shouldn't exist in the first - // place: . + // place: . lhs: lhs.into_json(renderer), rhs: rhs.into_json(renderer), }, @@ -522,6 +522,12 @@ pub(crate) fn from_trait_bound_modifier( } } +impl FromClean for TypeId { + fn from_clean(ty: clean::Type, renderer: &JsonRenderer<'_>) -> Self { + from_type(ty.into_json(renderer), renderer) + } +} + impl FromClean for Type { fn from_clean(ty: clean::Type, renderer: &JsonRenderer<'_>) -> Self { use clean::Type::{ @@ -539,26 +545,24 @@ impl FromClean for Type { // FIXME: add dedicated variant to json Type? SelfTy => Type::Generic("Self".to_owned()), Primitive(p) => Type::Primitive(p.as_sym().to_string()), - BareFunction(f) => Type::FunctionPointer(Box::new((*f).into_json(renderer))), + BareFunction(f) => Type::FunctionPointer((*f).into_json(renderer)), Tuple(t) => Type::Tuple(t.into_json(renderer)), - Slice(t) => Type::Slice(Box::new((*t).into_json(renderer))), - Array(t, s) => { - Type::Array { type_: Box::new((*t).into_json(renderer)), len: s.to_string() } - } + Slice(t) => Type::Slice((*t).into_json(renderer)), + Array(t, s) => Type::Array { type_: (*t).into_json(renderer), len: s.to_string() }, clean::Type::Pat(t, p) => Type::Pat { - type_: Box::new((*t).into_json(renderer)), + type_: (*t).into_json(renderer), __pat_unstable_do_not_use: p.to_string(), }, ImplTrait(g) => Type::ImplTrait(g.into_json(renderer)), Infer => Type::Infer, RawPointer(mutability, type_) => Type::RawPointer { is_mutable: mutability == ast::Mutability::Mut, - type_: Box::new((*type_).into_json(renderer)), + type_: (*type_).into_json(renderer), }, BorrowedRef { lifetime, mutability, type_ } => Type::BorrowedRef { lifetime: lifetime.map(convert_lifetime), is_mutable: mutability == ast::Mutability::Mut, - type_: Box::new((*type_).into_json(renderer)), + type_: (*type_).into_json(renderer), }, QPath(qpath) => (*qpath).into_json(renderer), // FIXME(unsafe_binder): Implement rustdoc-json. @@ -567,24 +571,34 @@ impl FromClean for Type { } } +fn from_type(ty: Type, renderer: &JsonRenderer<'_>) -> TypeId { + renderer.types.borrow_mut().insert_full(ty).0 +} + impl FromClean for Path { fn from_clean(path: clean::Path, renderer: &JsonRenderer<'_>) -> Path { Path { path: path.whole_name(), id: renderer.id_from_item_default(path.def_id().into()), - args: path.segments.last().map(|args| Box::new(args.clone().args.into_json(renderer))), + args: path.segments.into_iter().next_back().map(|args| args.args.into_json(renderer)), } } } +impl FromClean for TypeId { + fn from_clean(qpath: clean::QPathData, renderer: &JsonRenderer<'_>) -> Self { + from_type(qpath.into_json(renderer), renderer) + } +} + impl FromClean for Type { fn from_clean(qpath: clean::QPathData, renderer: &JsonRenderer<'_>) -> Self { let clean::QPathData { assoc, self_type, should_fully_qualify: _, trait_ } = qpath; Self::QualifiedPath { name: assoc.name.to_string(), - args: Box::new(assoc.args.into_json(renderer)), - self_type: Box::new(self_type.into_json(renderer)), + args: assoc.args.into_json(renderer), + self_type: self_type.into_json(renderer), trait_: trait_.map(|trait_| trait_.into_json(renderer)), } } @@ -768,7 +782,11 @@ impl FromClean for Use { Use { source: import.source.path.whole_name(), name, - id: import.source.did.map(ItemId::from).map(|i| renderer.id_from_item_default(i)), + id: import + .source + .did + .map(clean::ItemId::from) + .map(|i| renderer.id_from_item_default(i)), is_glob, } } diff --git a/src/librustdoc/json/ids.rs b/src/librustdoc/json/ids.rs index 737148bad4e88..44ba77dd38636 100644 --- a/src/librustdoc/json/ids.rs +++ b/src/librustdoc/json/ids.rs @@ -1,6 +1,6 @@ //! Id handling for rustdoc-json. //! -//! Manages the creation of [`rustdoc_json_types::Id`] and the +//! Manages the creation of [`rustdoc_json_types::ItemId`] and the //! fact that these don't correspond exactly to [`DefId`], because //! [`rustdoc_json_types::Item`] doesn't correspond exactly to what //! other phases think of as an "item". @@ -14,14 +14,14 @@ use rustdoc_json_types as types; use super::JsonRenderer; use crate::clean; -pub(super) type IdInterner = FxHashMap; +pub(super) type IdInterner = FxHashMap; #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] /// An uninterned id. /// /// Each one corresponds to exactly one of both: /// 1. [`rustdoc_json_types::Item`]. -/// 2. [`rustdoc_json_types::Id`] transitively (as each `Item` has an `Id`). +/// 2. [`rustdoc_json_types::ItemId`] transitively (as each `Item` has an `Id`). /// /// It's *broadly* equivalent to a [`DefId`], but needs slightly more information /// to fully disambiguate items, because sometimes we choose to split a single HIR @@ -66,7 +66,7 @@ pub(super) struct FullItemId { } impl JsonRenderer<'_> { - pub(crate) fn id_from_item_default(&self, item_id: clean::ItemId) -> types::Id { + pub(crate) fn id_from_item_default(&self, item_id: clean::ItemId) -> types::ItemId { self.id_from_item_inner(item_id, None, None) } @@ -75,7 +75,7 @@ impl JsonRenderer<'_> { item_id: clean::ItemId, name: Option, imported_id: Option, - ) -> types::Id { + ) -> types::ItemId { let (def_id, extra_id) = match item_id { clean::ItemId::DefId(did) => (did, imported_id), clean::ItemId::Blanket { for_, impl_id } => (for_, Some(impl_id)), @@ -107,10 +107,10 @@ impl JsonRenderer<'_> { let len = interner.len(); *interner .entry(key) - .or_insert_with(|| types::Id(len.try_into().expect("too many items in a crate"))) + .or_insert_with(|| types::ItemId(len.try_into().expect("too many items in a crate"))) } - pub(crate) fn id_from_item(&self, item: &clean::Item) -> types::Id { + pub(crate) fn id_from_item(&self, item: &clean::Item) -> types::ItemId { match item.kind { clean::ItemKind::ImportItem(ref import) => { let imported_id = import.source.did; diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index 131a12ce228f7..24f119c21ac70 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -14,7 +14,7 @@ use std::io::{BufWriter, Write, stdout}; use std::path::PathBuf; use std::rc::Rc; -use rustc_data_structures::fx::FxHashSet; +use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_hir::def_id::{DefId, DefIdSet}; use rustc_middle::ty::TyCtxt; use rustc_session::Session; @@ -41,7 +41,8 @@ pub(crate) struct JsonRenderer<'tcx> { tcx: TyCtxt<'tcx>, /// A mapping of IDs that contains all local items for this crate which gets output as a top /// level field of the JSON blob. - index: Rc>>, + index: RefCell>, + types: RefCell>, /// The directory where the JSON blob should be written to. /// /// If this is `None`, the blob will be printed to `stdout` instead. @@ -56,7 +57,7 @@ impl<'tcx> JsonRenderer<'tcx> { self.tcx.sess } - fn get_trait_implementors(&mut self, id: DefId) -> Vec { + fn get_trait_implementors(&mut self, id: DefId) -> Vec { Rc::clone(&self.cache) .implementors .get(&id) @@ -73,7 +74,7 @@ impl<'tcx> JsonRenderer<'tcx> { .unwrap_or_default() } - fn get_impls(&mut self, id: DefId) -> Vec { + fn get_impls(&mut self, id: DefId) -> Vec { Rc::clone(&self.cache) .impls .get(&id) @@ -134,7 +135,7 @@ fn target(sess: &rustc_session::Session) -> types::Target { let feature_stability: FxHashMap<&str, Stability> = sess .target .rust_target_features() - .into_iter() + .iter() .copied() .map(|(name, stability, _)| (name, stability)) .collect(); @@ -144,7 +145,7 @@ fn target(sess: &rustc_session::Session) -> types::Target { target_features: sess .target .rust_target_features() - .into_iter() + .iter() .copied() .filter(|(_, stability, _)| { // Describe only target features which the user can toggle @@ -158,7 +159,7 @@ fn target(sess: &rustc_session::Session) -> types::Target { _ => None, }, implies_features: implied_features - .into_iter() + .iter() .copied() .filter(|name| { // Imply only target features which the user can toggle @@ -197,7 +198,8 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { Ok(( JsonRenderer { tcx, - index: Rc::new(RefCell::new(FxHashMap::default())), + index: RefCell::new(FxHashMap::default()), + types: RefCell::new(FxIndexSet::default()), out_dir: if options.output_to_stdout { None } else { Some(options.output) }, cache: Rc::new(cache), imported_items, @@ -299,7 +301,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { debug!("Done with crate"); let e = ExternalCrate { crate_num: LOCAL_CRATE }; - let index = (*self.index).clone().into_inner(); + let index = self.index.clone().into_inner(); // Note that tcx.rust_target_features is inappropriate here because rustdoc tries to run for // multiple targets: https://github.com/rust-lang/rust/pull/137632 @@ -313,6 +315,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { crate_version: self.cache.crate_version.clone(), includes_private: self.cache.document_private, index, + types: self.types.borrow().iter().cloned().collect(), paths: self .cache .paths diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 8a3ab6f864072..9b6399a8f40d6 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -30,7 +30,7 @@ pub type FxHashMap = HashMap; // re-export for use in src/librustdoc /// This integer is incremented with every breaking change to the API, /// and is returned along with the JSON blob as [`Crate::format_version`]. /// Consuming code should assert that this value matches the format version(s) that it supports. -pub const FORMAT_VERSION: u32 = 46; +pub const FORMAT_VERSION: u32 = 47; /// The root of the emitted JSON blob. /// @@ -40,16 +40,18 @@ pub const FORMAT_VERSION: u32 = 46; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Crate { /// The id of the root [`Module`] item of the local crate. - pub root: Id, + pub root: ItemId, /// The version string given to `--crate-version`, if any. pub crate_version: Option, /// Whether or not the output includes private items. pub includes_private: bool, /// A collection of all items in the local crate as well as some external traits and their /// items that are referenced locally. - pub index: HashMap, + pub index: HashMap, /// Maps IDs to fully qualified paths and other info helpful for generating links. - pub paths: HashMap, + pub paths: HashMap, + /// A collection of all types of the local crate. Can be indexed with [`TypeId`]. + pub types: Vec, /// Maps `crate_id` of items to a crate name and html_root_url if it exists. pub external_crates: HashMap, /// Information about the target for which this documentation was generated @@ -159,7 +161,7 @@ pub struct ItemSummary { #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Item { /// The unique identifier of this item. Can be used to find this item in various mappings. - pub id: Id, + pub id: ItemId, /// This can be used as a key to the `external_crates` map of [`Crate`] to see which crate /// this item came from. pub crate_id: u32, @@ -175,7 +177,7 @@ pub struct Item { /// Some("") if there is some documentation but it is empty (EG `#[doc = ""]`). pub docs: Option, /// 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 - pub links: HashMap, + pub links: HashMap, /// Attributes on this item. /// /// Does not include `#[deprecated]` attributes: see the [`Self::deprecation`] field instead. @@ -228,7 +230,7 @@ pub enum Visibility { /// For `pub(in path)` visibility. Restricted { /// ID of the module to which this visibility restricts items. - parent: Id, + parent: ItemId, /// The path with which [`parent`] was referenced /// (like `super::super` or `crate::foo::bar`). /// @@ -289,9 +291,9 @@ pub enum GenericArgs { /// `Fn(A, B) -> C` Parenthesized { /// The input types, enclosed in parentheses. - inputs: Vec, + inputs: Vec, /// The output type provided after the `->`, if present. - output: Option, + output: Option, }, /// `T::method(..)` ReturnTypeNotation, @@ -314,7 +316,7 @@ pub enum GenericArg { /// std::borrow::Cow<'static, str> /// ^^^ /// ``` - Type(Type), + Type(TypeId), /// A constant as a generic argument. /// ```text /// core::array::IntoIter @@ -390,7 +392,12 @@ pub enum AssocItemConstraintKind { /// to parse them, or otherwise depend on any implementation details. #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] // FIXME(aDotInTheVoid): Consider making this non-public in rustdoc-types. -pub struct Id(pub u32); +pub struct ItemId(pub u32); + +/// A type identifier. +/// +/// It can be used to lookup in [`Crate::types`] to resolve it to [`Type`]. +pub type TypeId = usize; /// The fundamental kind of an item. Unlike [`ItemEnum`], this does not carry any additional info. /// @@ -485,7 +492,7 @@ pub enum ItemEnum { /// A `struct` declaration. Struct(Struct), /// A field of a struct. - StructField(Type), + StructField(TypeId), /// An `enum` declaration. Enum(Enum), /// A variant of a enum. @@ -509,7 +516,7 @@ pub enum ItemEnum { Constant { /// The type of the constant. #[serde(rename = "type")] - type_: Type, + type_: TypeId, /// The declared constant itself. #[serde(rename = "const")] const_: Constant, @@ -538,7 +545,7 @@ pub enum ItemEnum { AssocConst { /// The type of the constant. #[serde(rename = "type")] - type_: Type, + type_: TypeId, /// Inside a trait declaration, this is the default value for the associated constant, /// if provided. /// Inside an `impl` block, this is the value assigned to the associated constant, @@ -575,7 +582,7 @@ pub enum ItemEnum { /// // ^^^^^ /// ``` #[serde(rename = "type")] - type_: Option, + type_: Option, }, } @@ -588,7 +595,7 @@ pub struct Module { /// compiler. pub is_crate: bool, /// [`Item`]s declared inside this module. - pub items: Vec, + pub items: Vec, /// If `true`, this module is not part of the public API, but it contains /// items that are re-exported as public API. pub is_stripped: bool, @@ -604,11 +611,11 @@ pub struct Union { /// The list of fields in the union. /// /// All of the corresponding [`Item`]s are of kind [`ItemEnum::StructField`]. - pub fields: Vec, + pub fields: Vec, /// All impls (both of traits and inherent) for this union. /// /// All of the corresponding [`Item`]s are of kind [`ItemEnum::Impl`]. - pub impls: Vec, + pub impls: Vec, } /// A `struct`. @@ -621,7 +628,7 @@ pub struct Struct { pub generics: Generics, /// All impls (both of traits and inherent) for this struct. /// All of the corresponding [`Item`]s are of kind [`ItemEnum::Impl`]. - pub impls: Vec, + pub impls: Vec, } /// The kind of a [`Struct`] and the data specific to it, i.e. fields. @@ -636,7 +643,7 @@ pub enum StructKind { Unit, /// A struct with unnamed fields. /// - /// All [`Id`]'s will point to [`ItemEnum::StructField`]. + /// All [`ItemId`]'s will point to [`ItemEnum::StructField`]. /// Unlike most of JSON, private and `#[doc(hidden)]` fields will be given as `None` /// instead of being omitted, because order matters. /// @@ -644,7 +651,7 @@ pub enum StructKind { /// pub struct TupleStruct(i32); /// pub struct EmptyTupleStruct(); /// ``` - Tuple(Vec>), + Tuple(Vec>), /// A struct with named fields. /// /// ```rust @@ -655,7 +662,7 @@ pub enum StructKind { /// The list of fields in the struct. /// /// All of the corresponding [`Item`]s are of kind [`ItemEnum::StructField`]. - fields: Vec, + fields: Vec, /// Whether any fields have been removed from the result, due to being private or hidden. has_stripped_fields: bool, }, @@ -671,9 +678,9 @@ pub struct Enum { /// The list of variants in the enum. /// /// All of the corresponding [`Item`]s are of kind [`ItemEnum::Variant`] - pub variants: Vec, + pub variants: Vec, /// `impl`s for the enum. - pub impls: Vec, + pub impls: Vec, } /// A variant of an enum. @@ -700,7 +707,7 @@ pub enum VariantKind { Plain, /// A variant with unnamed fields. /// - /// All [`Id`]'s will point to [`ItemEnum::StructField`]. + /// All [`ItemId`]'s will point to [`ItemEnum::StructField`]. /// Unlike most of JSON, `#[doc(hidden)]` fields will be given as `None` /// instead of being omitted, because order matters. /// @@ -710,7 +717,7 @@ pub enum VariantKind { /// EmptyTupleVariant(), /// } /// ``` - Tuple(Vec>), + Tuple(Vec>), /// A variant with named fields. /// /// ```rust @@ -722,7 +729,7 @@ pub enum VariantKind { Struct { /// The list of variants in the enum. /// All of the corresponding [`Item`]s are of kind [`ItemEnum::Variant`]. - fields: Vec, + fields: Vec, /// Whether any variants have been removed from the result, due to being private or hidden. has_stripped_fields: bool, }, @@ -860,7 +867,7 @@ pub enum GenericParamDefKind { /// trait PartialEq {} /// // ^^^^ /// ``` - default: Option, + default: Option, /// This is normally `false`, which means that this generic parameter is /// declared in the Rust source text. /// @@ -891,7 +898,7 @@ pub enum GenericParamDefKind { Const { /// The type of the constant as declared. #[serde(rename = "type")] - type_: Type, + type_: TypeId, /// The stringified expression for the default value, if provided. It's not guaranteed that /// it'll match the actual source code for the default value. default: Option, @@ -915,7 +922,7 @@ pub enum WherePredicate { /// // ^ /// ``` #[serde(rename = "type")] - type_: Type, + type_: TypeId, /// The set of bounds that constrain the type. /// /// ```rust @@ -942,7 +949,7 @@ pub enum WherePredicate { /// A type must exactly equal another type. EqPredicate { /// The left side of the equation. - lhs: Type, + lhs: TypeId, /// The right side of the equation. rhs: Term, }, @@ -1020,7 +1027,7 @@ pub enum Term { /// fn f(x: impl IntoIterator) {} /// // ^^^ /// ``` - Type(Type), + Type(TypeId), /// A constant. /// /// ```ignore (incomplete feature in the snippet) @@ -1047,16 +1054,16 @@ pub enum Type { /// Built-in numeric types (e.g. `u32`, `f32`), `bool`, `char`. Primitive(String), /// A function pointer type, e.g. `fn(u32) -> u32`, `extern "C" fn() -> *const u8` - FunctionPointer(Box), + FunctionPointer(FunctionPointer), /// A tuple type, e.g. `(String, u32, Box)` - Tuple(Vec), + Tuple(Vec), /// An unsized slice type, e.g. `[u32]`. - Slice(Box), + Slice(TypeId), /// An array type, e.g. `[u32; 15]` Array { /// The type of the contained element. #[serde(rename = "type")] - type_: Box, + type_: TypeId, /// The stringified expression that is the length of the array. /// /// Keep in mind that it's not guaranteed to match the actual source code of the expression. @@ -1068,7 +1075,7 @@ pub enum Type { Pat { /// The base type, e.g. the `u32` in `u32 is 1..` #[serde(rename = "type")] - type_: Box, + type_: TypeId, #[doc(hidden)] __pat_unstable_do_not_use: String, }, @@ -1082,7 +1089,7 @@ pub enum Type { is_mutable: bool, /// The type of the pointee. #[serde(rename = "type")] - type_: Box, + type_: TypeId, }, /// `&'a mut String`, `&str`, etc. BorrowedRef { @@ -1092,7 +1099,7 @@ pub enum Type { is_mutable: bool, /// The type of the pointee, e.g. the `i32` in `&'a mut i32` #[serde(rename = "type")] - type_: Box, + type_: TypeId, }, /// Associated types like `::Name` and `T::Item` where /// `T: Iterator` or inherent associated types like `Struct::Name`. @@ -1110,14 +1117,14 @@ pub enum Type { /// as BetterIterator>::Item<'static> /// // ^^^^^^^^^ /// ``` - args: Box, + args: GenericArgs, /// The type with which this type is associated. /// /// ```ignore (incomplete expression) /// as Iterator>::Item /// // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ /// ``` - self_type: Box, + self_type: TypeId, /// `None` iff this is an *inherent* associated type. #[serde(rename = "trait")] trait_: Option, @@ -1142,14 +1149,14 @@ pub struct Path { // Example tested in ./tests/rustdoc-json/path_name.rs pub path: String, /// The ID of the type. - pub id: Id, + pub id: ItemId, /// Generic arguments to the type. /// /// ```ignore (incomplete expression) /// std::borrow::Cow<'static, str> /// // ^^^^^^^^^^^^^^ /// ``` - pub args: Option>, + pub args: Option, } /// A type that is a function pointer. @@ -1175,9 +1182,9 @@ pub struct FunctionSignature { /// /// Note that not all names will be valid identifiers, as some of /// them may be patterns. - pub inputs: Vec<(String, Type)>, + pub inputs: Vec<(String, TypeId)>, /// The output type, if specified. - pub output: Option, + pub output: Option, /// Whether the function accepts an arbitrary amount of trailing arguments the C way. /// /// ```ignore (incomplete code) @@ -1199,13 +1206,13 @@ pub struct Trait { /// [^1]: Formerly known as "object safe". pub is_dyn_compatible: bool, /// Associated [`Item`]s that can/must be implemented by the `impl` blocks. - pub items: Vec, + pub items: Vec, /// Information about the type parameters and `where` clauses of the trait. pub generics: Generics, /// Constraints that must be met by the implementor of the trait. pub bounds: Vec, /// The implementations of the trait. - pub implementations: Vec, + pub implementations: Vec, } /// A trait alias declaration, e.g. `trait Int = Add + Sub + Mul + Div;` @@ -1245,16 +1252,16 @@ pub struct Impl { pub trait_: Option, /// The type that the impl block is for. #[serde(rename = "for")] - pub for_: Type, + pub for_: TypeId, /// The list of associated items contained in this impl block. - pub items: Vec, + pub items: Vec, /// Whether this is a negative impl (e.g. `!Sized` or `!Send`). pub is_negative: bool, /// Whether this is an impl that’s implied by the compiler /// (for autotraits, e.g. `Send` or `Sync`). pub is_synthetic: bool, // FIXME: document this - pub blanket_impl: Option, + pub blanket_impl: Option, } /// A `use` statement. @@ -1270,7 +1277,7 @@ pub struct Use { /// ```rust /// pub use i32 as my_i32; /// ``` - pub id: Option, + pub id: Option, /// Whether this statement is a wildcard `use`, e.g. `use source::*;` pub is_glob: bool, } @@ -1315,7 +1322,7 @@ pub enum MacroKind { pub struct TypeAlias { /// The type referred to by this alias. #[serde(rename = "type")] - pub type_: Type, + pub type_: TypeId, /// Information about the type parameters and `where` clauses of the alias. pub generics: Generics, } @@ -1325,7 +1332,7 @@ pub struct TypeAlias { pub struct Static { /// The type of the static. #[serde(rename = "type")] - pub type_: Type, + pub type_: TypeId, /// This is `true` for mutable statics, declared as `static mut X: T = f();` pub is_mutable: bool, /// The stringified expression for the initial value. @@ -1356,7 +1363,7 @@ pub struct Primitive { /// The name of the type. pub name: String, /// The implementations, inherent and of traits, on the primitive type. - pub impls: Vec, + pub impls: Vec, } #[cfg(test)] diff --git a/src/tools/jsondocck/src/cache.rs b/src/tools/jsondocck/src/cache.rs index 1369c8ded0070..f7b9a6171cdcf 100644 --- a/src/tools/jsondocck/src/cache.rs +++ b/src/tools/jsondocck/src/cache.rs @@ -19,7 +19,7 @@ impl Cache { // `filename` needs to replace `-` with `_` to be sure the JSON path will always be valid. let filename = Path::new(&config.template).file_stem().unwrap().to_str().unwrap().replace('-', "_"); - let file_path = root.join(&Path::with_extension(Path::new(&filename), "json")); + let file_path = root.join(Path::with_extension(Path::new(&filename), "json")); let content = fs::read_to_string(&file_path).expect("failed to read JSON file"); Cache { diff --git a/src/tools/jsondoclint/src/main.rs b/src/tools/jsondoclint/src/main.rs index 5cbf346086062..5dcd5ef45fbbf 100644 --- a/src/tools/jsondoclint/src/main.rs +++ b/src/tools/jsondoclint/src/main.rs @@ -4,7 +4,7 @@ use std::path::{Path, PathBuf}; use anyhow::{Result, bail}; use clap::Parser; use fs_err as fs; -use rustdoc_json_types::{Crate, FORMAT_VERSION, Id}; +use rustdoc_json_types::{Crate, FORMAT_VERSION, ItemId}; use serde::Serialize; use serde_json::Value; @@ -15,7 +15,7 @@ mod validator; #[derive(Debug, PartialEq, Eq, Serialize, Clone)] struct Error { kind: ErrorKind, - id: Id, + id: ItemId, } #[derive(Debug, PartialEq, Eq, Serialize, Clone)] @@ -81,7 +81,7 @@ fn main() -> Result<()> { [sel] => eprintln!( "{} not in index or paths, but referred to at '{}'", err.id.0, - json_find::to_jsonpath(&sel) + json_find::to_jsonpath(sel) ), [sel, ..] => { if verbose { @@ -99,7 +99,7 @@ fn main() -> Result<()> { eprintln!( "{} not in index or paths, but referred to at '{}' and {} more", err.id.0, - json_find::to_jsonpath(&sel), + json_find::to_jsonpath(sel), sels.len() - 1, ) } diff --git a/src/tools/jsondoclint/src/validator.rs b/src/tools/jsondoclint/src/validator.rs index 8c9e4c8bb3a60..8e89b68dee2ac 100644 --- a/src/tools/jsondoclint/src/validator.rs +++ b/src/tools/jsondoclint/src/validator.rs @@ -4,9 +4,9 @@ use std::hash::Hash; use rustdoc_json_types::{ AssocItemConstraint, AssocItemConstraintKind, Constant, Crate, DynTrait, Enum, Function, FunctionPointer, FunctionSignature, GenericArg, GenericArgs, GenericBound, GenericParamDef, - Generics, Id, Impl, ItemEnum, ItemSummary, Module, Path, Primitive, ProcMacro, Static, Struct, - StructKind, Term, Trait, TraitAlias, Type, TypeAlias, Union, Use, Variant, VariantKind, - WherePredicate, + Generics, Impl, ItemEnum, ItemId, ItemSummary, Module, Path, Primitive, ProcMacro, Static, + Struct, StructKind, Term, Trait, TraitAlias, Type, TypeAlias, TypeId, Union, Use, Variant, + VariantKind, WherePredicate, }; use serde_json::Value; @@ -30,11 +30,11 @@ pub struct Validator<'a> { krate: &'a Crate, krate_json: Value, /// Worklist of Ids to check. - todo: HashSet<&'a Id>, + todo: HashSet<&'a ItemId>, /// Ids that have already been visited, so don't need to be checked again. - seen_ids: HashSet<&'a Id>, + seen_ids: HashSet<&'a ItemId>, /// Ids that have already been reported missing. - missing_ids: HashSet<&'a Id>, + missing_ids: HashSet<&'a ItemId>, } enum PathKind { @@ -73,7 +73,7 @@ impl<'a> Validator<'a> { } } - fn check_items(&mut self, id: &Id, items: &[Id]) { + fn check_items(&mut self, id: &ItemId, items: &[ItemId]) { let mut visited_ids = HashSet::with_capacity(items.len()); for item in items { @@ -86,7 +86,7 @@ impl<'a> Validator<'a> { } } - fn check_item(&mut self, id: &'a Id) { + fn check_item(&mut self, id: &'a ItemId) { if let Some(item) = &self.krate.index.get(id) { item.links.values().for_each(|id| self.add_any_id(id)); @@ -94,7 +94,7 @@ impl<'a> Validator<'a> { ItemEnum::Use(x) => self.check_use(x), ItemEnum::Union(x) => self.check_union(x), ItemEnum::Struct(x) => self.check_struct(x), - ItemEnum::StructField(x) => self.check_struct_field(x), + ItemEnum::StructField(x) => self.check_struct_field(*x), ItemEnum::Enum(x) => self.check_enum(x), ItemEnum::Variant(x) => self.check_variant(x, id), ItemEnum::Function(x) => self.check_function(x), @@ -103,7 +103,7 @@ impl<'a> Validator<'a> { ItemEnum::Impl(x) => self.check_impl(x, id), ItemEnum::TypeAlias(x) => self.check_type_alias(x), ItemEnum::Constant { type_, const_ } => { - self.check_type(type_); + self.check_type(*type_); self.check_constant(const_); } ItemEnum::Static(x) => self.check_static(x), @@ -114,12 +114,12 @@ impl<'a> Validator<'a> { ItemEnum::Module(x) => self.check_module(x, id), // FIXME: Why don't these have their own structs? ItemEnum::ExternCrate { .. } => {} - ItemEnum::AssocConst { type_, value: _ } => self.check_type(type_), + ItemEnum::AssocConst { type_, value: _ } => self.check_type(*type_), ItemEnum::AssocType { generics, bounds, type_ } => { self.check_generics(generics); bounds.iter().for_each(|b| self.check_generic_bound(b)); if let Some(ty) = type_ { - self.check_type(ty); + self.check_type(*ty); } } } @@ -129,7 +129,7 @@ impl<'a> Validator<'a> { } // Core checkers - fn check_module(&mut self, module: &'a Module, id: &Id) { + fn check_module(&mut self, module: &'a Module, id: &ItemId) { self.check_items(id, &module.items); module.items.iter().for_each(|i| self.add_mod_item_id(i)); } @@ -160,7 +160,7 @@ impl<'a> Validator<'a> { x.impls.iter().for_each(|i| self.add_impl_id(i)); } - fn check_struct_field(&mut self, x: &'a Type) { + fn check_struct_field(&mut self, x: TypeId) { self.check_type(x); } @@ -170,7 +170,7 @@ impl<'a> Validator<'a> { x.impls.iter().for_each(|i| self.add_impl_id(i)); } - fn check_variant(&mut self, x: &'a Variant, id: &'a Id) { + fn check_variant(&mut self, x: &'a Variant, id: &'a ItemId) { let Variant { kind, discriminant } = x; if let Some(discr) = discriminant { @@ -199,7 +199,7 @@ impl<'a> Validator<'a> { self.check_function_signature(&x.sig); } - fn check_trait(&mut self, x: &'a Trait, id: &Id) { + fn check_trait(&mut self, x: &'a Trait, id: &ItemId) { self.check_items(id, &x.items); self.check_generics(&x.generics); x.items.iter().for_each(|i| self.add_trait_item_id(i)); @@ -212,22 +212,22 @@ impl<'a> Validator<'a> { x.params.iter().for_each(|i| self.check_generic_bound(i)); } - fn check_impl(&mut self, x: &'a Impl, id: &Id) { + fn check_impl(&mut self, x: &'a Impl, id: &ItemId) { self.check_items(id, &x.items); self.check_generics(&x.generics); if let Some(path) = &x.trait_ { self.check_path(path, PathKind::Trait); } - self.check_type(&x.for_); + self.check_type(x.for_); x.items.iter().for_each(|i| self.add_trait_item_id(i)); - if let Some(blanket_impl) = &x.blanket_impl { + if let Some(blanket_impl) = x.blanket_impl { self.check_type(blanket_impl) } } fn check_type_alias(&mut self, x: &'a TypeAlias) { self.check_generics(&x.generics); - self.check_type(&x.type_); + self.check_type(x.type_); } fn check_constant(&mut self, _x: &'a Constant) { @@ -235,7 +235,7 @@ impl<'a> Validator<'a> { } fn check_static(&mut self, x: &'a Static) { - self.check_type(&x.type_); + self.check_type(x.type_); } fn check_macro(&mut self, _: &'a str) { @@ -255,24 +255,24 @@ impl<'a> Validator<'a> { x.where_predicates.iter().for_each(|w| self.check_where_predicate(w)); } - fn check_type(&mut self, x: &'a Type) { - match x { + fn check_type(&mut self, x: TypeId) { + match &self.krate.types[x] { Type::ResolvedPath(path) => self.check_path(path, PathKind::Type), Type::DynTrait(dyn_trait) => self.check_dyn_trait(dyn_trait), Type::Generic(_) => {} Type::Primitive(_) => {} - Type::Pat { type_, __pat_unstable_do_not_use: _ } => self.check_type(type_), - Type::FunctionPointer(fp) => self.check_function_pointer(&**fp), - Type::Tuple(tys) => tys.iter().for_each(|ty| self.check_type(ty)), - Type::Slice(inner) => self.check_type(&**inner), - Type::Array { type_, len: _ } => self.check_type(&**type_), + Type::Pat { type_, __pat_unstable_do_not_use: _ } => self.check_type(*type_), + Type::FunctionPointer(fp) => self.check_function_pointer(fp), + Type::Tuple(tys) => tys.iter().for_each(|ty| self.check_type(*ty)), + Type::Slice(inner) => self.check_type(*inner), + Type::Array { type_, len: _ } => self.check_type(*type_), Type::ImplTrait(bounds) => bounds.iter().for_each(|b| self.check_generic_bound(b)), Type::Infer => {} - Type::RawPointer { is_mutable: _, type_ } => self.check_type(&**type_), - Type::BorrowedRef { lifetime: _, is_mutable: _, type_ } => self.check_type(&**type_), + Type::RawPointer { is_mutable: _, type_ } => self.check_type(*type_), + Type::BorrowedRef { lifetime: _, is_mutable: _, type_ } => self.check_type(*type_), Type::QualifiedPath { name: _, args, self_type, trait_ } => { - self.check_generic_args(&**args); - self.check_type(&**self_type); + self.check_generic_args(args); + self.check_type(*self_type); if let Some(trait_) = trait_ { self.check_path(trait_, PathKind::Trait); } @@ -281,8 +281,8 @@ impl<'a> Validator<'a> { } fn check_function_signature(&mut self, x: &'a FunctionSignature) { - x.inputs.iter().for_each(|(_name, ty)| self.check_type(ty)); - if let Some(output) = &x.output { + x.inputs.iter().for_each(|(_name, ty)| self.check_type(*ty)); + if let Some(output) = x.output { self.check_type(output); } } @@ -310,7 +310,7 @@ impl<'a> Validator<'a> { } if let Some(args) = &x.args { - self.check_generic_args(&**args); + self.check_generic_args(args); } } @@ -321,9 +321,9 @@ impl<'a> Validator<'a> { constraints.iter().for_each(|bind| self.check_assoc_item_constraint(bind)); } GenericArgs::Parenthesized { inputs, output } => { - inputs.iter().for_each(|ty| self.check_type(ty)); + inputs.iter().for_each(|ty| self.check_type(*ty)); if let Some(o) = output { - self.check_type(o); + self.check_type(*o); } } GenericArgs::ReturnTypeNotation => {} @@ -336,11 +336,11 @@ impl<'a> Validator<'a> { rustdoc_json_types::GenericParamDefKind::Type { bounds, default, is_synthetic: _ } => { bounds.iter().for_each(|b| self.check_generic_bound(b)); if let Some(ty) = default { - self.check_type(ty); + self.check_type(*ty); } } rustdoc_json_types::GenericParamDefKind::Const { type_, default: _ } => { - self.check_type(type_) + self.check_type(*type_) } } } @@ -348,7 +348,7 @@ impl<'a> Validator<'a> { fn check_generic_arg(&mut self, arg: &'a GenericArg) { match arg { GenericArg::Lifetime(_) => {} - GenericArg::Type(ty) => self.check_type(ty), + GenericArg::Type(ty) => self.check_type(*ty), GenericArg::Const(c) => self.check_constant(c), GenericArg::Infer => {} } @@ -366,7 +366,7 @@ impl<'a> Validator<'a> { fn check_term(&mut self, term: &'a Term) { match term { - Term::Type(ty) => self.check_type(ty), + Term::Type(ty) => self.check_type(*ty), Term::Constant(con) => self.check_constant(con), } } @@ -374,7 +374,7 @@ impl<'a> Validator<'a> { fn check_where_predicate(&mut self, w: &'a WherePredicate) { match w { WherePredicate::BoundPredicate { type_, bounds, generic_params } => { - self.check_type(type_); + self.check_type(*type_); bounds.iter().for_each(|b| self.check_generic_bound(b)); generic_params.iter().for_each(|gpd| self.check_generic_param_def(gpd)); } @@ -382,7 +382,7 @@ impl<'a> Validator<'a> { // nop, all strings. } WherePredicate::EqPredicate { lhs, rhs } => { - self.check_type(lhs); + self.check_type(*lhs); self.check_term(rhs); } } @@ -400,7 +400,7 @@ impl<'a> Validator<'a> { fp.generic_params.iter().for_each(|gpd| self.check_generic_param_def(gpd)); } - fn check_item_info(&mut self, id: &Id, item_info: &ItemSummary) { + fn check_item_info(&mut self, id: &ItemId, item_info: &ItemSummary) { // FIXME: Their should be a better way to determine if an item is local, rather than relying on `LOCAL_CRATE_ID`, // which encodes rustc implementation details. if item_info.crate_id == LOCAL_CRATE_ID && !self.krate.index.contains_key(id) { @@ -413,7 +413,7 @@ impl<'a> Validator<'a> { } } - fn add_id_checked(&mut self, id: &'a Id, valid: fn(Kind) -> bool, expected: &str) { + fn add_id_checked(&mut self, id: &'a ItemId, valid: fn(Kind) -> bool, expected: &str) { if let Some(kind) = self.kind_of(id) { if valid(kind) { if !self.seen_ids.contains(id) { @@ -432,62 +432,62 @@ impl<'a> Validator<'a> { } } - fn add_any_id(&mut self, id: &'a Id) { + fn add_any_id(&mut self, id: &'a ItemId) { self.add_id_checked(id, |_| true, "any kind of item"); } - fn add_field_id(&mut self, id: &'a Id) { + fn add_field_id(&mut self, id: &'a ItemId) { self.add_id_checked(id, Kind::is_struct_field, "StructField"); } - fn add_mod_id(&mut self, id: &'a Id) { + fn add_mod_id(&mut self, id: &'a ItemId) { self.add_id_checked(id, Kind::is_module, "Module"); } - fn add_impl_id(&mut self, id: &'a Id) { + fn add_impl_id(&mut self, id: &'a ItemId) { self.add_id_checked(id, Kind::is_impl, "Impl"); } - fn add_variant_id(&mut self, id: &'a Id) { + fn add_variant_id(&mut self, id: &'a ItemId) { self.add_id_checked(id, Kind::is_variant, "Variant"); } - fn add_trait_or_alias_id(&mut self, id: &'a Id) { + fn add_trait_or_alias_id(&mut self, id: &'a ItemId) { self.add_id_checked(id, Kind::is_trait_or_alias, "Trait (or TraitAlias)"); } - fn add_type_id(&mut self, id: &'a Id) { + fn add_type_id(&mut self, id: &'a ItemId) { self.add_id_checked(id, Kind::is_type, "Type (Struct, Enum, Union or TypeAlias)"); } /// Add an Id that appeared in a trait - fn add_trait_item_id(&mut self, id: &'a Id) { + fn add_trait_item_id(&mut self, id: &'a ItemId) { self.add_id_checked(id, Kind::can_appear_in_trait, "Trait inner item"); } /// Add an Id that can be `use`d - fn add_import_item_id(&mut self, id: &'a Id) { + fn add_import_item_id(&mut self, id: &'a ItemId) { self.add_id_checked(id, Kind::can_appear_in_import, "Import inner item"); } - fn add_glob_import_item_id(&mut self, id: &'a Id) { + fn add_glob_import_item_id(&mut self, id: &'a ItemId) { self.add_id_checked(id, Kind::can_appear_in_glob_import, "Glob import inner item"); } /// Add an Id that appeared in a mod - fn add_mod_item_id(&mut self, id: &'a Id) { + fn add_mod_item_id(&mut self, id: &'a ItemId) { self.add_id_checked(id, Kind::can_appear_in_mod, "Module inner item") } - fn fail_expecting(&mut self, id: &Id, expected: &str) { + fn fail_expecting(&mut self, id: &ItemId, expected: &str) { let kind = self.kind_of(id).unwrap(); // We know it has a kind, as it's wrong. self.fail(id, ErrorKind::Custom(format!("Expected {expected} but found {kind:?}"))); } - fn fail(&mut self, id: &Id, kind: ErrorKind) { + fn fail(&mut self, id: &ItemId, kind: ErrorKind) { self.errs.push(Error { id: id.clone(), kind }); } - fn kind_of(&mut self, id: &Id) -> Option { + fn kind_of(&mut self, id: &ItemId) -> Option { if let Some(item) = self.krate.index.get(id) { Some(Kind::from_item(item)) } else if let Some(summary) = self.krate.paths.get(id) { diff --git a/src/tools/jsondoclint/src/validator/tests.rs b/src/tools/jsondoclint/src/validator/tests.rs index dd0b4ac5601a7..5fe4962f55815 100644 --- a/src/tools/jsondoclint/src/validator/tests.rs +++ b/src/tools/jsondoclint/src/validator/tests.rs @@ -18,19 +18,19 @@ fn check(krate: &Crate, errs: &[Error]) { #[test] fn errors_on_missing_links() { let k = Crate { - root: Id(0), + root: ItemId(0), crate_version: None, includes_private: false, index: FxHashMap::from_iter([( - Id(0), + ItemId(0), Item { name: Some("root".to_owned()), - id: Id(0), + id: ItemId(0), crate_id: 0, span: None, visibility: Visibility::Public, docs: None, - links: FxHashMap::from_iter([("Not Found".to_owned(), Id(1))]), + links: FxHashMap::from_iter([("Not Found".to_owned(), ItemId(1))]), attrs: vec![], deprecation: None, inner: ItemEnum::Module(Module { @@ -40,6 +40,7 @@ fn errors_on_missing_links() { }), }, )]), + types: vec![], paths: FxHashMap::default(), external_crates: FxHashMap::default(), target: rustdoc_json_types::Target { triple: "".to_string(), target_features: vec![] }, @@ -55,7 +56,7 @@ fn errors_on_missing_links() { SelectorPart::Field("links".to_owned()), SelectorPart::Field("Not Found".to_owned()), ]]), - id: Id(1), + id: ItemId(1), }], ); } @@ -65,33 +66,33 @@ fn errors_on_missing_links() { #[test] fn errors_on_local_in_paths_and_not_index() { let krate = Crate { - root: Id(0), + root: ItemId(0), crate_version: None, includes_private: false, index: FxHashMap::from_iter([ ( - Id(0), + ItemId(0), Item { - id: Id(0), + id: ItemId(0), crate_id: 0, name: Some("microcore".to_owned()), span: None, visibility: Visibility::Public, docs: None, - links: FxHashMap::from_iter([(("prim@i32".to_owned(), Id(2)))]), + links: FxHashMap::from_iter([(("prim@i32".to_owned(), ItemId(2)))]), attrs: Vec::new(), deprecation: None, inner: ItemEnum::Module(Module { is_crate: true, - items: vec![Id(1)], + items: vec![ItemId(1)], is_stripped: false, }), }, ), ( - Id(1), + ItemId(1), Item { - id: Id(1), + id: ItemId(1), crate_id: 0, name: Some("i32".to_owned()), span: None, @@ -104,8 +105,9 @@ fn errors_on_local_in_paths_and_not_index() { }, ), ]), + types: vec![], paths: FxHashMap::from_iter([( - Id(2), + ItemId(2), ItemSummary { crate_id: 0, path: vec!["microcore".to_owned(), "i32".to_owned()], @@ -120,7 +122,7 @@ fn errors_on_local_in_paths_and_not_index() { check( &krate, &[Error { - id: Id(2), + id: ItemId(2), kind: ErrorKind::Custom("Id for local item in `paths` but not in `index`".to_owned()), }], ); @@ -137,14 +139,14 @@ fn errors_on_missing_path() { let generics = Generics { params: vec![], where_predicates: vec![] }; let krate = Crate { - root: Id(0), + root: ItemId(0), crate_version: None, includes_private: false, index: FxHashMap::from_iter([ ( - Id(0), + ItemId(0), Item { - id: Id(0), + id: ItemId(0), crate_id: 0, name: Some("foo".to_owned()), span: None, @@ -155,15 +157,15 @@ fn errors_on_missing_path() { deprecation: None, inner: ItemEnum::Module(Module { is_crate: true, - items: vec![Id(1), Id(2)], + items: vec![ItemId(1), ItemId(2)], is_stripped: false, }), }, ), ( - Id(1), + ItemId(1), Item { - id: Id(0), + id: ItemId(0), crate_id: 0, name: Some("Bar".to_owned()), span: None, @@ -180,9 +182,9 @@ fn errors_on_missing_path() { }, ), ( - Id(2), + ItemId(2), Item { - id: Id(0), + id: ItemId(0), crate_id: 0, name: Some("mk_bar".to_owned()), span: None, @@ -194,11 +196,7 @@ fn errors_on_missing_path() { inner: ItemEnum::Function(Function { sig: FunctionSignature { inputs: vec![], - output: Some(Type::ResolvedPath(Path { - path: "Bar".to_owned(), - id: Id(1), - args: None, - })), + output: Some(0), is_c_variadic: false, }, generics, @@ -213,8 +211,9 @@ fn errors_on_missing_path() { }, ), ]), + types: vec![Type::ResolvedPath(Path { path: "Bar".to_owned(), id: ItemId(1), args: None })], paths: FxHashMap::from_iter([( - Id(0), + ItemId(0), ItemSummary { crate_id: 0, path: vec!["foo".to_owned()], kind: ItemKind::Module }, )]), external_crates: FxHashMap::default(), @@ -226,10 +225,10 @@ fn errors_on_missing_path() { &krate, &[Error { kind: ErrorKind::Custom( - r#"No entry in '$.paths' for Path { path: "Bar", id: Id(1), args: None }"# + r#"No entry in '$.paths' for Path { path: "Bar", id: ItemId(1), args: None }"# .to_owned(), ), - id: Id(1), + id: ItemId(1), }], ); } @@ -238,13 +237,13 @@ fn errors_on_missing_path() { #[should_panic = "LOCAL_CRATE_ID is wrong"] fn checks_local_crate_id_is_correct() { let krate = Crate { - root: Id(0), + root: ItemId(0), crate_version: None, includes_private: false, index: FxHashMap::from_iter([( - Id(0), + ItemId(0), Item { - id: Id(0), + id: ItemId(0), crate_id: LOCAL_CRATE_ID.wrapping_add(1), name: Some("irrelavent".to_owned()), span: None, @@ -260,6 +259,7 @@ fn checks_local_crate_id_is_correct() { }), }, )]), + types: vec![], paths: FxHashMap::default(), external_crates: FxHashMap::default(), target: rustdoc_json_types::Target { triple: "".to_string(), target_features: vec![] }, diff --git a/tests/run-make/rustdoc-types-depth/rmake.rs b/tests/run-make/rustdoc-types-depth/rmake.rs new file mode 100644 index 0000000000000..ae5fc809edb68 --- /dev/null +++ b/tests/run-make/rustdoc-types-depth/rmake.rs @@ -0,0 +1,28 @@ +use run_make_support::rustdoc; +use run_make_support::serde_json::{self, Value}; + +const REPEAT: usize = 150; + +fn main() { + let deeply_nested_code = + format!("pub type Foo = {}u128{};", "Box<".repeat(REPEAT), ">".repeat(REPEAT)); + let output = rustdoc() + .stdin_buf(deeply_nested_code) + .args(["-", "-Zunstable-options", "-wjson", "-o-"]) + .run() + .stdout(); + let parsed = serde_json::from_slice::(&output).expect("failed to parse JSON"); + + assert!(max_depth(&parsed) < 15); +} + +fn max_depth(v: &Value) -> usize { + match v { + Value::Null => 1, + Value::Bool(_) => 1, + Value::Number(_) => 1, + Value::String(_) => 1, + Value::Array(a) => a.iter().map(max_depth).max().unwrap_or(0) + 1, + Value::Object(o) => o.values().map(max_depth).max().unwrap_or(0) + 1, + } +} diff --git a/tests/rustdoc-json/assoc_items.rs b/tests/rustdoc-json/assoc_items.rs index f47a522e81a4a..8d7a7474b4c4c 100644 --- a/tests/rustdoc-json/assoc_items.rs +++ b/tests/rustdoc-json/assoc_items.rs @@ -15,19 +15,20 @@ pub trait EasyToImpl { type ToDeclare; //@ has "$.index[?(@.docs=='AN_ATTRIBUTE trait')].inner.assoc_const" //@ is "$.index[?(@.docs=='AN_ATTRIBUTE trait')].inner.assoc_const.value" null - //@ is "$.index[?(@.docs=='AN_ATTRIBUTE trait')].inner.assoc_const.type.primitive" '"usize"' + //@ is "$.index[?(@.docs=='AN_ATTRIBUTE trait')].inner.assoc_const.type" 0 + //@ is "$.types[0].primitive" '"usize"' /// AN_ATTRIBUTE trait const AN_ATTRIBUTE: usize; } impl EasyToImpl for Simple { //@ has "$.index[?(@.docs=='ToDeclare impl')].inner.assoc_type" - //@ is "$.index[?(@.docs=='ToDeclare impl')].inner.assoc_type.type.primitive" \"usize\" + //@ is "$.index[?(@.docs=='ToDeclare impl')].inner.assoc_type.type" 0 /// ToDeclare impl type ToDeclare = usize; //@ has "$.index[?(@.docs=='AN_ATTRIBUTE impl')].inner.assoc_const" - //@ is "$.index[?(@.docs=='AN_ATTRIBUTE impl')].inner.assoc_const.type.primitive" \"usize\" + //@ is "$.index[?(@.docs=='AN_ATTRIBUTE impl')].inner.assoc_const.type" 0 //@ is "$.index[?(@.docs=='AN_ATTRIBUTE impl')].inner.assoc_const.value" \"12\" /// AN_ATTRIBUTE impl const AN_ATTRIBUTE: usize = 12; diff --git a/tests/rustdoc-json/attrs/automatically_derived.rs b/tests/rustdoc-json/attrs/automatically_derived.rs index 4e1ab3d145e5d..2bebf682e211f 100644 --- a/tests/rustdoc-json/attrs/automatically_derived.rs +++ b/tests/rustdoc-json/attrs/automatically_derived.rs @@ -9,5 +9,8 @@ impl Default for Manual { } } -//@ is '$.index[?(@.inner.impl.for.resolved_path.path == "Derive" && @.inner.impl.trait.path == "Default")].attrs' '["#[automatically_derived]"]' -//@ is '$.index[?(@.inner.impl.for.resolved_path.path == "Manual" && @.inner.impl.trait.path == "Default")].attrs' '[]' +//@ is '$.types[0].resolved_path.path' '"Derive"' +//@ is '$.types[14].resolved_path.path' '"Manual"' + +//@ is '$.index[?(@.inner.impl.for == 0 && @.inner.impl.trait.path == "Default")].attrs' '["#[automatically_derived]"]' +//@ is '$.index[?(@.inner.impl.for == 14 && @.inner.impl.trait.path == "Default")].attrs' '[]' diff --git a/tests/rustdoc-json/blanket_impls.rs b/tests/rustdoc-json/blanket_impls.rs index d500bf5af6bd7..cce9af7870649 100644 --- a/tests/rustdoc-json/blanket_impls.rs +++ b/tests/rustdoc-json/blanket_impls.rs @@ -3,6 +3,7 @@ #![no_std] //@ has "$.index[?(@.name=='Error')].inner.assoc_type" -//@ has "$.index[?(@.name=='Error')].inner.assoc_type.type.resolved_path" -//@ has "$.index[?(@.name=='Error')].inner.assoc_type.type.resolved_path.path" \"Infallible\" +//@ has "$.index[?(@.name=='Error')].inner.assoc_type.type" 10 +//@ has "$.types[10].resolved_path" +//@ has "$.types[10].resolved_path.path" \"Infallible\" pub struct ForBlanketTryFromImpl; diff --git a/tests/rustdoc-json/enums/tuple_fields_hidden.rs b/tests/rustdoc-json/enums/tuple_fields_hidden.rs index aa25625b94cfa..c6f79178908ef 100644 --- a/tests/rustdoc-json/enums/tuple_fields_hidden.rs +++ b/tests/rustdoc-json/enums/tuple_fields_hidden.rs @@ -67,14 +67,16 @@ pub enum EnumWithStrippedTupleVariants { //@ is "$.index[?(@.docs=='3.3.0')].name" '"0"' //@ is "$.index[?(@.docs=='3.3.1')].name" '"1"' -//@ is "$.index[?(@.docs=='1.1.0')].inner.struct_field" '{"primitive": "bool"}' -//@ is "$.index[?(@.docs=='2.1.0')].inner.struct_field" '{"primitive": "bool"}' -//@ is "$.index[?(@.docs=='2.1.1')].inner.struct_field" '{"primitive": "bool"}' -//@ is "$.index[?(@.docs=='2.2.1')].inner.struct_field" '{"primitive": "bool"}' -//@ is "$.index[?(@.docs=='2.3.0')].inner.struct_field" '{"primitive": "bool"}' -//@ is "$.index[?(@.docs=='3.1.1')].inner.struct_field" '{"primitive": "bool"}' -//@ is "$.index[?(@.docs=='3.1.2')].inner.struct_field" '{"primitive": "bool"}' -//@ is "$.index[?(@.docs=='3.2.0')].inner.struct_field" '{"primitive": "bool"}' -//@ is "$.index[?(@.docs=='3.2.2')].inner.struct_field" '{"primitive": "bool"}' -//@ is "$.index[?(@.docs=='3.3.0')].inner.struct_field" '{"primitive": "bool"}' -//@ is "$.index[?(@.docs=='3.3.1')].inner.struct_field" '{"primitive": "bool"}' +//@ is "$.types[0].primitive" '"bool"' + +//@ is "$.index[?(@.docs=='1.1.0')].inner.struct_field" 0 +//@ is "$.index[?(@.docs=='2.1.0')].inner.struct_field" 0 +//@ is "$.index[?(@.docs=='2.1.1')].inner.struct_field" 0 +//@ is "$.index[?(@.docs=='2.2.1')].inner.struct_field" 0 +//@ is "$.index[?(@.docs=='2.3.0')].inner.struct_field" 0 +//@ is "$.index[?(@.docs=='3.1.1')].inner.struct_field" 0 +//@ is "$.index[?(@.docs=='3.1.2')].inner.struct_field" 0 +//@ is "$.index[?(@.docs=='3.2.0')].inner.struct_field" 0 +//@ is "$.index[?(@.docs=='3.2.2')].inner.struct_field" 0 +//@ is "$.index[?(@.docs=='3.3.0')].inner.struct_field" 0 +//@ is "$.index[?(@.docs=='3.3.1')].inner.struct_field" 0 diff --git a/tests/rustdoc-json/fn_pointer/abi.rs b/tests/rustdoc-json/fn_pointer/abi.rs index 34150c0fe89e0..f5be2f1ba0004 100644 --- a/tests/rustdoc-json/fn_pointer/abi.rs +++ b/tests/rustdoc-json/fn_pointer/abi.rs @@ -1,22 +1,29 @@ #![feature(abi_vectorcall)] -//@ is "$.index[?(@.name=='AbiRust')].inner.type_alias.type.function_pointer.header.abi" \"Rust\" +//@ is "$.index[?(@.name=='AbiRust')].inner.type_alias.type" 0 +//@ is "$.types[0].function_pointer.header.abi" \"Rust\" pub type AbiRust = fn(); -//@ is "$.index[?(@.name=='AbiC')].inner.type_alias.type.function_pointer.header.abi" '{"C": {"unwind": false}}' +//@ is "$.index[?(@.name=='AbiC')].inner.type_alias.type" 1 +//@ is "$.types[1].function_pointer.header.abi" '{"C": {"unwind": false}}' pub type AbiC = extern "C" fn(); -//@ is "$.index[?(@.name=='AbiSystem')].inner.type_alias.type.function_pointer.header.abi" '{"System": {"unwind": false}}' +//@ is "$.index[?(@.name=='AbiSystem')].inner.type_alias.type" 2 +//@ is "$.types[2].function_pointer.header.abi" '{"System": {"unwind": false}}' pub type AbiSystem = extern "system" fn(); -//@ is "$.index[?(@.name=='AbiCUnwind')].inner.type_alias.type.function_pointer.header.abi" '{"C": {"unwind": true}}' +//@ is "$.index[?(@.name=='AbiCUnwind')].inner.type_alias.type" 3 +//@ is "$.types[3].function_pointer.header.abi" '{"C": {"unwind": true}}' pub type AbiCUnwind = extern "C-unwind" fn(); -//@ is "$.index[?(@.name=='AbiSystemUnwind')].inner.type_alias.type.function_pointer.header.abi" '{"System": {"unwind": true}}' +//@ is "$.index[?(@.name=='AbiSystemUnwind')].inner.type_alias.type" 4 +//@ is "$.types[4].function_pointer.header.abi" '{"System": {"unwind": true}}' pub type AbiSystemUnwind = extern "system-unwind" fn(); -//@ is "$.index[?(@.name=='AbiVecorcall')].inner.type_alias.type.function_pointer.header.abi.Other" '"\"vectorcall\""' +//@ is "$.index[?(@.name=='AbiVecorcall')].inner.type_alias.type" 5 +//@ is "$.types[5].function_pointer.header.abi.Other" '"\"vectorcall\""' pub type AbiVecorcall = extern "vectorcall" fn(); -//@ is "$.index[?(@.name=='AbiVecorcallUnwind')].inner.type_alias.type.function_pointer.header.abi.Other" '"\"vectorcall-unwind\""' +//@ is "$.index[?(@.name=='AbiVecorcallUnwind')].inner.type_alias.type" 6 +//@ is "$.types[6].function_pointer.header.abi.Other" '"\"vectorcall-unwind\""' pub type AbiVecorcallUnwind = extern "vectorcall-unwind" fn(); diff --git a/tests/rustdoc-json/fn_pointer/generics.rs b/tests/rustdoc-json/fn_pointer/generics.rs index 960b91e7d8eab..ebcb9144ae36b 100644 --- a/tests/rustdoc-json/fn_pointer/generics.rs +++ b/tests/rustdoc-json/fn_pointer/generics.rs @@ -1,8 +1,11 @@ -//@ count "$.index[?(@.name=='WithHigherRankTraitBounds')].inner.type_alias.type.function_pointer.sig.inputs[*]" 1 -//@ is "$.index[?(@.name=='WithHigherRankTraitBounds')].inner.type_alias.type.function_pointer.sig.inputs[0][0]" '"val"' -//@ is "$.index[?(@.name=='WithHigherRankTraitBounds')].inner.type_alias.type.function_pointer.sig.inputs[0][1].borrowed_ref.lifetime" \"\'c\" -//@ is "$.index[?(@.name=='WithHigherRankTraitBounds')].inner.type_alias.type.function_pointer.sig.output.primitive" \"i32\" -//@ count "$.index[?(@.name=='WithHigherRankTraitBounds')].inner.type_alias.type.function_pointer.generic_params[*]" 1 -//@ is "$.index[?(@.name=='WithHigherRankTraitBounds')].inner.type_alias.type.function_pointer.generic_params[0].name" \"\'c\" -//@ is "$.index[?(@.name=='WithHigherRankTraitBounds')].inner.type_alias.type.function_pointer.generic_params[0].kind" '{ "lifetime": { "outlives": [] } }' +//@ is "$.index[?(@.name=='WithHigherRankTraitBounds')].inner.type_alias.type" 2 +//@ count "$.types[2].function_pointer.sig.inputs[*]" 1 +//@ is "$.types[2].function_pointer.sig.inputs[0][0]" '"val"' +//@ is "$.types[2].function_pointer.sig.inputs[0][1]" 1 +//@ is "$.types[1].borrowed_ref.lifetime" \"\'c\" +//@ is "$.types[2].function_pointer.sig.output" 0 +//@ is "$.types[0].primitive" \"i32\" +//@ count "$.types[2].function_pointer.generic_params[*]" 1 +//@ is "$.types[2].function_pointer.generic_params[0].name" \"\'c\" +//@ is "$.types[2].function_pointer.generic_params[0].kind" '{ "lifetime": { "outlives": [] } }' pub type WithHigherRankTraitBounds = for<'c> fn(val: &'c i32) -> i32; diff --git a/tests/rustdoc-json/fn_pointer/qualifiers.rs b/tests/rustdoc-json/fn_pointer/qualifiers.rs index 769749d0dd4c9..d8673902f4ea8 100644 --- a/tests/rustdoc-json/fn_pointer/qualifiers.rs +++ b/tests/rustdoc-json/fn_pointer/qualifiers.rs @@ -1,9 +1,11 @@ -//@ is "$.index[?(@.name=='FnPointer')].inner.type_alias.type.function_pointer.header.is_unsafe" false -//@ is "$.index[?(@.name=='FnPointer')].inner.type_alias.type.function_pointer.header.is_const" false -//@ is "$.index[?(@.name=='FnPointer')].inner.type_alias.type.function_pointer.header.is_async" false +//@ is "$.index[?(@.name=='FnPointer')].inner.type_alias.type" 0 +//@ is "$.types[0].function_pointer.header.is_unsafe" false +//@ is "$.types[0].function_pointer.header.is_const" false +//@ is "$.types[0].function_pointer.header.is_async" false pub type FnPointer = fn(); -//@ is "$.index[?(@.name=='UnsafePointer')].inner.type_alias.type.function_pointer.header.is_unsafe" true -//@ is "$.index[?(@.name=='UnsafePointer')].inner.type_alias.type.function_pointer.header.is_const" false -//@ is "$.index[?(@.name=='UnsafePointer')].inner.type_alias.type.function_pointer.header.is_async" false +//@ is "$.index[?(@.name=='UnsafePointer')].inner.type_alias.type" 1 +//@ is "$.types[1].function_pointer.header.is_unsafe" true +//@ is "$.types[1].function_pointer.header.is_const" false +//@ is "$.types[1].function_pointer.header.is_async" false pub type UnsafePointer = unsafe fn(); diff --git a/tests/rustdoc-json/fns/async_return.rs b/tests/rustdoc-json/fns/async_return.rs index e7c6a2981aceb..7fe108ea01052 100644 --- a/tests/rustdoc-json/fns/async_return.rs +++ b/tests/rustdoc-json/fns/async_return.rs @@ -4,29 +4,30 @@ use std::future::Future; -//@ is "$.index[?(@.name=='get_int')].inner.function.sig.output.primitive" \"i32\" +//@ is "$.types[0].primitive" \"i32\" + +//@ is "$.index[?(@.name=='get_int')].inner.function.sig.output" 0 //@ is "$.index[?(@.name=='get_int')].inner.function.header.is_async" false pub fn get_int() -> i32 { 42 } -//@ is "$.index[?(@.name=='get_int_async')].inner.function.sig.output.primitive" \"i32\" +//@ is "$.index[?(@.name=='get_int_async')].inner.function.sig.output" 0 //@ is "$.index[?(@.name=='get_int_async')].inner.function.header.is_async" true pub async fn get_int_async() -> i32 { 42 } -//@ is "$.index[?(@.name=='get_int_future')].inner.function.sig.output.impl_trait[0].trait_bound.trait.path" '"Future"' -//@ is "$.index[?(@.name=='get_int_future')].inner.function.sig.output.impl_trait[0].trait_bound.trait.args.angle_bracketed.constraints[0].name" '"Output"' -//@ is "$.index[?(@.name=='get_int_future')].inner.function.sig.output.impl_trait[0].trait_bound.trait.args.angle_bracketed.constraints[0].binding.equality.type.primitive" \"i32\" +//@ is "$.index[?(@.name=='get_int_future')].inner.function.sig.output" 1 +//@ is "$.types[1].impl_trait[0].trait_bound.trait.path" '"Future"' +//@ is "$.types[1].impl_trait[0].trait_bound.trait.args.angle_bracketed.constraints[0].name" '"Output"' +//@ is "$.types[1].impl_trait[0].trait_bound.trait.args.angle_bracketed.constraints[0].binding.equality.type" 0 //@ is "$.index[?(@.name=='get_int_future')].inner.function.header.is_async" false pub fn get_int_future() -> impl Future { async { 42 } } -//@ is "$.index[?(@.name=='get_int_future_async')].inner.function.sig.output.impl_trait[0].trait_bound.trait.path" '"Future"' -//@ is "$.index[?(@.name=='get_int_future_async')].inner.function.sig.output.impl_trait[0].trait_bound.trait.args.angle_bracketed.constraints[0].name" '"Output"' -//@ is "$.index[?(@.name=='get_int_future_async')].inner.function.sig.output.impl_trait[0].trait_bound.trait.args.angle_bracketed.constraints[0].binding.equality.type.primitive" \"i32\" +//@ is "$.index[?(@.name=='get_int_future_async')].inner.function.sig.output" 1 //@ is "$.index[?(@.name=='get_int_future_async')].inner.function.header.is_async" true pub async fn get_int_future_async() -> impl Future { async { 42 } diff --git a/tests/rustdoc-json/fns/generic_args.rs b/tests/rustdoc-json/fns/generic_args.rs index 2ea68173d68d8..675053f3c7c7a 100644 --- a/tests/rustdoc-json/fns/generic_args.rs +++ b/tests/rustdoc-json/fns/generic_args.rs @@ -12,7 +12,8 @@ pub trait GenericFoo<'a> {} //@ is "$.index[?(@.name=='generics')].inner.function.generics.params[0].kind.type.bounds[0].trait_bound.trait.id" '$foo' //@ count "$.index[?(@.name=='generics')].inner.function.sig.inputs[*]" 1 //@ is "$.index[?(@.name=='generics')].inner.function.sig.inputs[0][0]" '"f"' -//@ is "$.index[?(@.name=='generics')].inner.function.sig.inputs[0][1].generic" '"F"' +//@ is "$.index[?(@.name=='generics')].inner.function.sig.inputs[0][1]" 0 +//@ is "$.types[0].generic" '"F"' pub fn generics(f: F) {} //@ is "$.index[?(@.name=='impl_trait')].inner.function.generics.where_predicates" "[]" @@ -21,8 +22,9 @@ pub fn generics(f: F) {} //@ is "$.index[?(@.name=='impl_trait')].inner.function.generics.params[0].kind.type.bounds[0].trait_bound.trait.id" $foo //@ count "$.index[?(@.name=='impl_trait')].inner.function.sig.inputs[*]" 1 //@ is "$.index[?(@.name=='impl_trait')].inner.function.sig.inputs[0][0]" '"f"' -//@ count "$.index[?(@.name=='impl_trait')].inner.function.sig.inputs[0][1].impl_trait[*]" 1 -//@ is "$.index[?(@.name=='impl_trait')].inner.function.sig.inputs[0][1].impl_trait[0].trait_bound.trait.id" $foo +//@ is "$.index[?(@.name=='impl_trait')].inner.function.sig.inputs[0][1]" 1 +//@ count "$.types[1].impl_trait[*]" 1 +//@ is "$.types[1].impl_trait[0].trait_bound.trait.id" $foo pub fn impl_trait(f: impl Foo) {} //@ count "$.index[?(@.name=='where_clase')].inner.function.generics.params[*]" 3 @@ -30,14 +32,15 @@ pub fn impl_trait(f: impl Foo) {} //@ is "$.index[?(@.name=='where_clase')].inner.function.generics.params[0].kind" '{"type": {"bounds": [], "default": null, "is_synthetic": false}}' //@ count "$.index[?(@.name=='where_clase')].inner.function.sig.inputs[*]" 3 //@ is "$.index[?(@.name=='where_clase')].inner.function.sig.inputs[0][0]" '"f"' -//@ is "$.index[?(@.name=='where_clase')].inner.function.sig.inputs[0][1].generic" '"F"' +//@ is "$.index[?(@.name=='where_clase')].inner.function.sig.inputs[0][1]" 0 //@ count "$.index[?(@.name=='where_clase')].inner.function.generics.where_predicates[*]" 3 -//@ is "$.index[?(@.name=='where_clase')].inner.function.generics.where_predicates[0].bound_predicate.type.generic" \"F\" +//@ is "$.index[?(@.name=='where_clase')].inner.function.generics.where_predicates[0].bound_predicate.type" 0 //@ count "$.index[?(@.name=='where_clase')].inner.function.generics.where_predicates[0].bound_predicate.bounds[*]" 1 //@ is "$.index[?(@.name=='where_clase')].inner.function.generics.where_predicates[0].bound_predicate.bounds[0].trait_bound.trait.id" $foo -//@ is "$.index[?(@.name=='where_clase')].inner.function.generics.where_predicates[1].bound_predicate.type.generic" \"G\" +//@ is "$.index[?(@.name=='where_clase')].inner.function.generics.where_predicates[1].bound_predicate.type" 2 +//@ is "$.types[2].generic" \"G\" //@ count "$.index[?(@.name=='where_clase')].inner.function.generics.where_predicates[1].bound_predicate.bounds[*]" 1 //@ is "$.index[?(@.name=='where_clase')].inner.function.generics.where_predicates[1].bound_predicate.bounds[0].trait_bound.trait.id" $generic_foo //@ count "$.index[?(@.name=='where_clase')].inner.function.generics.where_predicates[1].bound_predicate.bounds[0].trait_bound.generic_params[*]" 1 @@ -45,8 +48,10 @@ pub fn impl_trait(f: impl Foo) {} //@ is "$.index[?(@.name=='where_clase')].inner.function.generics.where_predicates[1].bound_predicate.bounds[0].trait_bound.generic_params[0].kind.lifetime.outlives" "[]" //@ is "$.index[?(@.name=='where_clase')].inner.function.generics.where_predicates[1].bound_predicate.generic_params" "[]" -//@ is "$.index[?(@.name=='where_clase')].inner.function.generics.where_predicates[2].bound_predicate.type.borrowed_ref.lifetime" \"\'b\" -//@ is "$.index[?(@.name=='where_clase')].inner.function.generics.where_predicates[2].bound_predicate.type.borrowed_ref.type.generic" \"H\" +//@ is "$.index[?(@.name=='where_clase')].inner.function.generics.where_predicates[2].bound_predicate.type" 4 +//@ is "$.types[4].borrowed_ref.lifetime" \"\'b\" +//@ is "$.types[4].borrowed_ref.type" 3 +//@ is "$.types[3].generic" \"H\" //@ count "$.index[?(@.name=='where_clase')].inner.function.generics.where_predicates[2].bound_predicate.bounds[*]" 1 //@ is "$.index[?(@.name=='where_clase')].inner.function.generics.where_predicates[2].bound_predicate.bounds[0].trait_bound.trait.id" $foo //@ is "$.index[?(@.name=='where_clase')].inner.function.generics.where_predicates[2].bound_predicate.bounds[0].trait_bound.generic_params" "[]" diff --git a/tests/rustdoc-json/fns/generic_returns.rs b/tests/rustdoc-json/fns/generic_returns.rs index a0d4c745599cb..d0ea16d3ad6d7 100644 --- a/tests/rustdoc-json/fns/generic_returns.rs +++ b/tests/rustdoc-json/fns/generic_returns.rs @@ -4,8 +4,9 @@ pub trait Foo {} //@ is "$.index[?(@.name=='get_foo')].inner.function.sig.inputs" [] -//@ count "$.index[?(@.name=='get_foo')].inner.function.sig.output.impl_trait[*]" 1 -//@ is "$.index[?(@.name=='get_foo')].inner.function.sig.output.impl_trait[0].trait_bound.trait.id" $foo +//@ is "$.index[?(@.name=='get_foo')].inner.function.sig.output" 0 +//@ count "$.types[0].impl_trait[*]" 1 +//@ is "$.types[0].impl_trait[0].trait_bound.trait.id" $foo pub fn get_foo() -> impl Foo { Fooer {} } diff --git a/tests/rustdoc-json/fns/generics.rs b/tests/rustdoc-json/fns/generics.rs index 3efd917309a0e..faa45ac4371ab 100644 --- a/tests/rustdoc-json/fns/generics.rs +++ b/tests/rustdoc-json/fns/generics.rs @@ -6,7 +6,8 @@ pub trait Wham {} //@ is "$.index[?(@.name=='one_generic_param_fn')].inner.function.generics.params[0].name" '"T"' //@ is "$.index[?(@.name=='one_generic_param_fn')].inner.function.generics.params[0].kind.type.is_synthetic" false //@ is "$.index[?(@.name=='one_generic_param_fn')].inner.function.generics.params[0].kind.type.bounds[0].trait_bound.trait.id" $wham_id -//@ is "$.index[?(@.name=='one_generic_param_fn')].inner.function.sig.inputs" '[["w", {"generic": "T"}]]' +//@ is "$.index[?(@.name=='one_generic_param_fn')].inner.function.sig.inputs" '[["w", 0]]' +//@ is "$.types[0].generic" '"T"' pub fn one_generic_param_fn(w: T) {} //@ is "$.index[?(@.name=='one_synthetic_generic_param_fn')].inner.function.generics.where_predicates" [] @@ -16,5 +17,6 @@ pub fn one_generic_param_fn(w: T) {} //@ is "$.index[?(@.name=='one_synthetic_generic_param_fn')].inner.function.generics.params[0].kind.type.bounds[0].trait_bound.trait.id" $wham_id //@ count "$.index[?(@.name=='one_synthetic_generic_param_fn')].inner.function.sig.inputs[*]" 1 //@ is "$.index[?(@.name=='one_synthetic_generic_param_fn')].inner.function.sig.inputs[0][0]" '"w"' -//@ is "$.index[?(@.name=='one_synthetic_generic_param_fn')].inner.function.sig.inputs[0][1].impl_trait[0].trait_bound.trait.id" $wham_id +//@ is "$.index[?(@.name=='one_synthetic_generic_param_fn')].inner.function.sig.inputs[0][1]" 1 +//@ is "$.types[1].impl_trait[0].trait_bound.trait.id" $wham_id pub fn one_synthetic_generic_param_fn(w: impl Wham) {} diff --git a/tests/rustdoc-json/fns/return_type_alias.rs b/tests/rustdoc-json/fns/return_type_alias.rs index c39abc7589458..9a71f67b0afd5 100644 --- a/tests/rustdoc-json/fns/return_type_alias.rs +++ b/tests/rustdoc-json/fns/return_type_alias.rs @@ -3,7 +3,8 @@ //@ set foo = "$.index[?(@.name=='Foo')].id" pub type Foo = i32; -//@ is "$.index[?(@.name=='demo')].inner.function.sig.output.resolved_path.id" $foo +//@ is "$.index[?(@.name=='demo')].inner.function.sig.output" 1 +//@ is "$.types[1].resolved_path.id" $foo pub fn demo() -> Foo { 42 } diff --git a/tests/rustdoc-json/generic-associated-types/gats.rs b/tests/rustdoc-json/generic-associated-types/gats.rs index 5218cc886e35b..9e8165650c55a 100644 --- a/tests/rustdoc-json/generic-associated-types/gats.rs +++ b/tests/rustdoc-json/generic-associated-types/gats.rs @@ -4,17 +4,19 @@ pub trait LendingIterator { //@ count "$.index[?(@.name=='LendingItem')].inner.assoc_type.generics.params[*]" 1 //@ is "$.index[?(@.name=='LendingItem')].inner.assoc_type.generics.params[*].name" \"\'a\" //@ count "$.index[?(@.name=='LendingItem')].inner.assoc_type.generics.where_predicates[*]" 1 - //@ is "$.index[?(@.name=='LendingItem')].inner.assoc_type.generics.where_predicates[*].bound_predicate.type.generic" \"Self\" + //@ is "$.index[?(@.name=='LendingItem')].inner.assoc_type.generics.where_predicates[*].bound_predicate.type" 0 + //@ is "$.types[0].generic" \"Self\" //@ is "$.index[?(@.name=='LendingItem')].inner.assoc_type.generics.where_predicates[*].bound_predicate.bounds[*].outlives" \"\'a\" //@ count "$.index[?(@.name=='LendingItem')].inner.assoc_type.bounds[*]" 1 type LendingItem<'a>: Display where Self: 'a; - //@ count "$.index[?(@.name=='lending_next')].inner.function.sig.output.qualified_path.args.angle_bracketed.args[*]" 1 - //@ count "$.index[?(@.name=='lending_next')].inner.function.sig.output.qualified_path.args.angle_bracketed.bindings[*]" 0 - //@ is "$.index[?(@.name=='lending_next')].inner.function.sig.output.qualified_path.self_type.generic" \"Self\" - //@ is "$.index[?(@.name=='lending_next')].inner.function.sig.output.qualified_path.name" \"LendingItem\" + //@ is "$.index[?(@.name=='lending_next')].inner.function.sig.output" 2 + //@ count "$.types[2].qualified_path.args.angle_bracketed.args[*]" 1 + //@ count "$.types[2].qualified_path.args.angle_bracketed.bindings[*]" 0 + //@ is "$.types[2].qualified_path.self_type" 0 + //@ is "$.types[2].qualified_path.name" \"LendingItem\" fn lending_next<'a>(&'a self) -> Self::LendingItem<'a>; } @@ -26,7 +28,8 @@ pub trait Iterator { //@ count "$.index[?(@.name=='next')].inner.function.sig.output.qualified_path.args.angle_bracketed.args[*]" 0 //@ count "$.index[?(@.name=='next')].inner.function.sig.output.qualified_path.args.angle_bracketed.bindings[*]" 0 - //@ is "$.index[?(@.name=='next')].inner.function.sig.output.qualified_path.self_type.generic" \"Self\" - //@ is "$.index[?(@.name=='next')].inner.function.sig.output.qualified_path.name" \"Item\" + //@ is "$.index[?(@.name=='next')].inner.function.sig.output" 3 + //@ is "$.types[3].qualified_path.self_type" 0 + //@ is "$.types[3].qualified_path.name" \"Item\" fn next<'a>(&'a self) -> Self::Item; } diff --git a/tests/rustdoc-json/impl-trait-in-assoc-type.rs b/tests/rustdoc-json/impl-trait-in-assoc-type.rs index 742a46e896746..9005385b3b877 100644 --- a/tests/rustdoc-json/impl-trait-in-assoc-type.rs +++ b/tests/rustdoc-json/impl-trait-in-assoc-type.rs @@ -8,11 +8,13 @@ impl IntoIterator for AlwaysTrue { /// type Item type Item = bool; - //@ count '$.index[?(@.docs=="type IntoIter")].inner.assoc_type.type.impl_trait[*]' 1 - //@ is '$.index[?(@.docs=="type IntoIter")].inner.assoc_type.type.impl_trait[0].trait_bound.trait.path' '"Iterator"' - //@ count '$.index[?(@.docs=="type IntoIter")].inner.assoc_type.type.impl_trait[0].trait_bound.trait.args.angle_bracketed.constraints[*]' 1 - //@ is '$.index[?(@.docs=="type IntoIter")].inner.assoc_type.type.impl_trait[0].trait_bound.trait.args.angle_bracketed.constraints[0].name' '"Item"' - //@ is '$.index[?(@.docs=="type IntoIter")].inner.assoc_type.type.impl_trait[0].trait_bound.trait.args.angle_bracketed.constraints[0].binding.equality.type.primitive' '"bool"' + //@ is '$.index[?(@.docs=="type IntoIter")].inner.assoc_type.type' 15 + //@ count '$.types[15].impl_trait[*]' 1 + //@ is '$.types[15].impl_trait[0].trait_bound.trait.path' '"Iterator"' + //@ count '$.types[15].impl_trait[0].trait_bound.trait.args.angle_bracketed.constraints[*]' 1 + //@ is '$.types[15].impl_trait[0].trait_bound.trait.args.angle_bracketed.constraints[0].name' '"Item"' + //@ is '$.types[15].impl_trait[0].trait_bound.trait.args.angle_bracketed.constraints[0].binding.equality.type' 14 + //@ is '$.types[14].primitive' '"bool"' //@ set IntoIter = '$.index[?(@.docs=="type IntoIter")].id' /// type IntoIter diff --git a/tests/rustdoc-json/impl-trait-precise-capturing.rs b/tests/rustdoc-json/impl-trait-precise-capturing.rs index 37adb514f55fb..9d0284397377e 100644 --- a/tests/rustdoc-json/impl-trait-precise-capturing.rs +++ b/tests/rustdoc-json/impl-trait-precise-capturing.rs @@ -1,4 +1,5 @@ -//@ is "$.index[?(@.name=='hello')].inner.function.sig.output.impl_trait[1].use[0].lifetime" \"\'a\" -//@ is "$.index[?(@.name=='hello')].inner.function.sig.output.impl_trait[1].use[1].param" \"T\" -//@ is "$.index[?(@.name=='hello')].inner.function.sig.output.impl_trait[1].use[2].param" \"N\" +//@ is "$.index[?(@.name=='hello')].inner.function.sig.output" 0 +//@ is "$.types[0].impl_trait[1].use[0].lifetime" \"\'a\" +//@ is "$.types[0].impl_trait[1].use[1].param" \"T\" +//@ is "$.types[0].impl_trait[1].use[2].param" \"N\" pub fn hello<'a, T, const N: usize>() -> impl Sized + use<'a, T, N> {} diff --git a/tests/rustdoc-json/impls/auto.rs b/tests/rustdoc-json/impls/auto.rs index 5440301f96501..4be4a0b18377a 100644 --- a/tests/rustdoc-json/impls/auto.rs +++ b/tests/rustdoc-json/impls/auto.rs @@ -19,6 +19,7 @@ impl Foo { //@ is "$.index[?(@.docs=='has span')].span.end" "[15, 2]" //@ is "$.index[?(@.docs=='has span')].inner.impl.is_synthetic" false //@ is "$.index[?(@.inner.impl.is_synthetic==true)].span" null -//@ is "$.index[?(@.inner.impl.is_synthetic==true)].inner.impl.for.resolved_path.path" '"Foo"' +//@ is "$.index[?(@.inner.impl.is_synthetic==true)].inner.impl.for" 0 +//@ is "$.types[0].resolved_path.path" '"Foo"' //@ is "$.index[?(@.inner.impl.is_synthetic==true)].inner.impl.trait.path" '"Bar"' pub struct Foo; diff --git a/tests/rustdoc-json/impls/foreign_for_local.rs b/tests/rustdoc-json/impls/foreign_for_local.rs index e46b158d80205..355fa949af82f 100644 --- a/tests/rustdoc-json/impls/foreign_for_local.rs +++ b/tests/rustdoc-json/impls/foreign_for_local.rs @@ -12,7 +12,8 @@ pub struct LocalStruct; impl foreign_trait::ForeignTrait for LocalStruct {} //@ set impl = "$.index[?(@.docs=='foreign for local')].id" -//@ is "$.index[?(@.docs=='foreign for local')].inner.impl.for.resolved_path.id" $LocalStruct +//@ is "$.index[?(@.docs=='foreign for local')].inner.impl.for" 0 +//@ is "$.types[0].resolved_path.id" $LocalStruct //@ is "$.index[?(@.docs=='foreign for local')].inner.impl.trait.id" $ForeignTrait //@ has "$.index[?(@.name=='LocalStruct')].inner.struct.impls[*]" $impl diff --git a/tests/rustdoc-json/impls/local_for_foreign.rs b/tests/rustdoc-json/impls/local_for_foreign.rs index 86c72a580b2e3..af82eb519e765 100644 --- a/tests/rustdoc-json/impls/local_for_foreign.rs +++ b/tests/rustdoc-json/impls/local_for_foreign.rs @@ -13,6 +13,7 @@ impl LocalTrait for foreign_struct::ForeignStruct {} //@ set impl = "$.index[?(@.docs=='local for foreign')].id" //@ is "$.index[?(@.docs=='local for foreign')].inner.impl.trait.id" $LocalTrait -//@ is "$.index[?(@.docs=='local for foreign')].inner.impl.for.resolved_path.id" $ForeignStruct +//@ is "$.index[?(@.docs=='local for foreign')].inner.impl.for" 0 +//@ is "$.types[0].resolved_path.id" $ForeignStruct //@ is "$.index[?(@.name=='LocalTrait')].inner.trait.implementations[*]" $impl diff --git a/tests/rustdoc-json/impls/local_for_local.rs b/tests/rustdoc-json/impls/local_for_local.rs index 876a7912f09b0..035951045ff1c 100644 --- a/tests/rustdoc-json/impls/local_for_local.rs +++ b/tests/rustdoc-json/impls/local_for_local.rs @@ -9,4 +9,5 @@ impl Trait for Struct {} //@ has "$.index[?(@.name=='Struct')].inner.struct.impls[*]" $impl //@ is "$.index[?(@.name=='Trait')].inner.trait.implementations[*]" $impl //@ is "$.index[?(@.docs=='impl')].inner.impl.trait.id" $trait -//@ is "$.index[?(@.docs=='impl')].inner.impl.for.resolved_path.id" $struct +//@ is "$.index[?(@.docs=='impl')].inner.impl.for" 0 +//@ is "$.types[0].resolved_path.id" $struct diff --git a/tests/rustdoc-json/impls/local_for_local_primitive.rs b/tests/rustdoc-json/impls/local_for_local_primitive.rs index 859c0cb8ec82d..f28c6ed3ed54c 100644 --- a/tests/rustdoc-json/impls/local_for_local_primitive.rs +++ b/tests/rustdoc-json/impls/local_for_local_primitive.rs @@ -4,7 +4,8 @@ pub trait Local {} //@ is "$.index[?(@.docs=='Local for bool')].inner.impl.trait.id" $Local -//@ is "$.index[?(@.docs=='Local for bool')].inner.impl.for.primitive" '"bool"' +//@ is "$.index[?(@.docs=='Local for bool')].inner.impl.for" 0 +//@ is "$.types[0].primitive" '"bool"' /// Local for bool impl Local for bool {} diff --git a/tests/rustdoc-json/impls/trait-for-dyn-trait.rs b/tests/rustdoc-json/impls/trait-for-dyn-trait.rs index 17cb07f3571de..029cf5f38fa14 100644 --- a/tests/rustdoc-json/impls/trait-for-dyn-trait.rs +++ b/tests/rustdoc-json/impls/trait-for-dyn-trait.rs @@ -12,4 +12,5 @@ impl T1 for dyn T2 {} //@ is '$.index[?(@.name=="T2")].inner.trait.implementations' [] //@ is '$.index[?(@.docs=="Fun impl")].inner.impl.trait.id' $t1 -//@ is '$.index[?(@.docs=="Fun impl")].inner.impl.for.dyn_trait.traits[*].trait.id' $t2 +//@ is '$.index[?(@.docs=="Fun impl")].inner.impl.for' 0 +//@ is '$.types[0].dyn_trait.traits[*].trait.id' $t2 diff --git a/tests/rustdoc-json/lifetime/longest.rs b/tests/rustdoc-json/lifetime/longest.rs index 50cf084c39873..6c2fdf8f338ab 100644 --- a/tests/rustdoc-json/lifetime/longest.rs +++ b/tests/rustdoc-json/lifetime/longest.rs @@ -8,17 +8,14 @@ //@ is "$.index[?(@.name=='longest')].inner.function.sig.inputs[0][0]" '"l"' //@ is "$.index[?(@.name=='longest')].inner.function.sig.inputs[1][0]" '"r"' -//@ is "$.index[?(@.name=='longest')].inner.function.sig.inputs[0][1].borrowed_ref.lifetime" \"\'a\" -//@ is "$.index[?(@.name=='longest')].inner.function.sig.inputs[0][1].borrowed_ref.is_mutable" false -//@ is "$.index[?(@.name=='longest')].inner.function.sig.inputs[0][1].borrowed_ref.type.primitive" \"str\" +//@ is "$.index[?(@.name=='longest')].inner.function.sig.inputs[0][1]" 1 +//@ is "$.index[?(@.name=='longest')].inner.function.sig.inputs[1][1]" 1 +//@ is "$.index[?(@.name=='longest')].inner.function.sig.output" 1 -//@ is "$.index[?(@.name=='longest')].inner.function.sig.inputs[1][1].borrowed_ref.lifetime" \"\'a\" -//@ is "$.index[?(@.name=='longest')].inner.function.sig.inputs[1][1].borrowed_ref.is_mutable" false -//@ is "$.index[?(@.name=='longest')].inner.function.sig.inputs[1][1].borrowed_ref.type.primitive" \"str\" - -//@ is "$.index[?(@.name=='longest')].inner.function.sig.output.borrowed_ref.lifetime" \"\'a\" -//@ is "$.index[?(@.name=='longest')].inner.function.sig.output.borrowed_ref.is_mutable" false -//@ is "$.index[?(@.name=='longest')].inner.function.sig.output.borrowed_ref.type.primitive" \"str\" +//@ is "$.types[1].borrowed_ref.lifetime" \"\'a\" +//@ is "$.types[1].borrowed_ref.is_mutable" false +//@ is "$.types[1].borrowed_ref.type" 0 +//@ is "$.types[0].primitive" \"str\" pub fn longest<'a>(l: &'a str, r: &'a str) -> &'a str { if l.len() > r.len() { l } else { r } diff --git a/tests/rustdoc-json/lifetime/outlives.rs b/tests/rustdoc-json/lifetime/outlives.rs index f191b386c6cae..24c63a51e8368 100644 --- a/tests/rustdoc-json/lifetime/outlives.rs +++ b/tests/rustdoc-json/lifetime/outlives.rs @@ -8,9 +8,12 @@ //@ is "$.index[?(@.name=='foo')].inner.function.generics.params[2].kind.type.default" null //@ count "$.index[?(@.name=='foo')].inner.function.generics.params[2].kind.type.bounds[*]" 1 //@ is "$.index[?(@.name=='foo')].inner.function.generics.params[2].kind.type.bounds[0].outlives" \"\'b\" -//@ is "$.index[?(@.name=='foo')].inner.function.sig.inputs[0][1].borrowed_ref.lifetime" \"\'a\" -//@ is "$.index[?(@.name=='foo')].inner.function.sig.inputs[0][1].borrowed_ref.is_mutable" false -//@ is "$.index[?(@.name=='foo')].inner.function.sig.inputs[0][1].borrowed_ref.type.borrowed_ref.lifetime" \"\'b\" -//@ is "$.index[?(@.name=='foo')].inner.function.sig.inputs[0][1].borrowed_ref.type.borrowed_ref.is_mutable" false -//@ is "$.index[?(@.name=='foo')].inner.function.sig.inputs[0][1].borrowed_ref.type.borrowed_ref.type.generic" \"T\" +//@ is "$.index[?(@.name=='foo')].inner.function.sig.inputs[0][1]" 2 +//@ is "$.types[2].borrowed_ref.lifetime" \"\'a\" +//@ is "$.types[2].borrowed_ref.is_mutable" false +//@ is "$.types[2].borrowed_ref.type" 1 +//@ is "$.types[1].borrowed_ref.lifetime" \"\'b\" +//@ is "$.types[1].borrowed_ref.is_mutable" false +//@ is "$.types[1].borrowed_ref.type" 0 +//@ is "$.types[0].generic" \"T\" pub fn foo<'a, 'b: 'a, T: 'b>(_: &'a &'b T) {} diff --git a/tests/rustdoc-json/lifetime/outlives_in_where.rs b/tests/rustdoc-json/lifetime/outlives_in_where.rs index 48faf8ff8306e..badc0fe771c59 100644 --- a/tests/rustdoc-json/lifetime/outlives_in_where.rs +++ b/tests/rustdoc-json/lifetime/outlives_in_where.rs @@ -12,7 +12,8 @@ where //@ is '$.index[?(@.name=="on_trait")].inner.function.generics.params[1].kind.type.bounds' [] //@ is '$.index[?(@.name=="on_trait")].inner.function.generics.params[1].kind.type.bounds' [] //@ count '$.index[?(@.name=="on_trait")].inner.function.generics.where_predicates[*]' 1 -//@ is '$.index[?(@.name=="on_trait")].inner.function.generics.where_predicates[0].bound_predicate.type.generic' '"T"' +//@ is '$.index[?(@.name=="on_trait")].inner.function.generics.where_predicates[0].bound_predicate.type' 0 +//@ is '$.types[0].generic' '"T"' //@ count '$.index[?(@.name=="on_trait")].inner.function.generics.where_predicates[0].bound_predicate.bounds[*]' 1 //@ is '$.index[?(@.name=="on_trait")].inner.function.generics.where_predicates[0].bound_predicate.bounds[0].outlives' \"\'a\" pub fn on_trait<'a, T>() diff --git a/tests/rustdoc-json/path_name.rs b/tests/rustdoc-json/path_name.rs index dcfaa0607c4c4..1696cf69b4536 100644 --- a/tests/rustdoc-json/path_name.rs +++ b/tests/rustdoc-json/path_name.rs @@ -19,22 +19,28 @@ pub use priv_mod::{InPrivMod, InPrivMod as InPrivMod2}; use pub_mod::InPubMod as InPubMod3; pub use pub_mod::{InPubMod, InPubMod as InPubMod2}; -//@ is "$.index[?(@.name=='T0')].inner.type_alias.type.resolved_path.path" '"priv_mod::InPrivMod"' +//@ is "$.index[?(@.name=='T0')].inner.type_alias.type" 15 +//@ is "$.types[15].resolved_path.path" '"priv_mod::InPrivMod"' pub type T0 = priv_mod::InPrivMod; -//@ is "$.index[?(@.name=='T1')].inner.type_alias.type.resolved_path.path" '"InPrivMod"' +//@ is "$.index[?(@.name=='T1')].inner.type_alias.type" 0 +//@ is "$.types[0].resolved_path.path" '"InPrivMod"' pub type T1 = InPrivMod; -//@ is "$.index[?(@.name=='T2')].inner.type_alias.type.resolved_path.path" '"InPrivMod2"' +//@ is "$.index[?(@.name=='T2')].inner.type_alias.type" 16 +//@ is "$.types[16].resolved_path.path" '"InPrivMod2"' pub type T2 = InPrivMod2; -//@ is "$.index[?(@.name=='T3')].inner.type_alias.type.resolved_path.path" '"priv_mod::InPrivMod"' +//@ is "$.index[?(@.name=='T3')].inner.type_alias.type" 15 pub type T3 = InPrivMod3; -//@ is "$.index[?(@.name=='U0')].inner.type_alias.type.resolved_path.path" '"pub_mod::InPubMod"' +//@ is "$.index[?(@.name=='U0')].inner.type_alias.type" 17 +//@ is "$.types[17].resolved_path.path" '"pub_mod::InPubMod"' pub type U0 = pub_mod::InPubMod; -//@ is "$.index[?(@.name=='U1')].inner.type_alias.type.resolved_path.path" '"InPubMod"' +//@ is "$.index[?(@.name=='U1')].inner.type_alias.type" 14 +//@ is "$.types[14].resolved_path.path" '"InPubMod"' pub type U1 = InPubMod; -//@ is "$.index[?(@.name=='U2')].inner.type_alias.type.resolved_path.path" '"InPubMod2"' +//@ is "$.index[?(@.name=='U2')].inner.type_alias.type" 18 +//@ is "$.types[18].resolved_path.path" '"InPubMod2"' pub type U2 = InPubMod2; -//@ is "$.index[?(@.name=='U3')].inner.type_alias.type.resolved_path.path" '"pub_mod::InPubMod"' +//@ is "$.index[?(@.name=='U3')].inner.type_alias.type" 17 pub type U3 = InPubMod3; // Check we only have paths for structs at their original path @@ -43,25 +49,32 @@ pub type U3 = InPubMod3; pub use defines_and_reexports::{InPrivMod as XPrivMod, InPubMod as XPubMod}; use defines_and_reexports::{InPrivMod as XPrivMod2, InPubMod as XPubMod2}; -//@ is "$.index[?(@.name=='X0')].inner.type_alias.type.resolved_path.path" '"defines_and_reexports::m1::InPubMod"' +//@ is "$.index[?(@.name=='X0')].inner.type_alias.type" 19 +//@ is "$.types[19].resolved_path.path" '"defines_and_reexports::m1::InPubMod"' pub type X0 = defines_and_reexports::m1::InPubMod; -//@ is "$.index[?(@.name=='X1')].inner.type_alias.type.resolved_path.path" '"defines_and_reexports::InPubMod"' +//@ is "$.index[?(@.name=='X1')].inner.type_alias.type" 20 +//@ is "$.types[20].resolved_path.path" '"defines_and_reexports::InPubMod"' pub type X1 = defines_and_reexports::InPubMod; -//@ is "$.index[?(@.name=='X2')].inner.type_alias.type.resolved_path.path" '"defines_and_reexports::InPubMod2"' +//@ is "$.index[?(@.name=='X2')].inner.type_alias.type" 21 +//@ is "$.types[21].resolved_path.path" '"defines_and_reexports::InPubMod2"' pub type X2 = defines_and_reexports::InPubMod2; -//@ is "$.index[?(@.name=='X3')].inner.type_alias.type.resolved_path.path" '"XPubMod"' +//@ is "$.index[?(@.name=='X3')].inner.type_alias.type" 22 +//@ is "$.types[22].resolved_path.path" '"XPubMod"' pub type X3 = XPubMod; // N.B. This isn't the path as used *or* the original path! -//@ is "$.index[?(@.name=='X4')].inner.type_alias.type.resolved_path.path" '"defines_and_reexports::InPubMod"' +//@ is "$.index[?(@.name=='X4')].inner.type_alias.type" 20 pub type X4 = XPubMod2; -//@ is "$.index[?(@.name=='Y1')].inner.type_alias.type.resolved_path.path" '"defines_and_reexports::InPrivMod"' +//@ is "$.index[?(@.name=='Y1')].inner.type_alias.type" 23 +//@ is "$.types[23].resolved_path.path" '"defines_and_reexports::InPrivMod"' pub type Y1 = defines_and_reexports::InPrivMod; -//@ is "$.index[?(@.name=='Y2')].inner.type_alias.type.resolved_path.path" '"defines_and_reexports::InPrivMod2"' +//@ is "$.index[?(@.name=='Y2')].inner.type_alias.type" 24 +//@ is "$.types[24].resolved_path.path" '"defines_and_reexports::InPrivMod2"' pub type Y2 = defines_and_reexports::InPrivMod2; -//@ is "$.index[?(@.name=='Y3')].inner.type_alias.type.resolved_path.path" '"XPrivMod"' +//@ is "$.index[?(@.name=='Y3')].inner.type_alias.type" 25 +//@ is "$.types[25].resolved_path.path" '"XPrivMod"' pub type Y3 = XPrivMod; -//@ is "$.index[?(@.name=='Y4')].inner.type_alias.type.resolved_path.path" '"defines_and_reexports::InPrivMod"' +//@ is "$.index[?(@.name=='Y4')].inner.type_alias.type" 23 pub type Y4 = XPrivMod2; // For foreign items, $.paths contains the *origional* path, even if it's not publicly @@ -74,9 +87,12 @@ pub type Y4 = XPrivMod2; // Tests for the example in the docs of Path::name. // If these change, chage the docs. -//@ is "$.index[?(@.name=='Vec1')].inner.type_alias.type.resolved_path.path" '"std::vec::Vec"' +//@ is "$.index[?(@.name=='Vec1')].inner.type_alias.type" 27 +//@ is "$.types[27].resolved_path.path" '"std::vec::Vec"' pub type Vec1 = std::vec::Vec; -//@ is "$.index[?(@.name=='Vec2')].inner.type_alias.type.resolved_path.path" '"Vec"' +//@ is "$.index[?(@.name=='Vec2')].inner.type_alias.type" 28 +//@ is "$.types[28].resolved_path.path" '"Vec"' pub type Vec2 = Vec; -//@ is "$.index[?(@.name=='Vec3')].inner.type_alias.type.resolved_path.path" '"std::prelude::v1::Vec"' +//@ is "$.index[?(@.name=='Vec3')].inner.type_alias.type" 29 +//@ is "$.types[29].resolved_path.path" '"std::prelude::v1::Vec"' pub type Vec3 = std::prelude::v1::Vec; diff --git a/tests/rustdoc-json/primitives/primitive_type.rs b/tests/rustdoc-json/primitives/primitive_type.rs index a0d34218b805d..f285b5551ec51 100644 --- a/tests/rustdoc-json/primitives/primitive_type.rs +++ b/tests/rustdoc-json/primitives/primitive_type.rs @@ -1,17 +1,22 @@ #![feature(never_type)] //@ is "$.index[?(@.name=='PrimNever')].visibility" \"public\" -//@ is "$.index[?(@.name=='PrimNever')].inner.type_alias.type.primitive" \"never\" +//@ is "$.index[?(@.name=='PrimNever')].inner.type_alias.type" 0 +//@ is "$.types[0].primitive" \"never\" pub type PrimNever = !; -//@ is "$.index[?(@.name=='PrimStr')].inner.type_alias.type.primitive" \"str\" +//@ is "$.index[?(@.name=='PrimStr')].inner.type_alias.type" 1 +//@ is "$.types[1].primitive" \"str\" pub type PrimStr = str; -//@ is "$.index[?(@.name=='PrimBool')].inner.type_alias.type.primitive" \"bool\" +//@ is "$.index[?(@.name=='PrimBool')].inner.type_alias.type" 2 +//@ is "$.types[2].primitive" \"bool\" pub type PrimBool = bool; -//@ is "$.index[?(@.name=='PrimChar')].inner.type_alias.type.primitive" \"char\" +//@ is "$.index[?(@.name=='PrimChar')].inner.type_alias.type" 3 +//@ is "$.types[3].primitive" \"char\" pub type PrimChar = char; -//@ is "$.index[?(@.name=='PrimU8')].inner.type_alias.type.primitive" \"u8\" +//@ is "$.index[?(@.name=='PrimU8')].inner.type_alias.type" 4 +//@ is "$.types[4].primitive" \"u8\" pub type PrimU8 = u8; diff --git a/tests/rustdoc-json/return-type-notation.rs b/tests/rustdoc-json/return-type-notation.rs index 7943991616b99..8e8f484bf9527 100644 --- a/tests/rustdoc-json/return-type-notation.rs +++ b/tests/rustdoc-json/return-type-notation.rs @@ -9,7 +9,8 @@ pub trait Foo { } //@ is "$.index[?(@.name=='foo')].inner.function.generics.params[0].kind.type.bounds[0].trait_bound.trait.args.angle_bracketed.constraints[0].args" '"return_type_notation"' -//@ ismany "$.index[?(@.name=='foo')].inner.function.generics.where_predicates[*].bound_predicate.type.qualified_path.args" '"return_type_notation"' '"return_type_notation"' +//@ ismany "$.index[?(@.name=='foo')].inner.function.generics.where_predicates[*].bound_predicate.type" 1 2 +//@ ismany "$.types[1, 2].qualified_path.args" '"return_type_notation"' '"return_type_notation"' pub fn foo>() where ::bar(..): 'static, diff --git a/tests/rustdoc-json/return_private.rs b/tests/rustdoc-json/return_private.rs index 8fbdb6be5c912..e965638e6cc0f 100644 --- a/tests/rustdoc-json/return_private.rs +++ b/tests/rustdoc-json/return_private.rs @@ -6,8 +6,9 @@ mod secret { } //@ has "$.index[?(@.name=='get_secret')].inner.function" -//@ is "$.index[?(@.name=='get_secret')].inner.function.sig.output.resolved_path.path" '"secret::Secret"' -//@ is "$.index[?(@.name=='get_secret')].inner.function.sig.output.resolved_path.id" $struct_secret +//@ is "$.index[?(@.name=='get_secret')].inner.function.sig.output" 0 +//@ is "$.types[0].resolved_path.path" '"secret::Secret"' +//@ is "$.types[0].resolved_path.id" $struct_secret pub fn get_secret() -> secret::Secret { secret::Secret } diff --git a/tests/rustdoc-json/statics/extern.rs b/tests/rustdoc-json/statics/extern.rs index 5be13c8b8fc49..fed91a8886250 100644 --- a/tests/rustdoc-json/statics/extern.rs +++ b/tests/rustdoc-json/statics/extern.rs @@ -35,4 +35,5 @@ unsafe extern "C" { } //@ ismany '$.index[?(@.inner.static)].inner.static.expr' '""' '""' '""' '""' '""' '""' '""' '""' -//@ ismany '$.index[?(@.inner.static)].inner.static.type.primitive' '"i32"' '"i32"' '"i32"' '"i32"' '"i32"' '"i32"' '"i32"' '"i32"' +//@ is '$.types[0].primitive' '"i32"' +//@ ismany '$.index[?(@.inner.static)].inner.static.type' 0 0 0 0 0 0 0 0 diff --git a/tests/rustdoc-json/statics/statics.rs b/tests/rustdoc-json/statics/statics.rs index 497a134c503dd..037054a78c330 100644 --- a/tests/rustdoc-json/statics/statics.rs +++ b/tests/rustdoc-json/statics/statics.rs @@ -1,10 +1,12 @@ -//@ is '$.index[?(@.name=="A")].inner.static.type.primitive' '"i32"' +//@ is '$.index[?(@.name=="A")].inner.static.type' 0 +//@ is '$.types[0].primitive' '"i32"' //@ is '$.index[?(@.name=="A")].inner.static.is_mutable' false //@ is '$.index[?(@.name=="A")].inner.static.expr' '"5"' //@ is '$.index[?(@.name=="A")].inner.static.is_unsafe' false pub static A: i32 = 5; -//@ is '$.index[?(@.name=="B")].inner.static.type.primitive' '"u32"' +//@ is '$.index[?(@.name=="B")].inner.static.type' 1 +//@ is '$.types[1].primitive' '"u32"' //@ is '$.index[?(@.name=="B")].inner.static.is_mutable' true // Expr value isn't gaurenteed, it'd be fine to change it. //@ is '$.index[?(@.name=="B")].inner.static.expr' '"_"' diff --git a/tests/rustdoc-json/trait_alias.rs b/tests/rustdoc-json/trait_alias.rs index e7a586ee95a3e..06a25e38752e9 100644 --- a/tests/rustdoc-json/trait_alias.rs +++ b/tests/rustdoc-json/trait_alias.rs @@ -6,12 +6,14 @@ //@ is "$.index[?(@.name=='StrLike')].span.filename" $FILE pub trait StrLike = AsRef; -//@ is "$.index[?(@.name=='f')].inner.function.sig.output.impl_trait[0].trait_bound.trait.id" $StrLike +//@ is "$.index[?(@.name=='f')].inner.function.sig.output" 1 +//@ is "$.types[1].impl_trait[0].trait_bound.trait.id" $StrLike pub fn f() -> impl StrLike { "heya" } -//@ !is "$.index[?(@.name=='g')].inner.function.sig.output.impl_trait[0].trait_bound.trait.id" $StrLike +//@ is "$.index[?(@.name=='g')].inner.function.sig.output" 2 +//@ !is "$.types[2].impl_trait[0].trait_bound.trait.id" $StrLike pub fn g() -> impl AsRef { "heya" } diff --git a/tests/rustdoc-json/traits/implementors.rs b/tests/rustdoc-json/traits/implementors.rs index 499acefedb773..2f3ebc8b0c5d2 100644 --- a/tests/rustdoc-json/traits/implementors.rs +++ b/tests/rustdoc-json/traits/implementors.rs @@ -15,4 +15,5 @@ impl Wham for GeorgeMichael {} // Impl points to both struct and trait. //@ is "$.index[?(@.docs == 'Wham for George Michael')].inner.impl.trait.id" $wham -//@ is "$.index[?(@.docs == 'Wham for George Michael')].inner.impl.for.resolved_path.id" $gm +//@ is "$.index[?(@.docs == 'Wham for George Michael')].inner.impl.for" 0 +//@ is "$.types[0].resolved_path.id" $gm diff --git a/tests/rustdoc-json/traits/self.rs b/tests/rustdoc-json/traits/self.rs index 018bda9cc3c5a..5fe6460f4b50b 100644 --- a/tests/rustdoc-json/traits/self.rs +++ b/tests/rustdoc-json/traits/self.rs @@ -8,28 +8,32 @@ pub struct Foo; impl Foo { //@ ismany '$.index[?(@.name=="by_ref")].inner.function.sig.inputs[0][0]' '"self"' '"self"' '"self"' - //@ ismany '$.index[?(@.name=="by_ref")].inner.function.sig.inputs[0][1].borrowed_ref.type.generic' '"Self"' '"Self"' '"Self"' - //@ ismany '$.index[?(@.name=="by_ref")].inner.function.sig.inputs[0][1].borrowed_ref.lifetime' null null null - //@ ismany '$.index[?(@.name=="by_ref")].inner.function.sig.inputs[0][1].borrowed_ref.is_mutable' false false false + //@ ismany '$.index[?(@.name=="by_ref")].inner.function.sig.inputs[0][1]' 1 1 1 + //@ is '$.types[1].borrowed_ref.type' 0 + //@ is '$.types[0].generic' '"Self"' + //@ is '$.types[1].borrowed_ref.lifetime' null + //@ is '$.types[1].borrowed_ref.is_mutable' false pub fn by_ref(&self) {} //@ ismany '$.index[?(@.name=="by_exclusive_ref")].inner.function.sig.inputs[0][0]' '"self"' '"self"' '"self"' - //@ ismany '$.index[?(@.name=="by_exclusive_ref")].inner.function.sig.inputs[0][1].borrowed_ref.type.generic' '"Self"' '"Self"' '"Self"' - //@ ismany '$.index[?(@.name=="by_exclusive_ref")].inner.function.sig.inputs[0][1].borrowed_ref.lifetime' null null null - //@ ismany '$.index[?(@.name=="by_exclusive_ref")].inner.function.sig.inputs[0][1].borrowed_ref.is_mutable' true true true + //@ ismany '$.index[?(@.name=="by_exclusive_ref")].inner.function.sig.inputs[0][1]' 2 2 2 + //@ is '$.types[2].borrowed_ref.type' 0 + //@ is '$.types[2].borrowed_ref.lifetime' null + //@ is '$.types[2].borrowed_ref.is_mutable' true pub fn by_exclusive_ref(&mut self) {} //@ ismany '$.index[?(@.name=="by_value")].inner.function.sig.inputs[0][0]' '"self"' '"self"' '"self"' - //@ ismany '$.index[?(@.name=="by_value")].inner.function.sig.inputs[0][1].generic' '"Self"' '"Self"' '"Self"' + //@ ismany '$.index[?(@.name=="by_value")].inner.function.sig.inputs[0][1]' 0 0 0 pub fn by_value(self) {} //@ ismany '$.index[?(@.name=="with_lifetime")].inner.function.sig.inputs[0][0]' '"self"' '"self"' '"self"' - //@ ismany '$.index[?(@.name=="with_lifetime")].inner.function.sig.inputs[0][1].borrowed_ref.type.generic' '"Self"' '"Self"' '"Self"' - //@ ismany '$.index[?(@.name=="with_lifetime")].inner.function.sig.inputs[0][1].borrowed_ref.lifetime' \"\'a\" \"\'a\" \"\'a\" - //@ ismany '$.index[?(@.name=="with_lifetime")].inner.function.sig.inputs[0][1].borrowed_ref.is_mutable' false false false + //@ ismany '$.index[?(@.name=="with_lifetime")].inner.function.sig.inputs[0][1]' 3 3 3 + //@ is '$.types[3].borrowed_ref.type' 0 + //@ is '$.types[3].borrowed_ref.lifetime' \"\'a\" + //@ is '$.types[3].borrowed_ref.is_mutable' false pub fn with_lifetime<'a>(&'a self) {} - //@ ismany '$.index[?(@.name=="build")].inner.function.sig.output.generic' '"Self"' '"Self"' '"Self"' + //@ ismany '$.index[?(@.name=="build")].inner.function.sig.output' 0 0 0 pub fn build() -> Self { Self } diff --git a/tests/rustdoc-json/traits/trait_alias.rs b/tests/rustdoc-json/traits/trait_alias.rs index 497930a67c832..237cf04729a80 100644 --- a/tests/rustdoc-json/traits/trait_alias.rs +++ b/tests/rustdoc-json/traits/trait_alias.rs @@ -11,15 +11,17 @@ pub trait Orig {} //@ is "$.index[?(@.name == 'Alias')].inner.trait_alias.generics" '{"params": [], "where_predicates": []}' //@ count "$.index[?(@.name == 'Alias')].inner.trait_alias.params[*]" 1 //@ is "$.index[?(@.name == 'Alias')].inner.trait_alias.params[0].trait_bound.trait.id" $Orig -//@ is "$.index[?(@.name == 'Alias')].inner.trait_alias.params[0].trait_bound.trait.args.angle_bracketed.args[0].type.primitive" '"i32"' +//@ is "$.index[?(@.name == 'Alias')].inner.trait_alias.params[0].trait_bound.trait.args.angle_bracketed.args[0].type" 0 +//@ is "$.types[0].primitive" '"i32"' pub trait Alias = Orig; pub struct Struct; impl Orig for Struct {} -//@ has "$.index[?(@.name=='takes_alias')].inner.function.sig.inputs[0][1].impl_trait" -//@ is "$.index[?(@.name=='takes_alias')].inner.function.sig.inputs[0][1].impl_trait[0].trait_bound.trait.id" $Alias +//@ is "$.index[?(@.name=='takes_alias')].inner.function.sig.inputs[0][1]" 15 +//@ has "$.types[15].impl_trait" +//@ is "$.types[15].impl_trait[0].trait_bound.trait.id" $Alias //@ is "$.index[?(@.name=='takes_alias')].inner.function.generics.params[0].kind.type.bounds[0].trait_bound.trait.id" $Alias pub fn takes_alias(_: impl Alias) {} // FIXME: Should the trait be mentioned in both the decl and generics? diff --git a/tests/rustdoc-json/type/dyn.rs b/tests/rustdoc-json/type/dyn.rs index 4e533a67f8b4d..6110422391829 100644 --- a/tests/rustdoc-json/type/dyn.rs +++ b/tests/rustdoc-json/type/dyn.rs @@ -6,40 +6,47 @@ use std::fmt::Debug; //@ set weird_order = "$.index[?(@.name=='WeirdOrder')].id" //@ ismany "$.index[?(@.name=='dyn')].inner.module.items[*]" $sync_int_gen $ref_fn $weird_order -//@ has "$.index[?(@.name=='SyncIntGen')].inner.type_alias" +//@ has "$.index[?(@.name=='SyncIntGen')].inner.type_alias" //@ is "$.index[?(@.name=='SyncIntGen')].inner.type_alias.generics" '{"params": [], "where_predicates": []}' -//@ has "$.index[?(@.name=='SyncIntGen')].inner.type_alias.type.resolved_path" -//@ is "$.index[?(@.name=='SyncIntGen')].inner.type_alias.type.resolved_path.path" \"Box\" -//@ is "$.index[?(@.name=='SyncIntGen')].inner.type_alias.type.resolved_path.args.angle_bracketed.constraints" [] -//@ count "$.index[?(@.name=='SyncIntGen')].inner.type_alias.type.resolved_path.args.angle_bracketed.args" 1 -//@ has "$.index[?(@.name=='SyncIntGen')].inner.type_alias.type.resolved_path.args.angle_bracketed.args[0].type.dyn_trait" -//@ is "$.index[?(@.name=='SyncIntGen')].inner.type_alias.type.resolved_path.args.angle_bracketed.args[0].type.dyn_trait.lifetime" \"\'static\" -//@ count "$.index[?(@.name=='SyncIntGen')].inner.type_alias.type.resolved_path.args.angle_bracketed.args[0].type.dyn_trait.traits[*]" 3 -//@ is "$.index[?(@.name=='SyncIntGen')].inner.type_alias.type.resolved_path.args.angle_bracketed.args[0].type.dyn_trait.traits[0].generic_params" [] -//@ is "$.index[?(@.name=='SyncIntGen')].inner.type_alias.type.resolved_path.args.angle_bracketed.args[0].type.dyn_trait.traits[1].generic_params" [] -//@ is "$.index[?(@.name=='SyncIntGen')].inner.type_alias.type.resolved_path.args.angle_bracketed.args[0].type.dyn_trait.traits[2].generic_params" [] -//@ is "$.index[?(@.name=='SyncIntGen')].inner.type_alias.type.resolved_path.args.angle_bracketed.args[0].type.dyn_trait.traits[0].trait.path" '"Fn"' -//@ is "$.index[?(@.name=='SyncIntGen')].inner.type_alias.type.resolved_path.args.angle_bracketed.args[0].type.dyn_trait.traits[1].trait.path" '"Send"' -//@ is "$.index[?(@.name=='SyncIntGen')].inner.type_alias.type.resolved_path.args.angle_bracketed.args[0].type.dyn_trait.traits[2].trait.path" '"Sync"' -//@ is "$.index[?(@.name=='SyncIntGen')].inner.type_alias.type.resolved_path.args.angle_bracketed.args[0].type.dyn_trait.traits[0].trait.args" '{"parenthesized": {"inputs": [],"output": {"primitive": "i32"}}}' +//@ is "$.index[?(@.name=='SyncIntGen')].inner.type_alias.type" 2 +//@ has "$.types[2].resolved_path" +//@ is "$.types[2].resolved_path.path" \"Box\" +//@ is "$.types[2].resolved_path.args.angle_bracketed.constraints" [] +//@ count "$.types[2].resolved_path.args.angle_bracketed.args" 1 +//@ is "$.types[2].resolved_path.args.angle_bracketed.args[0].type" 1 +//@ has "$.types[1].dyn_trait" +//@ is "$.types[1].dyn_trait.lifetime" \"\'static\" +//@ count "$.types[1].dyn_trait.traits[*]" 3 +//@ is "$.types[1].dyn_trait.traits[0].generic_params" [] +//@ is "$.types[1].dyn_trait.traits[1].generic_params" [] +//@ is "$.types[1].dyn_trait.traits[2].generic_params" [] +//@ is "$.types[1].dyn_trait.traits[0].trait.path" '"Fn"' +//@ is "$.types[1].dyn_trait.traits[1].trait.path" '"Send"' +//@ is "$.types[1].dyn_trait.traits[2].trait.path" '"Sync"' +//@ is "$.types[0].primitive" '"i32"' +//@ is "$.types[1].dyn_trait.traits[0].trait.args" '{"parenthesized": {"inputs": [],"output": 0}}' pub type SyncIntGen = Box i32 + Send + Sync + 'static>; //@ has "$.index[?(@.name=='RefFn')].inner.type_alias" //@ is "$.index[?(@.name=='RefFn')].inner.type_alias.generics" '{"params": [{"kind": {"lifetime": {"outlives": []}},"name": "'\''a"}],"where_predicates": []}' -//@ has "$.index[?(@.name=='RefFn')].inner.type_alias.type.borrowed_ref" -//@ is "$.index[?(@.name=='RefFn')].inner.type_alias.type.borrowed_ref.is_mutable" 'false' -//@ is "$.index[?(@.name=='RefFn')].inner.type_alias.type.borrowed_ref.lifetime" "\"'a\"" -//@ has "$.index[?(@.name=='RefFn')].inner.type_alias.type.borrowed_ref.type.dyn_trait" -//@ is "$.index[?(@.name=='RefFn')].inner.type_alias.type.borrowed_ref.type.dyn_trait.lifetime" null -//@ count "$.index[?(@.name=='RefFn')].inner.type_alias.type.borrowed_ref.type.dyn_trait.traits[*]" 1 -//@ is "$.index[?(@.name=='RefFn')].inner.type_alias.type.borrowed_ref.type.dyn_trait.traits[0].generic_params" '[{"kind": {"lifetime": {"outlives": []}},"name": "'\''b"}]' -//@ is "$.index[?(@.name=='RefFn')].inner.type_alias.type.borrowed_ref.type.dyn_trait.traits[0].trait.path" '"Fn"' -//@ has "$.index[?(@.name=='RefFn')].inner.type_alias.type.borrowed_ref.type.dyn_trait.traits[0].trait.args.parenthesized.inputs[0].borrowed_ref" -//@ is "$.index[?(@.name=='RefFn')].inner.type_alias.type.borrowed_ref.type.dyn_trait.traits[0].trait.args.parenthesized.inputs[0].borrowed_ref.lifetime" "\"'b\"" -//@ has "$.index[?(@.name=='RefFn')].inner.type_alias.type.borrowed_ref.type.dyn_trait.traits[0].trait.args.parenthesized.output.borrowed_ref" -//@ is "$.index[?(@.name=='RefFn')].inner.type_alias.type.borrowed_ref.type.dyn_trait.traits[0].trait.args.parenthesized.output.borrowed_ref.lifetime" "\"'b\"" +//@ is "$.index[?(@.name=='RefFn')].inner.type_alias.type" 5 +//@ has "$.types[5].borrowed_ref" +//@ is "$.types[5].borrowed_ref.is_mutable" 'false' +//@ is "$.types[5].borrowed_ref.lifetime" "\"'a\"" +//@ is "$.types[5].borrowed_ref.type" 4 +//@ has "$.types[4].dyn_trait" +//@ is "$.types[4].dyn_trait.lifetime" null +//@ count "$.types[4].dyn_trait.traits[*]" 1 +//@ is "$.types[4].dyn_trait.traits[0].generic_params" '[{"kind": {"lifetime": {"outlives": []}},"name": "'\''b"}]' +//@ is "$.types[4].dyn_trait.traits[0].trait.path" '"Fn"' +//@ is "$.types[4].dyn_trait.traits[0].trait.args.parenthesized.inputs[0]" 3 +//@ has "$.types[3].borrowed_ref" +//@ is "$.types[3].borrowed_ref.lifetime" "\"'b\"" +//@ is "$.types[4].dyn_trait.traits[0].trait.args.parenthesized.output" 3 pub type RefFn<'a> = &'a dyn for<'b> Fn(&'b i32) -> &'b i32; -//@ is "$.index[?(@.name=='WeirdOrder')].inner.type_alias.type.resolved_path.args.angle_bracketed.args[0].type.dyn_trait.traits[0].trait.path" '"Send"' -//@ is "$.index[?(@.name=='WeirdOrder')].inner.type_alias.type.resolved_path.args.angle_bracketed.args[0].type.dyn_trait.traits[1].trait.path" '"Debug"' +//@ is "$.index[?(@.name=='WeirdOrder')].inner.type_alias.type" 7 +//@ is "$.types[7].resolved_path.args.angle_bracketed.args[0].type" 6 +//@ is "$.types[6].dyn_trait.traits[0].trait.path" '"Send"' +//@ is "$.types[6].dyn_trait.traits[1].trait.path" '"Debug"' pub type WeirdOrder = Box; diff --git a/tests/rustdoc-json/type/fn_lifetime.rs b/tests/rustdoc-json/type/fn_lifetime.rs index 10e95cc5e5624..6cafeb702230e 100644 --- a/tests/rustdoc-json/type/fn_lifetime.rs +++ b/tests/rustdoc-json/type/fn_lifetime.rs @@ -5,20 +5,23 @@ //@ count "$.index[?(@.name=='GenericFn')].inner.type_alias.generics.params[*].kind.lifetime.outlives[*]" 0 //@ count "$.index[?(@.name=='GenericFn')].inner.type_alias.generics.where_predicates[*]" 0 //@ count "$.index[?(@.name=='GenericFn')].inner.type_alias.type.function_pointer.generic_params[*]" 0 -//@ count "$.index[?(@.name=='GenericFn')].inner.type_alias.type.function_pointer.sig.inputs[*]" 1 -//@ is "$.index[?(@.name=='GenericFn')].inner.type_alias.type.function_pointer.sig.inputs[*][1].borrowed_ref.lifetime" \"\'a\" -//@ is "$.index[?(@.name=='GenericFn')].inner.type_alias.type.function_pointer.sig.output.borrowed_ref.lifetime" \"\'a\" +//@ is "$.index[?(@.name=='GenericFn')].inner.type_alias.type" 2 +//@ count "$.types[2].function_pointer.sig.inputs[*]" 1 +//@ is "$.types[2].function_pointer.sig.inputs[*][1]" 1 +//@ is "$.types[1].borrowed_ref.lifetime" \"\'a\" +//@ is "$.types[2].function_pointer.sig.output" 1 pub type GenericFn<'a> = fn(&'a i32) -> &'a i32; //@ has "$.index[?(@.name=='ForAll')].inner.type_alias" //@ count "$.index[?(@.name=='ForAll')].inner.type_alias.generics.params[*]" 0 //@ count "$.index[?(@.name=='ForAll')].inner.type_alias.generics.where_predicates[*]" 0 -//@ count "$.index[?(@.name=='ForAll')].inner.type_alias.type.function_pointer.generic_params[*]" 1 -//@ is "$.index[?(@.name=='ForAll')].inner.type_alias.type.function_pointer.generic_params[*].name" \"\'a\" -//@ has "$.index[?(@.name=='ForAll')].inner.type_alias.type.function_pointer.generic_params[*].kind.lifetime" -//@ count "$.index[?(@.name=='ForAll')].inner.type_alias.type.function_pointer.generic_params[*].kind.lifetime.outlives[*]" 0 -//@ count "$.index[?(@.name=='ForAll')].inner.type_alias.type.function_pointer.sig.inputs[*]" 1 -//@ is "$.index[?(@.name=='ForAll')].inner.type_alias.type.function_pointer.sig.inputs[*][1].borrowed_ref.lifetime" \"\'a\" -//@ is "$.index[?(@.name=='ForAll')].inner.type_alias.type.function_pointer.sig.output.borrowed_ref.lifetime" \"\'a\" +//@ is "$.index[?(@.name=='ForAll')].inner.type_alias.type" 3 +//@ count "$.types[3].function_pointer.generic_params[*]" 1 +//@ is "$.types[3].function_pointer.generic_params[*].name" \"\'a\" +//@ has "$.types[3].function_pointer.generic_params[*].kind.lifetime" +//@ count "$.types[3].function_pointer.generic_params[*].kind.lifetime.outlives[*]" 0 +//@ count "$.types[3].function_pointer.sig.inputs[*]" 1 +//@ is "$.types[3].function_pointer.sig.inputs[*][1]" 1 +//@ is "$.types[3].function_pointer.sig.output" 1 pub type ForAll = for<'a> fn(&'a i32) -> &'a i32; diff --git a/tests/rustdoc-json/type/generic_default.rs b/tests/rustdoc-json/type/generic_default.rs index 26a232a1562b3..951b1e2b78954 100644 --- a/tests/rustdoc-json/type/generic_default.rs +++ b/tests/rustdoc-json/type/generic_default.rs @@ -7,7 +7,7 @@ pub enum Result { //@ set my_error = "$.index[?(@.name=='MyError')].id" pub struct MyError {} -//@ has "$.index[?(@.name=='MyResult')].inner.type_alias" +//@ has "$.index[?(@.name=='MyResult')].inner.type_alias" //@ count "$.index[?(@.name=='MyResult')].inner.type_alias.generics.where_predicates[*]" 0 //@ count "$.index[?(@.name=='MyResult')].inner.type_alias.generics.params[*]" 2 //@ is "$.index[?(@.name=='MyResult')].inner.type_alias.generics.params[0].name" \"T\" @@ -17,15 +17,19 @@ pub struct MyError {} //@ count "$.index[?(@.name=='MyResult')].inner.type_alias.generics.params[0].kind.type.bounds[*]" 0 //@ count "$.index[?(@.name=='MyResult')].inner.type_alias.generics.params[1].kind.type.bounds[*]" 0 //@ is "$.index[?(@.name=='MyResult')].inner.type_alias.generics.params[0].kind.type.default" null -//@ has "$.index[?(@.name=='MyResult')].inner.type_alias.generics.params[1].kind.type.default.resolved_path" -//@ is "$.index[?(@.name=='MyResult')].inner.type_alias.generics.params[1].kind.type.default.resolved_path.id" $my_error -//@ is "$.index[?(@.name=='MyResult')].inner.type_alias.generics.params[1].kind.type.default.resolved_path.path" \"MyError\" -//@ has "$.index[?(@.name=='MyResult')].inner.type_alias.type.resolved_path" -//@ is "$.index[?(@.name=='MyResult')].inner.type_alias.type.resolved_path.id" $result -//@ is "$.index[?(@.name=='MyResult')].inner.type_alias.type.resolved_path.path" \"Result\" -//@ is "$.index[?(@.name=='MyResult')].inner.type_alias.type.resolved_path.args.angle_bracketed.constraints" [] -//@ has "$.index[?(@.name=='MyResult')].inner.type_alias.type.resolved_path.args.angle_bracketed.args[0].type.generic" -//@ has "$.index[?(@.name=='MyResult')].inner.type_alias.type.resolved_path.args.angle_bracketed.args[1].type.generic" -//@ is "$.index[?(@.name=='MyResult')].inner.type_alias.type.resolved_path.args.angle_bracketed.args[0].type.generic" \"T\" -//@ is "$.index[?(@.name=='MyResult')].inner.type_alias.type.resolved_path.args.angle_bracketed.args[1].type.generic" \"E\" +//@ is "$.index[?(@.name=='MyResult')].inner.type_alias.generics.params[1].kind.type.default" 15 +//@ has "$.types[15].resolved_path" +//@ is "$.types[15].resolved_path.id" $my_error +//@ is "$.types[15].resolved_path.path" \"MyError\" +//@ is "$.index[?(@.name=='MyResult')].inner.type_alias.type" 2 +//@ has "$.types[2].resolved_path" +//@ is "$.types[2].resolved_path.id" $result +//@ is "$.types[2].resolved_path.path" \"Result\" +//@ is "$.types[2].resolved_path.args.angle_bracketed.constraints" [] +//@ is "$.types[2].resolved_path.args.angle_bracketed.args[0].type" 0 +//@ is "$.types[2].resolved_path.args.angle_bracketed.args[1].type" 1 +//@ has "$.types[0].generic" +//@ has "$.types[1].generic" +//@ is "$.types[0].generic" \"T\" +//@ is "$.types[1].generic" \"E\" pub type MyResult = Result; diff --git a/tests/rustdoc-json/type/hrtb.rs b/tests/rustdoc-json/type/hrtb.rs index 68b7a556a69a2..52acfa6152f6f 100644 --- a/tests/rustdoc-json/type/hrtb.rs +++ b/tests/rustdoc-json/type/hrtb.rs @@ -1,4 +1,5 @@ -//@ is "$.index[?(@.name=='genfn')].inner.function.generics.where_predicates[0].bound_predicate.type" '{"generic": "F"}' +//@ is "$.index[?(@.name=='genfn')].inner.function.generics.where_predicates[0].bound_predicate.type" 0 +//@ is "$.types[0].generic" '"F"' //@ is "$.index[?(@.name=='genfn')].inner.function.generics.where_predicates[0].bound_predicate.generic_params" '[{"kind": {"lifetime": {"outlives": []}},"name": "'\''a"},{"kind": {"lifetime": {"outlives": []}},"name": "'\''b"}]' pub fn genfn(f: F) where @@ -10,10 +11,12 @@ where //@ is "$.index[?(@.name=='dynfn')].inner.function.generics" '{"params": [], "where_predicates": []}' //@ is "$.index[?(@.name=='dynfn')].inner.function.generics" '{"params": [], "where_predicates": []}' -//@ is "$.index[?(@.name=='dynfn')].inner.function.sig.inputs[0][1].borrowed_ref.type.dyn_trait.lifetime" null -//@ count "$.index[?(@.name=='dynfn')].inner.function.sig.inputs[0][1].borrowed_ref.type.dyn_trait.traits[*]" 1 -//@ is "$.index[?(@.name=='dynfn')].inner.function.sig.inputs[0][1].borrowed_ref.type.dyn_trait.traits[0].generic_params" '[{"kind": {"lifetime": {"outlives": []}},"name": "'\''a"},{"kind": {"lifetime": {"outlives": []}},"name": "'\''b"}]' -//@ is "$.index[?(@.name=='dynfn')].inner.function.sig.inputs[0][1].borrowed_ref.type.dyn_trait.traits[0].trait.path" '"Fn"' +//@ is "$.index[?(@.name=='dynfn')].inner.function.sig.inputs[0][1]" 5 +//@ is "$.types[5].borrowed_ref.type" 4 +//@ is "$.types[4].dyn_trait.lifetime" null +//@ count "$.types[4].dyn_trait.traits[*]" 1 +//@ is "$.types[4].dyn_trait.traits[0].generic_params" '[{"kind": {"lifetime": {"outlives": []}},"name": "'\''a"},{"kind": {"lifetime": {"outlives": []}},"name": "'\''b"}]' +//@ is "$.types[4].dyn_trait.traits[0].trait.path" '"Fn"' pub fn dynfn(f: &dyn for<'a, 'b> Fn(&'a i32, &'b i32)) { let zero = 0; f(&zero, &zero); diff --git a/tests/rustdoc-json/type/inherent_associated_type.rs b/tests/rustdoc-json/type/inherent_associated_type.rs index e96a92f7cfb4b..f3b746c41f199 100644 --- a/tests/rustdoc-json/type/inherent_associated_type.rs +++ b/tests/rustdoc-json/type/inherent_associated_type.rs @@ -9,9 +9,11 @@ pub struct Owner; pub fn create() -> Owner::Metadata { OwnerMetadata } -//@ is '$.index[?(@.name=="create")].inner.function.sig.output.qualified_path.name' '"Metadata"' -//@ is '$.index[?(@.name=="create")].inner.function.sig.output.qualified_path.trait' null -//@ is '$.index[?(@.name=="create")].inner.function.sig.output.qualified_path.self_type.resolved_path.id' $Owner +//@ is '$.index[?(@.name=="create")].inner.function.sig.output' 15 +//@ is '$.types[15].qualified_path.name' '"Metadata"' +//@ is '$.types[15].qualified_path.trait' null +//@ is '$.types[15].qualified_path.self_type' 14 +//@ is '$.types[14].resolved_path.id' $Owner /// impl impl Owner { @@ -20,4 +22,5 @@ impl Owner { } //@ set iat = '$.index[?(@.docs=="iat")].id' //@ is '$.index[?(@.docs=="impl")].inner.impl.items[*]' $iat -//@ is '$.index[?(@.docs=="iat")].inner.assoc_type.type.resolved_path.id' $OwnerMetadata +//@ is '$.index[?(@.docs=="iat")].inner.assoc_type.type' 0 +//@ is '$.types[0].resolved_path.id' $OwnerMetadata diff --git a/tests/rustdoc-json/type/inherent_associated_type_bound.rs b/tests/rustdoc-json/type/inherent_associated_type_bound.rs index 20354909f8ec2..f59d08559a14a 100644 --- a/tests/rustdoc-json/type/inherent_associated_type_bound.rs +++ b/tests/rustdoc-json/type/inherent_associated_type_bound.rs @@ -6,12 +6,16 @@ pub struct Carrier<'a>(&'a ()); //@ count "$.index[?(@.name=='user')].inner.function.sig.inputs[*]" 1 //@ is "$.index[?(@.name=='user')].inner.function.sig.inputs[0][0]" '"_"' -//@ is '$.index[?(@.name=="user")].inner.function.sig.inputs[0][1].function_pointer.generic_params[*].name' \""'b"\" -//@ is '$.index[?(@.name=="user")].inner.function.sig.inputs[0][1].function_pointer.sig.inputs[0][1].qualified_path.self_type.resolved_path.id' $Carrier -//@ is '$.index[?(@.name=="user")].inner.function.sig.inputs[0][1].function_pointer.sig.inputs[0][1].qualified_path.self_type.resolved_path.args.angle_bracketed.args[0].lifetime' \""'b"\" -//@ is '$.index[?(@.name=="user")].inner.function.sig.inputs[0][1].function_pointer.sig.inputs[0][1].qualified_path.name' '"Focus"' -//@ is '$.index[?(@.name=="user")].inner.function.sig.inputs[0][1].function_pointer.sig.inputs[0][1].qualified_path.trait' null -//@ is '$.index[?(@.name=="user")].inner.function.sig.inputs[0][1].function_pointer.sig.inputs[0][1].qualified_path.args.angle_bracketed.args[0].type.primitive' '"i32"' +//@ is '$.index[?(@.name=="user")].inner.function.sig.inputs[0][1]' 18 +//@ is '$.types[18].function_pointer.generic_params[*].name' \""'b"\" +//@ is '$.types[18].function_pointer.sig.inputs[0][1]' 17 +//@ is '$.types[17].qualified_path.self_type' 16 +//@ is '$.types[16].resolved_path.id' $Carrier +//@ is '$.types[16].resolved_path.args.angle_bracketed.args[0].lifetime' \""'b"\" +//@ is '$.types[17].qualified_path.name' '"Focus"' +//@ is '$.types[17].qualified_path.trait' null +//@ is '$.types[17].qualified_path.args.angle_bracketed.args[0].type' 15 +//@ is '$.types[15].primitive' '"i32"' pub fn user(_: for<'b> fn(Carrier<'b>::Focus)) {} impl<'a> Carrier<'a> { diff --git a/tests/rustdoc-json/type/inherent_associated_type_projections.rs b/tests/rustdoc-json/type/inherent_associated_type_projections.rs index 934daba11bb1f..21136193ece62 100644 --- a/tests/rustdoc-json/type/inherent_associated_type_projections.rs +++ b/tests/rustdoc-json/type/inherent_associated_type_projections.rs @@ -6,10 +6,13 @@ pub struct Parametrized(T); //@ count "$.index[?(@.name=='test')].inner.function.sig.inputs[*]" 1 //@ is "$.index[?(@.name=='test')].inner.function.sig.inputs[0][0]" '"_"' -//@ is '$.index[?(@.name=="test")].inner.function.sig.inputs[0][1].qualified_path.self_type.resolved_path.id' $Parametrized -//@ is '$.index[?(@.name=="test")].inner.function.sig.inputs[0][1].qualified_path.self_type.resolved_path.args.angle_bracketed.args[0].type.primitive' \"i32\" -//@ is '$.index[?(@.name=="test")].inner.function.sig.inputs[0][1].qualified_path.name' '"Proj"' -//@ is '$.index[?(@.name=="test")].inner.function.sig.inputs[0][1].qualified_path.trait' null +//@ is '$.index[?(@.name=="test")].inner.function.sig.inputs[0][1]' 20 +//@ is '$.types[20].qualified_path.self_type' 5 +//@ is '$.types[5].resolved_path.id' $Parametrized +//@ is '$.types[5].resolved_path.args.angle_bracketed.args[0].type' 4 +//@ is '$.types[4].primitive' \"i32\" +//@ is '$.types[20].qualified_path.name' '"Proj"' +//@ is '$.types[20].qualified_path.trait' null pub fn test(_: Parametrized::Proj) {} /// param_bool diff --git a/tests/rustdoc-json/type_alias.rs b/tests/rustdoc-json/type_alias.rs index 7fd23a48040d1..8255cf14109a1 100644 --- a/tests/rustdoc-json/type_alias.rs +++ b/tests/rustdoc-json/type_alias.rs @@ -4,12 +4,14 @@ //@ is "$.index[?(@.name=='IntVec')].span.filename" $FILE pub type IntVec = Vec; -//@ is "$.index[?(@.name=='f')].inner.function.sig.output.resolved_path.id" $IntVec +//@ is "$.index[?(@.name=='f')].inner.function.sig.output" 2 +//@ is "$.types[2].resolved_path.id" $IntVec pub fn f() -> IntVec { vec![0; 32] } -//@ !is "$.index[?(@.name=='g')].inner.function.sig.output.resolved_path.id" $IntVec +//@ is "$.index[?(@.name=='g')].inner.function.sig.output" 1 +//@ !is "$.types[1].resolved_path.id" $IntVec pub fn g() -> Vec { vec![0; 32] } diff --git a/tests/rustdoc-json/unions/union.rs b/tests/rustdoc-json/unions/union.rs index 24ee47f195730..8c911238e0d06 100644 --- a/tests/rustdoc-json/unions/union.rs +++ b/tests/rustdoc-json/unions/union.rs @@ -1,14 +1,15 @@ //@ has "$.index[?(@.name=='Union')].visibility" \"public\" //@ has "$.index[?(@.name=='Union')].inner.union" -//@ !has "$.index[?(@.name=='Union')].inner.union.struct_type" +//@ !has "$.index[?(@.name=='Union')].inner.union.kind" //@ set Union = "$.index[?(@.name=='Union')].id" pub union Union { int: i32, float: f32, } -//@ has "$.index[?(@.name=='make_int_union')].inner.function.sig.output.resolved_path" -//@ is "$.index[?(@.name=='make_int_union')].inner.function.sig.output.resolved_path.id" $Union +//@ is "$.index[?(@.name=='make_int_union')].inner.function.sig.output" 0 +//@ has "$.types[0].resolved_path" +//@ is "$.types[0].resolved_path.id" $Union pub fn make_int_union(int: i32) -> Union { Union { int } }