about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-06-21 05:19:08 +0000
committerbors <bors@rust-lang.org>2025-06-21 05:19:08 +0000
commitdf4ad9e28b9fb973e244ebc65a8167a261b8f45e (patch)
tree1b17d0c6e48d7a5d09afa5fcddf63af774814b02 /src
parent15c701fbc995eb6c5b3a86021c18185f8eee020d (diff)
parent432c7d0235a61bc4f54e8be7b072583a769d8b2a (diff)
downloadrust-df4ad9e28b9fb973e244ebc65a8167a261b8f45e.tar.gz
rust-df4ad9e28b9fb973e244ebc65a8167a261b8f45e.zip
Auto merge of #142814 - tgross35:rollup-fioob6s, r=tgross35
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#142384 (Bringing `rustc_rayon_core` in tree as `rustc_thread_pool`)
 - rust-lang/rust#142476 (Insert parentheses around binary operation with attribute)
 - rust-lang/rust#142485 (Marks ADT live if it appears in pattern)
 - rust-lang/rust#142571 (Reason about borrowed classes in CopyProp.)
 - rust-lang/rust#142677 (Add CI check to ensure that rustdoc JSON `FORMAT_VERSION` is correctly updated)
 - rust-lang/rust#142716 (Adjust `with_generic_param_rib`.)
 - rust-lang/rust#142756 (Make `Clone` a `const_trait`)
 - rust-lang/rust#142765 (rustc_target: document public AbiMap-related fn and variants)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'src')
-rw-r--r--src/build_helper/src/ci.rs6
-rw-r--r--src/build_helper/src/git.rs2
-rw-r--r--src/tools/tidy/src/deps.rs2
-rw-r--r--src/tools/tidy/src/lib.rs1
-rw-r--r--src/tools/tidy/src/main.rs1
-rw-r--r--src/tools/tidy/src/rustdoc_json.rs101
6 files changed, 110 insertions, 3 deletions
diff --git a/src/build_helper/src/ci.rs b/src/build_helper/src/ci.rs
index 60f319129a0..9d114c70a67 100644
--- a/src/build_helper/src/ci.rs
+++ b/src/build_helper/src/ci.rs
@@ -17,7 +17,11 @@ impl CiEnv {
     }
 
     pub fn is_ci() -> bool {
-        Self::current() != CiEnv::None
+        Self::current().is_running_in_ci()
+    }
+
+    pub fn is_running_in_ci(self) -> bool {
+        self != CiEnv::None
     }
 
     /// Checks if running in rust-lang/rust managed CI job.
