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;
16 /// Returns the path to the Clippy project directory
20 /// Panics if the current directory could not be retrieved, there was an error reading any of the
21 /// Cargo.toml files or ancestor directory is the clippy root directory
23 pub fn clippy_project_root() -> PathBuf {
24 let current_dir = std::env::current_dir().unwrap();
25 for path in current_dir.ancestors() {
26 let result = std::fs::read_to_string(path.join("Cargo.toml"));
27 if let Err(err) = &result {
28 if err.kind() == std::io::ErrorKind::NotFound {
33 let content = result.unwrap();
34 if content.contains("[package]\nname = \"clippy\"") {
35 return path.to_path_buf();
38 panic!("error: Can't determine root of project. Please run inside a Clippy working dir.");