about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev@gmail.com>2021-01-27 04:43:33 +0900
committerGitHub <noreply@github.com>2021-01-27 04:43:33 +0900
commit24a1081a239927424ad8ad5b4500e26d83924e76 (patch)
tree72e1e2e486a5e1b973b1bca361ace34a8348e511
parent9da36082c2d54de74be9679cf63518e11cbc7fa1 (diff)
parent6f22f512ec8e4fce13d2d3675b6549e867bea824 (diff)
downloadrust-24a1081a239927424ad8ad5b4500e26d83924e76.tar.gz
rust-24a1081a239927424ad8ad5b4500e26d83924e76.zip
Rollup merge of #81401 - ehuss:tidy-cleanup, r=Mark-Simulacrum
tidy: Some code cleanup.

This is just some cleanup that shouldn't have any change in behavior.  (See commit messages for more details.)

* Remove cargo check. This test wasn't working, and is no longer valid.
* Remove edition filter exceptions. They are no longer necessary.
* Remove unnecessary trailing semicolon.  Otherwise the warning will prevent tidy from building after the beta branch.
-rw-r--r--src/tools/tidy/src/cargo.rs90
-rw-r--r--src/tools/tidy/src/edition.rs16
-rw-r--r--src/tools/tidy/src/features.rs2
-rw-r--r--src/tools/tidy/src/lib.rs1
-rw-r--r--src/tools/tidy/src/main.rs4
5 files changed, 2 insertions, 111 deletions
diff --git a/src/tools/tidy/src/cargo.rs b/src/tools/tidy/src/cargo.rs
deleted file mode 100644
index e06616a59f3..00000000000
--- a/src/tools/tidy/src/cargo.rs
+++ /dev/null
@@ -1,90 +0,0 @@
-//! Tidy check to ensure that `[dependencies]` and `extern crate` are in sync.
-//!
-//! This tidy check ensures that all crates listed in the `[dependencies]`
-//! section of a `Cargo.toml` are present in the corresponding `lib.rs` as
-//! `extern crate` declarations. This should help us keep the DAG correctly
-//! structured through various refactorings to prune out unnecessary edges.
-
-use std::fs;
-use std::path::Path;
-
-pub fn check(path: &Path, bad: &mut bool) {
-    if !super::filter_dirs(path) {
-        return;
-    }
-    for entry in t!(path.read_dir(), path).map(|e| t!(e)) {
-        // Look for `Cargo.toml` with a sibling `src/lib.rs` or `lib.rs`.
-        if entry.file_name().to_str() == Some("Cargo.toml") {
-            if path.join("src/lib.rs").is_file() {
-                verify(&entry.path(), &path.join("src/lib.rs"), bad)
-            }
-            if path.join("lib.rs").is_file() {
-                verify(&entry.path(), &path.join("lib.rs"), bad)
-            }
-        } else if t!(entry.file_type()).is_dir() {
-            check(&entry.path(), bad);
-        }
-    }
-}
-
-/// Verifies that the dependencies in Cargo.toml at `tomlfile` are synced with
-/// the `extern crate` annotations in the lib.rs at `libfile`.
-fn verify(tomlfile: &Path, libfile: &Path, bad: &mut bool) {
-    let toml = t!(fs::read_to_string(&tomlfile));
-    let librs = t!(fs::read_to_string(&libfile));
-
-    if toml.contains("name = \"bootstrap\"") {
-        return;
-    }
-
-    // "Poor man's TOML parser" -- just assume we use one syntax for now.
-    //
-    // We just look for:
-    //
-    // ````
-    // [dependencies]
-    // name = ...
-    // name2 = ...
-    // name3 = ...
-    // ```
-    //
-    // If we encounter a line starting with `[` then we assume it's the end of
-    // the dependency section and bail out.
-    let deps = match toml.find("[dependencies]") {
-        Some(i) => &toml[i + 1..],
-        None => return,
-    };
-    for line in deps.lines() {
-        if line.starts_with('[') {
-            break;
-        }
-
-        let krate = match line.split_once('=') {
-            None => continue,
-            Some((krate, _)) => krate.trim(),
-        };
-
-        // Don't worry about depending on core/std while not writing `extern crate
-        // core/std` -- that's intentional.
-        if krate == "core" || krate == "std" {
-            continue;
-        }
-
-        // This is intentional -- this dependency just makes the crate available
-        // for others later on.
-        let allowed = krate.starts_with("panic");
-        if toml.contains("name = \"std\"") && allowed {
-            continue;
-        }
-
-        if !librs.contains(&format!("extern crate {}", krate)) {
-            tidy_error!(
-                bad,
-                "{} doesn't have `extern crate {}`, but Cargo.toml \
-                              depends on it",
-                libfile.display(),
-                krate
-            );
-        }
-    }
-}
diff --git a/src/tools/tidy/src/edition.rs b/src/tools/tidy/src/edition.rs
index 7761ae64ee0..283c43e325c 100644
--- a/src/tools/tidy/src/edition.rs
+++ b/src/tools/tidy/src/edition.rs
@@ -2,20 +2,6 @@
 
 use std::path::Path;
 
