From 6f8586b40534138f5645e2d8946c3e4040f76251 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/22] 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 7d0d2e73d1c48d19de9ba236f87b1452e7ac3fef 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/22] 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 271a2f7962cac..7e5a2cad67965 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2044,7 +2044,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 b8bd10c5c8618a4284544dbfee624f59ee116853 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/22] 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 179c17469a505c3359e6729f899cf5045343dd01 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/22] 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 4a2f52937b0e65591abdbe068b0eec49481f7c2e 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/22] 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 bf9d1014bfc9a9845fb4e555fb8e47d3b4cacc6c 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/22] 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 07e83545945dc54d58d063a3b1756f1683649dae 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/22] 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 6b1a9440bade3d757c72555fa69e2027286da495 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/22] 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: {}