Skip to content

Commit

Permalink
jsondoclint: Recognise Typedef as valid kind for Type::ResolvedPath
Browse files Browse the repository at this point in the history
Closes #104851
  • Loading branch information
aDotInTheVoid committed Nov 25, 2022
1 parent 41e0363 commit eac8921
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/test/rustdoc-json/fns/return_type_alias.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Regression test for <https://github.com/rust-lang/rust/issues/104851>

/// @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
}
4 changes: 2 additions & 2 deletions src/tools/jsondoclint/src/item_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ impl Kind {
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 {
Expand Down
13 changes: 8 additions & 5 deletions src/tools/jsondoclint/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -224,7 +227,7 @@ impl<'a> Validator<'a> {

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(_) => {}
Expand Down Expand Up @@ -264,7 +267,7 @@ impl<'a> Validator<'a> {
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);
Expand Down Expand Up @@ -392,8 +395,8 @@ impl<'a> Validator<'a> {
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
Expand Down

0 comments on commit eac8921

Please sign in to comment.