-fn filter_dirs(path: &Path) -> bool {
-    // FIXME: just use super::filter_dirs after the submodules are updated.
-    if super::filter_dirs(path) {
-        return true;
-    }
-    let skip = [
-        "src/doc/book/second-edition",
-        "src/doc/book/2018-edition",
-        "src/doc/book/ci/stable-check",
-        "src/doc/reference/stable-check",
-    ];
-    skip.iter().any(|p| path.ends_with(p))
-}
-
 fn is_edition_2018(mut line: &str) -> bool {
     line = line.trim();
     line == "edition = \"2018\"" || line == "edition = \'2018\'"
@@ -24,7 +10,7 @@ fn is_edition_2018(mut line: &str) -> bool {
 pub fn check(path: &Path, bad: &mut bool) {
     super::walk(
         path,
-        &mut |path| filter_dirs(path) || path.ends_with("src/test"),
+        &mut |path| super::filter_dirs(path) || path.ends_with("src/test"),
         &mut |entry, contents| {
             let file = entry.path();
             let filename = file.file_name().unwrap();
diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs
index d3a44542759..cb84fd8be6f 100644
--- a/src/tools/tidy/src/features.rs
+++ b/src/tools/tidy/src/features.rs
@@ -422,7 +422,7 @@ fn map_lib_features(
                         mf(Err($msg), file, i + 1);
                         continue;
                     }};
-                };
+                }
                 if let Some((ref name, ref mut f)) = becoming_feature {
                     if f.tracking_issue.is_none() {
                         f.tracking_issue = find_attr_val(line, "issue").and_then(handle_issue_none);
diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs
index d282d240d82..27972c49924 100644
--- a/src/tools/tidy/src/lib.rs
+++ b/src/tools/tidy/src/lib.rs
@@ -40,7 +40,6 @@ macro_rules! tidy_error {
 }
 
 pub mod bins;
-pub mod cargo;
 pub mod debug_artifacts;
 pub mod deps;
 pub mod edition;
diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs
index 080e1631624..2ac96e404ac 100644
--- a/src/tools/tidy/src/main.rs
+++ b/src/tools/tidy/src/main.rs
@@ -49,10 +49,6 @@ fn main() {
     style::check(&compiler_path, &mut bad);
     style::check(&library_path, &mut bad);
 
-    cargo::check(&src_path, &mut bad);
-    cargo::check(&compiler_path, &mut bad);
-    cargo::check(&library_path, &mut bad);
-
     edition::check(&src_path, &mut bad);
     edition::check(&compiler_path, &mut bad);
     edition::check(&library_path, &mut bad);