Skip to content

Commit a581bb7

Browse files
authored
Rollup merge of rust-lang#101809 - aDotInTheVoid:jsondoclint, r=GuillaumeGomez
Replace `check_missing_items.py` with `jsondoclint` [zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/check_missing_items.2Epy.20Replacement.2E) check_missing_items.py was a python script that checked rustdoc json output to make sure all the Id's referenced existed in the JSON index. This PR replaces that with a rust binary (`jsondoclint`) that does the same thing. ### Motivation 1. Easier to change when `rustdoc-json-types` changes, as `jsondoclint` uses the types directly. 2. Better Errors: - Multiple Errors can be emited for a single crate - Errors can say where in JSON they occored ``` 2:2889:408 not in index or paths, but refered to at '.index."2:2888:104".inner.items[0]' 2:2890:410 not in index or paths, but refered to at '.index."2:2888:104".inner.items[1]' ``` 3. Catches more bugs. - Because matches are exaustive, all posible variants considered for enums - All Id's checked - Has already found rust-lang#101770, rust-lang#101199 and rust-lang#100973 - Id type is also checked, so the Id's in a structs fields can only be field items. 4. Allows the possibility of running from `rustdoc::json`, which we should do in a crator run at some point. cc `@CraftSpider` r? `@GuillaumeGomez`
2 parents 6e23b26 + f69a6c2 commit a581bb7

File tree

15 files changed

+816
-214
lines changed

15 files changed

+816
-214
lines changed

Cargo.lock

