1 #![feature(let_chains)]
3 #![feature(rustc_private)]
4 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
5 // warn on lints, that are included in `rust-lang/rust`s bootstrap
6 #![warn(rust_2018_idioms, unused_lifetimes)]
8 // The `rustc_driver` crate seems to be required in order to use the `rust_lexer` crate.
9 #[allow(unused_extern_crates)]
10 extern crate rustc_driver;
11 extern crate rustc_lexer;
13 use std::path::PathBuf;
25 static CARGO_CLIPPY_EXE: &str = "cargo-clippy";
27 static CARGO_CLIPPY_EXE: &str = "cargo-clippy.exe";
29 /// Returns the path to the `cargo-clippy` binary
31 pub fn cargo_clippy_path() -> PathBuf {
32 let mut path = std::env::current_exe().expect("failed to get current executable name");
33 path.set_file_name(CARGO_CLIPPY_EXE);
37 /// Returns the path to the Clippy project directory
41 /// Panics if the current directory could not be retrieved, there was an error reading any of the
42 /// Cargo.toml files or ancestor directory is the clippy root directory
44 pub fn clippy_project_root() -> PathBuf {
45 let current_dir = std::env::current_dir().unwrap();
46 for path in current_dir.ancestors() {
47 let result = std::fs::read_to_string(path.join("Cargo.toml"));
48 if let Err(err) = &result {
49 if err.kind() == std::io::ErrorKind::NotFound {
54 let content = result.unwrap();
55 if content.contains("[package]\nname = \"clippy\"") {
56 return path.to_path_buf();
59 panic!("error: Can't determine root of project. Please run inside a Clippy working dir.");