Skip to content

Commit 95e6356

Browse files
Rollup merge of #104943 - aDotInTheVoid:jsondoclint-use-enum, r=GuillaumeGomez
jsondoclint: Handle using enum variants and glob using enums. More work on jsondoclint for `core.json` Closes #104942 r? `@GuillaumeGomez` `@rustbot` modify labels: +A-testsuite
2 parents d99201c + ed0f097 commit 95e6356

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/104942>
2+
3+
#![feature(no_core)]
4+
#![no_core]
5+
6+
// @set Color = "$.index[*][?(@.name == 'Color')].id"
7+
pub enum Color {
8+
Red,
9+
Green,
10+
Blue,
11+
}
12+
13+
// @set use_Color = "$.index[*][?(@.kind == 'import')].id"
14+
// @is "$.index[*][?(@.kind == 'import')].inner.id" $Color
15+
// @is "$.index[*][?(@.kind == 'import')].inner.glob" true
16+
pub use Color::*;
17+
18+
// @ismany "$.index[*][?(@.name == 'use_glob')].inner.items[*]" $Color $use_Color
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(no_core)]
2+
#![no_core]
3+
4+
// @set AlwaysNone = "$.index[*][?(@.name == 'AlwaysNone')].id"
5+
pub enum AlwaysNone {
6+
// @set None = "$.index[*][?(@.name == 'None')].id"
7+
None,
8+
}
9+
// @is "$.index[*][?(@.name == 'AlwaysNone')].inner.variants[*]" $None
10+
11+
// @set use_None = "$.index[*][?(@.kind == 'import')].id"
12+
// @is "$.index[*][?(@.kind == 'import')].inner.id" $None
13+
pub use AlwaysNone::None;
14+
15+
// @ismany "$.index[*][?(@.name == 'use_variant')].inner.items[*]" $AlwaysNone $use_None

src/tools/jsondoclint/src/item_kind.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustdoc_json_types::{Item, ItemEnum, ItemKind, ItemSummary};
22

33
/// A univeral way to represent an [`ItemEnum`] or [`ItemKind`]
4-
#[derive(Debug)]
4+
#[derive(Debug, Clone, Copy)]
55
pub(crate) enum Kind {
66
Module,
77
ExternCrate,
@@ -68,6 +68,22 @@ impl Kind {
6868
}
6969
}
7070

71+
pub fn can_appear_in_import(self) -> bool {
72+
match self {
73+
Kind::Variant => true,
74+
Kind::Import => false,
75+
other => other.can_appear_in_mod(),
76+
}
77+
}
78+
79+
pub fn can_appear_in_glob_import(self) -> bool {
80+
match self {
81+
Kind::Module => true,
82+
Kind::Enum => true,
83+
_ => false,
84+
}
85+
}
86+
7187
pub fn can_appear_in_trait(self) -> bool {
7288
match self {
7389
Kind::AssocConst => true,

src/tools/jsondoclint/src/validator.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ impl<'a> Validator<'a> {
103103

104104
fn check_import(&mut self, x: &'a Import) {
105105
if x.glob {
106-
self.add_mod_id(x.id.as_ref().unwrap());
106+
self.add_glob_import_item_id(x.id.as_ref().unwrap());
107107
} else if let Some(id) = &x.id {
108-
self.add_mod_item_id(id);
108+
self.add_import_item_id(id);
109109
}
110110
}
111111

@@ -404,6 +404,15 @@ impl<'a> Validator<'a> {
404404
self.add_id_checked(id, Kind::can_appear_in_trait, "Trait inner item");
405405
}
406406

407+
/// Add an Id that can be `use`d
408+
fn add_import_item_id(&mut self, id: &'a Id) {
409+
self.add_id_checked(id, Kind::can_appear_in_import, "Import inner item");
410+
}
411+
412+
fn add_glob_import_item_id(&mut self, id: &'a Id) {
413+
self.add_id_checked(id, Kind::can_appear_in_glob_import, "Glob import inner item");
414+
}
415+
407416
/// Add an Id that appeared in a mod
408417
fn add_mod_item_id(&mut self, id: &'a Id) {
409418
self.add_id_checked(id, Kind::can_appear_in_mod, "Module inner item")

0 commit comments

Comments
 (0)