2 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
3 // warn on lints, that are included in `rust-lang/rust`s bootstrap
4 #![warn(rust_2018_idioms, unused_lifetimes)]
6 use std::path::PathBuf;
15 /// Returns the path to the Clippy project directory
19 /// Panics if the current directory could not be retrieved, there was an error reading any of the
20 /// Cargo.toml files or ancestor directory is the clippy root directory
22 pub fn clippy_project_root() -> PathBuf {
23 let current_dir = std::env::current_dir().unwrap();
24 for path in current_dir.ancestors() {
25 let result = std::fs::read_to_string(path.join("Cargo.toml"));
26 if let Err(err) = &result {
27 if err.kind() == std::io::ErrorKind::NotFound {
32 let content = result.unwrap();
33 if content.contains("[package]\nname = \"clippy\"") {
34 return path.to_path_buf();
37 panic!("error: Can't determine root of project. Please run inside a Clippy working dir.");