1use std::fs;
4use std::path::Path;
5
6use crate::deps::WorkspaceInfo;
7
8const ALLOWED_SOURCES: &[&str] = &[
10 r#""registry+https://github.com/rust-lang/crates.io-index""#,
11 r#""git+https://github.com/rust-lang/team#a5260e76d3aa894c64c56e6ddc8545b9a98043ec""#,
13];
14
15pub fn check(root: &Path, bad: &mut bool) {
18 for &WorkspaceInfo { path, submodules, .. } in crate::deps::WORKSPACES {
19 if crate::deps::has_missing_submodule(root, submodules) {
20 continue;
21 }
22
23 let lockfile = root.join(path).join("Cargo.lock");
26
27 if !lockfile.exists() {
28 tidy_error!(bad, "the `{path}` workspace doesn't have a Cargo.lock");
29 continue;
30 }
31
32 let cargo_lock = t!(fs::read_to_string(&lockfile));
34
35 for line in cargo_lock.lines() {
37 if !line.starts_with("source = ") {
39 continue;
40 }
41
42 let source = line.split_once('=').unwrap().1.trim();
44
45 if !ALLOWED_SOURCES.contains(&source) {
47 tidy_error!(bad, "invalid source: {}", source);
48 }
49 }
50 }
51}