diff --git a/src/build_helper/src/git.rs b/src/build_helper/src/git.rs
index 438cd14389c..9d1195aadf8 100644
--- a/src/build_helper/src/git.rs
+++ b/src/build_helper/src/git.rs
@@ -198,7 +198,7 @@ fn get_latest_upstream_commit_that_modified_files(
 /// author.
 ///
 /// If we are in CI, we simply return our first parent.
-fn get_closest_upstream_commit(
+pub fn get_closest_upstream_commit(
     git_dir: Option<&Path>,
     config: &GitConfig<'_>,
     env: CiEnv,
diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs
index 170dcd626a2..716d42c32eb 100644
--- a/src/tools/tidy/src/deps.rs
+++ b/src/tools/tidy/src/deps.rs
@@ -356,6 +356,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
     "rand",
     "rand_chacha",
     "rand_core",
+    "rand_xorshift", // dependency for doc-tests in rustc_thread_pool
     "rand_xoshiro",
     "redox_syscall",
     "regex",
@@ -364,7 +365,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
     "rustc-demangle",
     "rustc-hash",
     "rustc-literal-escaper",
-    "rustc-rayon-core",
     "rustc-stable-hash",
     "rustc_apfloat",
     "rustix",
diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs
index e8a12d56335..28aa80225b1 100644
--- a/src/tools/tidy/src/lib.rs
+++ b/src/tools/tidy/src/lib.rs
@@ -83,6 +83,7 @@ pub mod pal;
 pub mod rustdoc_css_themes;
 pub mod rustdoc_gui_tests;
 pub mod rustdoc_js;
+pub mod rustdoc_json;
 pub mod rustdoc_templates;
 pub mod style;
 pub mod target_policy;
diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs
index 776f1bde2eb..0b66017b865 100644
--- a/src/tools/tidy/src/main.rs
+++ b/src/tools/tidy/src/main.rs
@@ -110,6 +110,7 @@ fn main() {
         check!(rustdoc_css_themes, &librustdoc_path);
         check!(rustdoc_templates, &librustdoc_path);
         check!(rustdoc_js, &librustdoc_path, &tools_path, &src_path);
+        check!(rustdoc_json, &src_path);
         check!(known_bug, &crashes_path);
         check!(unknown_revision, &tests_path);
 
diff --git a/src/tools/tidy/src/rustdoc_json.rs b/src/tools/tidy/src/rustdoc_json.rs
new file mode 100644
index 00000000000..f179acf4a51
--- /dev/null
+++ b/src/tools/tidy/src/rustdoc_json.rs
@@ -0,0 +1,101 @@
+//! Tidy check to ensure that `FORMAT_VERSION` was correctly updated if `rustdoc-json-types` was
+//! updated as well.
+
+use std::ffi::OsStr;
+use std::path::Path;
+use std::process::Command;
+
+use build_helper::ci::CiEnv;
+use build_helper::git::{GitConfig, get_closest_upstream_commit};
+use build_helper::stage0_parser::parse_stage0_file;
+
+const RUSTDOC_JSON_TYPES: &str = "src/rustdoc-json-types";
+
+fn git_diff<S: AsRef<OsStr>>(base_commit: &str, extra_arg: S) -> Option<String> {
+    let output = Command::new("git").arg("diff").arg(base_commit).arg(extra_arg).output().ok()?;
+    Some(String::from_utf8_lossy(&output.stdout).into())
+}
+
+fn error_if_in_ci(ci_env: CiEnv, msg: &str, bad: &mut bool) {
+    if ci_env.is_running_in_ci() {
+        *bad = true;
+        eprintln!("error in `rustdoc_json` tidy check: {msg}");
+    } else {
+        eprintln!("{msg}. Skipping `rustdoc_json` tidy check");
+    }
+}
+
+pub fn check(src_path: &Path, bad: &mut bool) {
+    println!("Checking tidy rustdoc_json...");
+    let stage0 = parse_stage0_file();
+    let ci_env = CiEnv::current();
+    let base_commit = match get_closest_upstream_commit(
+        None,
+        &GitConfig {
+            nightly_branch: &stage0.config.nightly_branch,
+            git_merge_commit_email: &stage0.config.git_merge_commit_email,
+        },
+        ci_env,
+    ) {
+        Ok(Some(commit)) => commit,
+        Ok(None) => {
+            error_if_in_ci(ci_env, "no base commit found", bad);
+            return;
+        }
+        Err(error) => {
+            error_if_in_ci(ci_env, &format!("failed to retrieve base commit: {error}"), bad);
+            return;
+        }
+    };
+
+    // First we check that `src/rustdoc-json-types` was modified.
+    match git_diff(&base_commit, "--name-status") {
+        Some(output) => {
+            if !output
+                .lines()
+                .any(|line| line.starts_with("M") && line.contains(RUSTDOC_JSON_TYPES))
+            {
+                // `rustdoc-json-types` was not modified so nothing more to check here.
+                println!("`rustdoc-json-types` was not modified.");
+                return;
+            }
+        }
+        None => {
+            *bad = true;
+            eprintln!("error: failed to run `git diff` in rustdoc_json check");
+            return;
+        }
+    }
+    // Then we check that if `FORMAT_VERSION` was updated, the `Latest feature:` was also updated.
+    match git_diff(&base_commit, src_path.join("rustdoc-json-types")) {
+        Some(output) => {
+            let mut format_version_updated = false;
+            let mut latest_feature_comment_updated = false;
+            for line in output.lines() {
+                if line.starts_with("+pub const FORMAT_VERSION: u32 =") {
+                    format_version_updated = true;
+                } else if line.starts_with("+// Latest feature:") {
+                    latest_feature_comment_updated = true;
+                }
+            }
+            if format_version_updated != latest_feature_comment_updated {
+                *bad = true;
+                if latest_feature_comment_updated {
+                    eprintln!(
+                        "error in `rustdoc_json` tidy check: `Latest feature` comment was updated \
+                         whereas `FORMAT_VERSION` wasn't in `{RUSTDOC_JSON_TYPES}/lib.rs`"
+                    );
+                } else {
+                    eprintln!(
+                        "error in `rustdoc_json` tidy check: `Latest feature` comment was not \
+                         updated whereas `FORMAT_VERSION` was in `{RUSTDOC_JSON_TYPES}/lib.rs`"
+                    );
+                }
+            }
+        }
+        None => {
+            *bad = true;
+            eprintln!("error: failed to run `git diff` in rustdoc_json check");
+        }
+    }
+}