Skip to content

Commit 996de3a

Browse files
authored
Rollup merge of #104879 - aDotInTheVoid:jsondoclint-typedef, r=GuillaumeGomez
jsondoclint: Recognise Typedef as valid kind for Type::ResolvedPath Closes #104851 r? ``@GuillaumeGomez`` ``@rustbot`` modify labels: +A-testsuite
2 parents 287bb6d + eac8921 commit 996de3a

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/104851>
2+
3+
/// @set foo = "$.index[*][?(@.name=='Foo')].id"
4+
pub type Foo = i32;
5+
6+
// @is "$.index[*][?(@.name=='demo')].inner.decl.output.kind" '"resolved_path"'
7+
// @is "$.index[*][?(@.name=='demo')].inner.decl.output.inner.id" $foo
8+
pub fn demo() -> Foo {
9+
42
10+
}

src/tools/jsondoclint/src/item_kind.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ impl Kind {
114114
pub fn is_trait(self) -> bool {
115115
matches!(self, Kind::Trait)
116116
}
117-
pub fn is_struct_enum_union(self) -> bool {
118-
matches!(self, Kind::Struct | Kind::Enum | Kind::Union)
117+
pub fn is_type(self) -> bool {
118+
matches!(self, Kind::Struct | Kind::Enum | Kind::Union | Kind::Typedef)
119119
}
120120

121121
pub fn from_item(i: &Item) -> Self {

src/tools/jsondoclint/src/validator.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ pub struct Validator<'a> {
3232

3333
enum PathKind {
3434
Trait,
35-
StructEnumUnion,
35+
/// Structs, Enums, Unions and Typedefs.
36+
///
37+
/// This doesn't include trait's because traits are not types.
38+
Type,
3639
}
3740

3841
impl<'a> Validator<'a> {
@@ -224,7 +227,7 @@ impl<'a> Validator<'a> {
224227

225228
fn check_type(&mut self, x: &'a Type) {
226229
match x {
227-
Type::ResolvedPath(path) => self.check_path(path, PathKind::StructEnumUnion),
230+
Type::ResolvedPath(path) => self.check_path(path, PathKind::Type),
228231
Type::DynTrait(dyn_trait) => self.check_dyn_trait(dyn_trait),
229232
Type::Generic(_) => {}
230233
Type::Primitive(_) => {}
@@ -264,7 +267,7 @@ impl<'a> Validator<'a> {
264267
fn check_path(&mut self, x: &'a Path, kind: PathKind) {
265268
match kind {
266269
PathKind::Trait => self.add_trait_id(&x.id),
267-
PathKind::StructEnumUnion => self.add_struct_enum_union_id(&x.id),
270+
PathKind::Type => self.add_type_id(&x.id),
268271
}
269272
if let Some(args) = &x.args {
270273
self.check_generic_args(&**args);
@@ -392,8 +395,8 @@ impl<'a> Validator<'a> {
392395
self.add_id_checked(id, Kind::is_trait, "Trait");
393396
}
394397

395-
fn add_struct_enum_union_id(&mut self, id: &'a Id) {
396-
self.add_id_checked(id, Kind::is_struct_enum_union, "Struct or Enum or Union");
398+
fn add_type_id(&mut self, id: &'a Id) {
399+
self.add_id_checked(id, Kind::is_type, "Type (Struct, Enum, Union or Typedef)");
397400
}
398401

399402
/// Add an Id that appeared in a trait

0 commit comments

Comments
 (0)