Skip to content

Commit 965edb6

Browse files
committed
Enforce single MSRV setting location
As of rust 1.62, we can just set the MSRV in the Cargo.toml manifest for a package.
1 parent 95d2b40 commit 965edb6

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

cargo-rbmt/src/lint.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::fs;
2+
use std::path::Path;
23
use xshell::Shell;
34

45
use crate::environment::{get_crate_dirs, quiet_println, CONFIG_FILE_PATH};
@@ -46,6 +47,7 @@ pub fn run(sh: &Shell, packages: &[String]) -> Result<(), Box<dyn std::error::Er
4647
lint_workspace(sh)?;
4748
lint_crates(sh, packages)?;
4849
check_duplicate_deps(sh)?;
50+
check_clippy_toml_msrv(sh, packages)?;
4951

5052
quiet_println("Lint task completed successfully");
5153
Ok(())
@@ -139,3 +141,62 @@ fn check_duplicate_deps(sh: &Shell) -> Result<(), Box<dyn std::error::Error>> {
139141
quiet_println("No duplicate dependencies found");
140142
Ok(())
141143
}
144+
145+
/// Check for deprecated clippy.toml MSRV settings.
146+
///
147+
/// The bitcoin ecosystem has moved to Rust 1.74+ and should use Cargo.toml
148+
/// package.rust-version instead of clippy.toml msrv settings.
149+
fn check_clippy_toml_msrv(
150+
sh: &Shell,
151+
packages: &[String],
152+
) -> Result<(), Box<dyn std::error::Error>> {
153+
const CLIPPY_CONFIG_FILES: &[&str] = &["clippy.toml", ".clippy.toml"];
154+
155+
quiet_println("Checking for deprecated clippy.toml MSRV settings...");
156+
157+
let mut clippy_files = Vec::new();
158+
159+
// Check workspace root.
160+
let workspace_root = sh.current_dir();
161+
for filename in CLIPPY_CONFIG_FILES {
162+
let path = workspace_root.join(filename);
163+
if path.exists() {
164+
clippy_files.push(path);
165+
}
166+
}
167+
168+
// Check each package.
169+
let crate_dirs = get_crate_dirs(sh, packages)?;
170+
for crate_dir in crate_dirs {
171+
for filename in CLIPPY_CONFIG_FILES {
172+
let path = Path::new(&crate_dir).join(filename);
173+
if path.exists() {
174+
clippy_files.push(path);
175+
}
176+
}
177+
}
178+
179+
// Check each clippy file for the msrv setting.
180+
let mut problematic_files = Vec::new();
181+
for path in clippy_files {
182+
let contents = fs::read_to_string(&path)?;
183+
let config: toml::Value = toml::from_str(&contents)?;
184+
185+
if config.get("msrv").is_some() {
186+
problematic_files.push(path.display().to_string());
187+
}
188+
}
189+
190+
if !problematic_files.is_empty() {
191+
eprintln!(
192+
"\nError: Found MSRV in clippy.toml, use Cargo.toml package.rust-version instead:"
193+
);
194+
for file in &problematic_files {
195+
eprintln!(" {}", file);
196+
}
197+
return Err("MSRV should be specified in Cargo.toml, not clippy.toml".into());
198+
}
199+
200+
quiet_println("No deprecated clippy.toml MSRV settings found");
201+
Ok(())
202+
}

0 commit comments

Comments
 (0)