From eac8921ccffa45f39f8b0826882ad8c705184079 Mon Sep 17 00:00:00 2001 From: Nixon Enraght-Moony Date: Fri, 25 Nov 2022 10:53:14 +0000 Subject: [PATCH] jsondoclint: Recognise Typedef as valid kind for Type::ResolvedPath Closes #104851 --- src/test/rustdoc-json/fns/return_type_alias.rs | 10 ++++++++++ src/tools/jsondoclint/src/item_kind.rs | 4 ++-- src/tools/jsondoclint/src/validator.rs | 13 ++++++++----- 3 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 src/test/rustdoc-json/fns/return_type_alias.rs diff --git a/src/test/rustdoc-json/fns/return_type_alias.rs b/src/test/rustdoc-json/fns/return_type_alias.rs new file mode 100644 index 00000000000..2578bb49ad3 --- /dev/null +++ b/src/test/rustdoc-json/fns/return_type_alias.rs @@ -0,0 +1,10 @@ +// Regression test for + +/// @set foo = "$.index[*][?(@.name=='Foo')].id" +pub type Foo = i32; + +// @is "$.index[*][?(@.name=='demo')].inner.decl.output.kind" '"resolved_path"' +// @is "$.index[*][?(@.name=='demo')].inner.decl.output.inner.id" $foo +pub fn demo() -> Foo { + 42 +} diff --git a/src/tools/jsondoclint/src/item_kind.rs b/src/tools/jsondoclint/src/item_kind.rs index 225651a997e..a533e367122 100644 --- a/src/tools/jsondoclint/src/item_kind.rs +++ b/src/tools/jsondoclint/src/item_kind.rs @@ -114,8 +114,8 @@ pub fn is_variant(self) -> bool { pub fn is_trait(self) -> bool { matches!(self, Kind::Trait) } - pub fn is_struct_enum_union(self) -> bool { - matches!(self, Kind::Struct | Kind::Enum | Kind::Union) + pub fn is_type(self) -> bool { + matches!(self, Kind::Struct | Kind::Enum | Kind::Union | Kind::Typedef) } pub fn from_item(i: &Item) -> Self { diff --git a/src/tools/jsondoclint/src/validator.rs b/src/tools/jsondoclint/src/validator.rs index 5b293a3c4f7..9548276d826 100644 --- a/src/tools/jsondoclint/src/validator.rs +++ b/src/tools/jsondoclint/src/validator.rs @@ -32,7 +32,10 @@ pub struct Validator<'a> { enum PathKind { Trait, - StructEnumUnion, + /// Structs, Enums, Unions and Typedefs. + /// + /// This doesn't include trait's because traits are not types. + Type, } impl<'a> Validator<'a> { @@ -224,7 +227,7 @@ fn check_generics(&mut self, x: &'a Generics) { fn check_type(&mut self, x: &'a Type) { match x { - Type::ResolvedPath(path) => self.check_path(path, PathKind::StructEnumUnion), + Type::ResolvedPath(path) => self.check_path(path, PathKind::Type), Type::DynTrait(dyn_trait) => self.check_dyn_trait(dyn_trait), Type::Generic(_) => {} Type::Primitive(_) => {} @@ -264,7 +267,7 @@ fn check_generic_bound(&mut self, x: &'a GenericBound) { fn check_path(&mut self, x: &'a Path, kind: PathKind) { match kind { PathKind::Trait => self.add_trait_id(&x.id), - PathKind::StructEnumUnion => self.add_struct_enum_union_id(&x.id), + PathKind::Type => self.add_type_id(&x.id), } if let Some(args) = &x.args { self.check_generic_args(&**args); @@ -392,8 +395,8 @@ fn add_trait_id(&mut self, id: &'a Id) { self.add_id_checked(id, Kind::is_trait, "Trait"); } - fn add_struct_enum_union_id(&mut self, id: &'a Id) { - self.add_id_checked(id, Kind::is_struct_enum_union, "Struct or Enum or Union"); + fn add_type_id(&mut self, id: &'a Id) { + self.add_id_checked(id, Kind::is_type, "Type (Struct, Enum, Union or Typedef)"); } /// Add an Id that appeared in a trait