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
This commit is contained in:
Guillaume Gomez 2022-11-26 17:47:26 +01:00 committed by GitHub
commit 95e63560a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 3 deletions

View File

@ -0,0 +1,18 @@
// Regression test for <https://github.com/rust-lang/rust/issues/104942>
#![feature(no_core)]
#![no_core]
// @set Color = "$.index[*][?(@.name == 'Color')].id"
pub enum Color {
Red,
Green,
Blue,
}
// @set use_Color = "$.index[*][?(@.kind == 'import')].id"
// @is "$.index[*][?(@.kind == 'import')].inner.id" $Color
// @is "$.index[*][?(@.kind == 'import')].inner.glob" true
pub use Color::*;
// @ismany "$.index[*][?(@.name == 'use_glob')].inner.items[*]" $Color $use_Color

View File

@ -0,0 +1,15 @@
#![feature(no_core)]
#![no_core]
// @set AlwaysNone = "$.index[*][?(@.name == 'AlwaysNone')].id"
pub enum AlwaysNone {
// @set None = "$.index[*][?(@.name == 'None')].id"
None,
}
// @is "$.index[*][?(@.name == 'AlwaysNone')].inner.variants[*]" $None
// @set use_None = "$.index[*][?(@.kind == 'import')].id"
// @is "$.index[*][?(@.kind == 'import')].inner.id" $None
pub use AlwaysNone::None;
// @ismany "$.index[*][?(@.name == 'use_variant')].inner.items[*]" $AlwaysNone $use_None

View File

@ -1,7 +1,7 @@
use rustdoc_json_types::{Item, ItemEnum, ItemKind, ItemSummary};
/// A univeral way to represent an [`ItemEnum`] or [`ItemKind`]
#[derive(Debug)]
#[derive(Debug, Clone, Copy)]
pub(crate) enum Kind {
Module,
ExternCrate,
@ -68,6 +68,22 @@ impl Kind {
}
}
pub fn can_appear_in_import(self) -> bool {
match self {
Kind::Variant => true,
Kind::Import => false,
other => other.can_appear_in_mod(),
}
}
pub fn can_appear_in_glob_import(self) -> bool {
match self {
Kind::Module => true,
Kind::Enum => true,
_ => false,
}
}
pub fn can_appear_in_trait(self) -> bool {
match self {
Kind::AssocConst => true,

View File

@ -103,9 +103,9 @@ impl<'a> Validator<'a> {
fn check_import(&mut self, x: &'a Import) {
if x.glob {
self.add_mod_id(x.id.as_ref().unwrap());
self.add_glob_import_item_id(x.id.as_ref().unwrap());
} else if let Some(id) = &x.id {
self.add_mod_item_id(id);
self.add_import_item_id(id);
}
}
@ -404,6 +404,15 @@ impl<'a> Validator<'a> {
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) {
self.add_id_checked(id, Kind::can_appear_in_import, "Import inner item");
}
fn add_glob_import_item_id(&mut self, id: &'a Id) {
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) {
self.add_id_checked(id, Kind::can_appear_in_mod, "Module inner item")