Skip to content

Commit 7d43319

Browse files
authored
Check that no profile is present in Cargo.toml files (#15544)
changelog: none r? flip1995
2 parents b7d76e2 + d32e563 commit 7d43319

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/no-profile-in-cargo-toml.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Check that we do not have `profile.*` sections in our `Cargo.toml` files,
2+
// as this causes warnings when run from the compiler repository which includes
3+
// Clippy in a workspace.
4+
//
5+
// Those sections can be put into `.cargo/config.toml` which will be read
6+
// when commands are issued from the top-level Clippy directory, outside of
7+
// a workspace.
8+
9+
use std::fs::File;
10+
use std::io::{self, BufRead as _};
11+
use walkdir::WalkDir;
12+
13+
#[test]
14+
fn no_profile_in_cargo_toml() {
15+
// This check could parse `Cargo.toml` using a TOML deserializer, but in practice
16+
// profile sections would be added at the beginning of a line as `[profile.*]`, so
17+
// keep it fast and simple.
18+
for entry in WalkDir::new(".")
19+
.into_iter()
20+
.filter_map(Result::ok)
21+
.filter(|e| e.file_name().to_str() == Some("Cargo.toml"))
22+
{
23+
for line in io::BufReader::new(File::open(entry.path()).unwrap())
24+
.lines()
25+
.map(Result::unwrap)
26+
{
27+
if line.starts_with("[profile.") {
28+
eprintln!("Profile section `{line}` found in file `{}`.", entry.path().display());
29+
eprintln!("Use `.cargo/config.toml` for profiles specific to the standalone Clippy repository.");
30+
panic!("Profile section found in `Cargo.toml`");
31+
}
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)