From 5db3b54315c79aee5022fcc44a8b42132835c990 Mon Sep 17 00:00:00 2001 From: Fluid <90795031+fluiderson@users.noreply.github.com> Date: Wed, 25 Jun 2025 05:08:33 +0300 Subject: [PATCH 01/21] update the edition --- src/tools/jsondocck/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/jsondocck/Cargo.toml b/src/tools/jsondocck/Cargo.toml index 80fc26cbe6680..f2ae68f7fbd69 100644 --- a/src/tools/jsondocck/Cargo.toml +++ b/src/tools/jsondocck/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "jsondocck" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] jsonpath-rust = "1.0.0" From 2dc143f9fce3dfa2d62c78159225977c5f71e65a Mon Sep 17 00:00:00 2001 From: Fluid <90795031+fluiderson@users.noreply.github.com> Date: Wed, 25 Jun 2025 05:18:59 +0300 Subject: [PATCH 02/21] remove the version field it's unnecessary for private crates --- Cargo.lock | 2 +- src/tools/jsondocck/Cargo.toml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7e798d6d26144..154a622dca77a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1977,7 +1977,7 @@ dependencies = [ [[package]] name = "jsondocck" -version = "0.1.0" +version = "0.0.0" dependencies = [ "fs-err", "getopts", diff --git a/src/tools/jsondocck/Cargo.toml b/src/tools/jsondocck/Cargo.toml index f2ae68f7fbd69..fb4ab32f6793b 100644 --- a/src/tools/jsondocck/Cargo.toml +++ b/src/tools/jsondocck/Cargo.toml @@ -1,6 +1,5 @@ [package] name = "jsondocck" -version = "0.1.0" edition = "2024" [dependencies] From 184b7f4d4cfc3f2f170065da9e2f05d2d42d9650 Mon Sep 17 00:00:00 2001 From: Fluid <90795031+fluiderson@users.noreply.github.com> Date: Wed, 25 Jun 2025 05:36:27 +0300 Subject: [PATCH 03/21] remove an unused variable the deleted lines are duplicates of the lines 36 & 37 --- src/tools/compiletest/src/runtest/rustdoc_json.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tools/compiletest/src/runtest/rustdoc_json.rs b/src/tools/compiletest/src/runtest/rustdoc_json.rs index 9f88faca89268..71919f08df56c 100644 --- a/src/tools/compiletest/src/runtest/rustdoc_json.rs +++ b/src/tools/compiletest/src/runtest/rustdoc_json.rs @@ -18,8 +18,6 @@ impl TestCx<'_> { self.fatal_proc_rec("rustdoc failed!", &proc_res); } - let mut json_out = out_dir.join(self.testpaths.file.file_stem().unwrap()); - json_out.set_extension("json"); let res = self.run_command_to_procres( Command::new(self.config.jsondocck_path.as_ref().unwrap()) .arg("--doc-dir") From 5c9f239f75138eef5bf773d51616486f6356ad01 Mon Sep 17 00:00:00 2001 From: Fluid <90795031+fluiderson@users.noreply.github.com> Date: Wed, 25 Jun 2025 05:40:52 +0300 Subject: [PATCH 04/21] appease clippy --- src/tools/compiletest/src/runtest/rustdoc_json.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/compiletest/src/runtest/rustdoc_json.rs b/src/tools/compiletest/src/runtest/rustdoc_json.rs index 71919f08df56c..3d6baaee377c0 100644 --- a/src/tools/compiletest/src/runtest/rustdoc_json.rs +++ b/src/tools/compiletest/src/runtest/rustdoc_json.rs @@ -13,7 +13,7 @@ impl TestCx<'_> { panic!("failed to remove and recreate output directory `{out_dir}`: {e}") }); - let proc_res = self.document(&out_dir, &self.testpaths); + let proc_res = self.document(&out_dir, self.testpaths); if !proc_res.status.success() { self.fatal_proc_rec("rustdoc failed!", &proc_res); } From 30aa6c7dd738306a8abc1aabbbe3188cde2b6cef Mon Sep 17 00:00:00 2001 From: Fluid <90795031+fluiderson@users.noreply.github.com> Date: Wed, 25 Jun 2025 06:29:43 +0300 Subject: [PATCH 05/21] unify message style --- src/tools/jsondocck/src/config.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/tools/jsondocck/src/config.rs b/src/tools/jsondocck/src/config.rs index 6bef37c225973..4492fb25f918f 100644 --- a/src/tools/jsondocck/src/config.rs +++ b/src/tools/jsondocck/src/config.rs @@ -2,18 +2,18 @@ use getopts::Options; #[derive(Debug)] pub struct Config { - /// The directory documentation output was generated in + /// The directory documentation output was generated in. pub doc_dir: String, - /// The file documentation was generated for, with docck directives to check + /// The file documentation was generated for, with docck directives to check. pub template: String, } -/// Create a Config from a vector of command-line arguments +/// Create a Config from a vector of command-line arguments. pub fn parse_config(args: Vec) -> Config { let mut opts = Options::new(); - opts.reqopt("", "doc-dir", "Path to the documentation directory", "PATH") - .reqopt("", "template", "Path to the template file", "PATH") - .optflag("h", "help", "show this message"); + opts.reqopt("", "doc-dir", "Path to the documentation directory.", "PATH") + .reqopt("", "template", "Path to the template file.", "PATH") + .optflag("h", "help", "Show this message."); let (argv0, args_) = args.split_first().unwrap(); if args.len() == 1 { From 2d334e45ebe7f45420c29ad7adf6784ebdc5ed63 Mon Sep 17 00:00:00 2001 From: Fluid <90795031+fluiderson@users.noreply.github.com> Date: Wed, 25 Jun 2025 06:31:19 +0300 Subject: [PATCH 06/21] add "input"/"output" to make it more clear what's what --- src/tools/jsondocck/src/config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/jsondocck/src/config.rs b/src/tools/jsondocck/src/config.rs index 4492fb25f918f..379cba39ff59e 100644 --- a/src/tools/jsondocck/src/config.rs +++ b/src/tools/jsondocck/src/config.rs @@ -11,8 +11,8 @@ pub struct Config { /// Create a Config from a vector of command-line arguments. pub fn parse_config(args: Vec) -> Config { let mut opts = Options::new(); - opts.reqopt("", "doc-dir", "Path to the documentation directory.", "PATH") - .reqopt("", "template", "Path to the template file.", "PATH") + opts.reqopt("", "doc-dir", "Path to the documentation output directory.", "PATH") + .reqopt("", "template", "Path to the input template file.", "PATH") .optflag("h", "help", "Show this message."); let (argv0, args_) = args.split_first().unwrap(); From 816887a513f39a30543988eb794d62ff11745f75 Mon Sep 17 00:00:00 2001 From: Fluid <90795031+fluiderson@users.noreply.github.com> Date: Wed, 25 Jun 2025 06:41:40 +0300 Subject: [PATCH 07/21] unify message style --- src/tools/jsondocck/src/config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/jsondocck/src/config.rs b/src/tools/jsondocck/src/config.rs index 379cba39ff59e..064bab95fafab 100644 --- a/src/tools/jsondocck/src/config.rs +++ b/src/tools/jsondocck/src/config.rs @@ -4,11 +4,11 @@ use getopts::Options; pub struct Config { /// The directory documentation output was generated in. pub doc_dir: String, - /// The file documentation was generated for, with docck directives to check. + /// The file documentation was generated for, with `jsondocck` directives to check. pub template: String, } -/// Create a Config from a vector of command-line arguments. +/// Create [`Config`] from a vector of command-line arguments. pub fn parse_config(args: Vec) -> Config { let mut opts = Options::new(); opts.reqopt("", "doc-dir", "Path to the documentation output directory.", "PATH") From 2aa7015511bdb7487ae9061993f9cc088becd9df Mon Sep 17 00:00:00 2001 From: Fluid <90795031+fluiderson@users.noreply.github.com> Date: Wed, 25 Jun 2025 07:28:22 +0300 Subject: [PATCH 08/21] optimize the config parsing --- src/tools/jsondocck/src/config.rs | 31 ++++++++++++++++++------------- src/tools/jsondocck/src/main.rs | 4 +++- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/tools/jsondocck/src/config.rs b/src/tools/jsondocck/src/config.rs index 064bab95fafab..7fe33b1565e8d 100644 --- a/src/tools/jsondocck/src/config.rs +++ b/src/tools/jsondocck/src/config.rs @@ -1,3 +1,6 @@ +use std::cell::LazyCell; +use std::env::Args; + use getopts::Options; #[derive(Debug)] @@ -8,30 +11,32 @@ pub struct Config { pub template: String, } -/// Create [`Config`] from a vector of command-line arguments. -pub fn parse_config(args: Vec) -> Config { +/// Create [`Config`] from an iterator of command-line arguments. +pub fn parse_config(mut args: Args) -> Option { let mut opts = Options::new(); opts.reqopt("", "doc-dir", "Path to the documentation output directory.", "PATH") .reqopt("", "template", "Path to the input template file.", "PATH") .optflag("h", "help", "Show this message."); - let (argv0, args_) = args.split_first().unwrap(); - if args.len() == 1 { - let message = format!("Usage: {}