Skip to content

Commit 86c513e

Browse files
committed
Let CLIPPY_CONF_DIR be used to start search for config, and fall back to
CARGO_MANIFEST_DIR if it isn't set. If CARGO_MANIFEST_DIR isn't set, fall back "." rather than panicing. Issue #3663
1 parent 71d03ae commit 86c513e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

clippy_lints/src/utils/conf.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,13 @@ pub fn lookup_conf_file() -> io::Result<Option<path::PathBuf>> {
163163
/// Possible filename to search for.
164164
const CONFIG_FILE_NAMES: [&str; 2] = [".clippy.toml", "clippy.toml"];
165165

166-
let mut current = path::PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"));
167-
166+
// Start looking for a config file in CLIPPY_CONF_DIR, or failing that, CARGO_MANIFEST_DIR.
167+
// If neither of those exist, use ".".
168+
let mut current = path::PathBuf::from(
169+
env::var("CLIPPY_CONF_DIR")
170+
.or_else(|_| env::var("CARGO_MANIFEST_DIR"))
171+
.unwrap_or_else(|_| ".".to_string()),
172+
);
168173
loop {
169174
for config_file_name in &CONFIG_FILE_NAMES {
170175
let config_file = current.join(config_file_name);

0 commit comments

Comments
 (0)