+16-6
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ dependencies = [
103103

104104
[[package]]
105105
name = "anyhow"
106-
version = "1.0.60"
106+
version = "1.0.65"
107107
source = "registry+https://github.com/rust-lang/crates.io-index"
108-
checksum = "c794e162a5eff65c72ef524dfe393eb923c354e350bb78b9c7383df13f3bc142"
108+
checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602"
109109

110110
[[package]]
111111
name = "array_tool"
@@ -1362,9 +1362,9 @@ dependencies = [
13621362

13631363
[[package]]
13641364
name = "fs-err"
1365-
version = "2.5.0"
1365+
version = "2.8.1"
13661366
source = "registry+https://github.com/rust-lang/crates.io-index"
1367-
checksum = "bcd1163ae48bda72a20ae26d66a04d3094135cadab911cff418ae5e33f253431"
1367+
checksum = "64db3e262960f0662f43a6366788d5f10f7f244b8f7d7d987f560baf5ded5c50"
13681368

13691369
[[package]]
13701370
name = "fs_extra"
@@ -1891,6 +1891,16 @@ dependencies = [
18911891
"shlex",
18921892
]
18931893

1894+
[[package]]
1895+
name = "jsondoclint"
1896+
version = "0.1.0"
1897+
dependencies = [
1898+
"anyhow",
1899+
"fs-err",
1900+
"rustdoc-json-types",
1901+
"serde_json",
1902+
]
1903+
18941904
[[package]]
18951905
name = "jsonpath_lib"
18961906
version = "0.2.6"
@@ -4445,9 +4455,9 @@ dependencies = [
44454455

44464456
[[package]]
44474457
name = "serde_json"
4448-
version = "1.0.83"
4458+
version = "1.0.85"
44494459
source = "registry+https://github.com/rust-lang/crates.io-index"
4450-
checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7"
4460+
checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44"
44514461
dependencies = [
44524462
"indexmap",
44534463
"itoa",

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ members = [
3333
"src/tools/unicode-table-generator",
3434
"src/tools/expand-yaml-anchors",
3535
"src/tools/jsondocck",
36+
"src/tools/jsondoclint",
3637
"src/tools/html-checker",
3738
"src/tools/bump-stage0",
3839
"src/tools/replace-version-placeholder",

src/bootstrap/test.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,8 @@ note: if you're sure you want to do this, please open an issue as to why. In the
13411341
let json_compiler = compiler.with_stage(0);
13421342
cmd.arg("--jsondocck-path")
13431343
.arg(builder.ensure(tool::JsonDocCk { compiler: json_compiler, target }));
1344+
cmd.arg("--jsondoclint-path")
1345+
.arg(builder.ensure(tool::JsonDocLint { compiler: json_compiler, target }));
13441346
}
13451347

13461348
if mode == "run-make" {

src/bootstrap/tool.rs

+1
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ bootstrap_tool!(
376376
ExpandYamlAnchors, "src/tools/expand-yaml-anchors", "expand-yaml-anchors";
377377
LintDocs, "src/tools/lint-docs", "lint-docs";
378378
JsonDocCk, "src/tools/jsondocck", "jsondocck";
379+
JsonDocLint, "src/tools/jsondoclint", "jsondoclint";
379380
HtmlChecker, "src/tools/html-checker", "html-checker";
380381
BumpStage0, "src/tools/bump-stage0", "bump-stage0";
381382
ReplaceVersionPlaceholder, "src/tools/replace-version-placeholder", "replace-version-placeholder";

src/etc/check_missing_items.py

-202
This file was deleted.

src/test/rustdoc-json/type/extern.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(extern_types)]
2+
3+
extern {
4+
/// No inner information
5+
pub type Foo;
6+
}
7+
8+
// @is "$.index[*][?(@.docs=='No inner information')].name" '"Foo"'
9+
// @is "$.index[*][?(@.docs=='No inner information')].kind" '"foreign_type"'
10+
// @!has "$.index[*][?(@.docs=='No inner information')].inner"

src/tools/compiletest/src/common.rs

+3
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ pub struct Config {
203203
/// The jsondocck executable.
204204
pub jsondocck_path: Option<String>,
205205

206+
/// The jsondoclint executable.
207+
pub jsondoclint_path: Option<String>,
208+
206209
/// The LLVM `FileCheck` binary path.
207210
pub llvm_filecheck: Option<PathBuf>,
208211

src/tools/compiletest/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
6464
.optopt("", "rust-demangler-path", "path to rust-demangler to use in tests", "PATH")
6565
.reqopt("", "python", "path to python to use for doc tests", "PATH")
6666
.optopt("", "jsondocck-path", "path to jsondocck to use for doc tests", "PATH")
67+
.optopt("", "jsondoclint-path", "path to jsondoclint to use for doc tests", "PATH")
6768
.optopt("", "valgrind-path", "path to Valgrind executable for Valgrind tests", "PROGRAM")
6869
.optflag("", "force-valgrind", "fail if Valgrind tests cannot be run under Valgrind")
6970
.optopt("", "run-clang-based-tests-with", "path to Clang executable", "PATH")
@@ -226,6 +227,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
226227
rust_demangler_path: matches.opt_str("rust-demangler-path").map(PathBuf::from),
227228
python: matches.opt_str("python").unwrap(),
228229
jsondocck_path: matches.opt_str("jsondocck-path"),
230+
jsondoclint_path: matches.opt_str("jsondoclint-path"),
229231
valgrind_path: matches.opt_str("valgrind-path"),
230232
force_valgrind: matches.opt_present("force-valgrind"),
231233
run_clang_based_tests_with: matches.opt_str("run-clang-based-tests-with"),

src/tools/compiletest/src/runtest.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -2563,14 +2563,13 @@ impl<'test> TestCx<'test> {
25632563

25642564
let mut json_out = out_dir.join(self.testpaths.file.file_stem().unwrap());
25652565
json_out.set_extension("json");
2566+
25662567
let res = self.cmd2procres(
2567-
Command::new(&self.config.python)
2568-
.arg(root.join("src/etc/check_missing_items.py"))
2569-
.arg(&json_out),
2568+
Command::new(self.config.jsondoclint_path.as_ref().unwrap()).arg(&json_out),
25702569
);
25712570

25722571
if !res.status.success() {
2573-
self.fatal_proc_rec("check_missing_items failed!", &res);
2572+
self.fatal_proc_rec("jsondoclint failed!", &res);
25742573
}
25752574
}
25762575

src/tools/jsondoclint/Cargo.toml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "jsondoclint"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
anyhow = "1.0.62"
10+
fs-err = "2.8.1"
11+
rustdoc-json-types = { version = "0.1.0", path = "../../rustdoc-json-types" }
12+
serde_json = "1.0.85"

0 commit comments

Comments
 (0)