Skip to content

Commit 4c77771

Browse files
committed
tidy: check_crate_duplicate is no longer useful
After cargo becomes a workspace, no one uses `check_crate_duplicate` to check if cargo is a dependency anymore.
1 parent f795a15 commit 4c77771

File tree

1 file changed

+8
-47
lines changed

1 file changed

+8
-47
lines changed

src/tools/tidy/src/deps.rs

+8-47
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,6 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[
335335
"windows_x86_64_msvc",
336336
];
337337

338-
const FORBIDDEN_TO_HAVE_DUPLICATES: &[&str] = &[
339-
// This crate takes quite a long time to build, so don't allow two versions of them
340-
// to accidentally sneak into our dependency graph, in order to ensure we keep our CI times
341-
// under control.
342-
"cargo",
343-
];
344-
345338
/// Dependency checks.
346339
///
347340
/// `root` is path to the directory with the root `Cargo.toml` (for the workspace). `cargo` is path
@@ -361,7 +354,6 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
361354
&["rustc_driver", "rustc_codegen_llvm"],
362355
bad,
363356
);
364-
check_crate_duplicate(&metadata, &[], bad);
365357

366358
// Check cargo independently as it has it's own workspace.
367359
let mut cmd = cargo_metadata::MetadataCommand::new();
@@ -371,7 +363,6 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
371363
let cargo_metadata = t!(cmd.exec());
372364
let runtime_ids = HashSet::new();
373365
check_license_exceptions(&cargo_metadata, EXCEPTIONS_CARGO, runtime_ids, bad);
374-
check_crate_duplicate(&cargo_metadata, FORBIDDEN_TO_HAVE_DUPLICATES, bad);
375366
check_rustfix(&metadata, &cargo_metadata, bad);
376367

377368
// Check rustc_codegen_cranelift independently as it has it's own workspace.
@@ -389,7 +380,6 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
389380
&["rustc_codegen_cranelift"],
390381
bad,
391382
);
392-
check_crate_duplicate(&metadata, &[], bad);
393383

394384
let mut cmd = cargo_metadata::MetadataCommand::new();
395385
cmd.cargo_path(cargo)
@@ -535,40 +525,6 @@ fn check_permitted_dependencies(
535525
}
536526
}
537527

538-
/// Prevents multiple versions of some expensive crates.
539-
fn check_crate_duplicate(
540-
metadata: &Metadata,
541-
forbidden_to_have_duplicates: &[&str],
542-
bad: &mut bool,
543-
) {
544-
for &name in forbidden_to_have_duplicates {
545-
let matches: Vec<_> = metadata.packages.iter().filter(|pkg| pkg.name == name).collect();
546-
match matches.len() {
547-
0 => {
548-
tidy_error!(
549-
bad,
550-
"crate `{}` is missing, update `check_crate_duplicate` \
551-
if it is no longer used",
552-
name
553-
);
554-
}
555-
1 => {}
556-
_ => {
557-
tidy_error!(
558-
bad,
559-
"crate `{}` is duplicated in `Cargo.lock`, \
560-
it is too expensive to build multiple times, \
561-
so make sure only one version appears across all dependencies",
562-
name
563-
);
564-
for pkg in matches {
565-
println!(" * {}", pkg.id);
566-
}
567-
}
568-
}
569-
}
570-
}
571-
572528
/// Finds a package with the given name.
573529
fn pkg_from_name<'a>(metadata: &'a Metadata, name: &'static str) -> &'a Package {
574530
let mut i = metadata.packages.iter().filter(|p| p.name == name);
@@ -618,18 +574,23 @@ fn deps_of_filtered<'a>(
618574
}
619575
}
620576

621-
fn direct_deps_of<'a>(metadata: &'a Metadata, pkg_id: &'a PackageId) -> impl Iterator<Item = &'a Package> {
577+
fn direct_deps_of<'a>(
578+
metadata: &'a Metadata,
579+
pkg_id: &'a PackageId,
580+
) -> impl Iterator<Item = &'a Package> {
622581
let resolve = metadata.resolve.as_ref().unwrap();
623582
let node = resolve.nodes.iter().find(|n| &n.id == pkg_id).unwrap();
624583
node.deps.iter().map(|dep| pkg_from_id(metadata, &dep.pkg))
625584
}
626585

627586
fn check_rustfix(rust_metadata: &Metadata, cargo_metadata: &Metadata, bad: &mut bool) {
628587
let cargo = pkg_from_name(cargo_metadata, "cargo");
629-
let cargo_rustfix = direct_deps_of(cargo_metadata, &cargo.id).find(|p| p.name == "rustfix").unwrap();
588+
let cargo_rustfix =
589+
direct_deps_of(cargo_metadata, &cargo.id).find(|p| p.name == "rustfix").unwrap();
630590

631591
let compiletest = pkg_from_name(rust_metadata, "compiletest");
632-
let compiletest_rustfix = direct_deps_of(rust_metadata, &compiletest.id).find(|p| p.name == "rustfix").unwrap();
592+
let compiletest_rustfix =
593+
direct_deps_of(rust_metadata, &compiletest.id).find(|p| p.name == "rustfix").unwrap();
633594

634595
if cargo_rustfix.version != compiletest_rustfix.version {
635596
tidy_error!(

0 commit comments

Comments
 (0)