Skip to content

Commit 6eea598

Browse files
committed
Fix config file lookup
1 parent 3af9584 commit 6eea598

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

clippy_lints/src/lib.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore) {
405405

406406
#[doc(hidden)]
407407
pub fn read_conf(sess: &Session) -> Conf {
408-
use std::path::Path;
409408
let file_name = match utils::conf::lookup_conf_file() {
410409
Ok(Some(path)) => path,
411410
Ok(None) => return Conf::default(),
@@ -416,16 +415,6 @@ pub fn read_conf(sess: &Session) -> Conf {
416415
},
417416
};
418417

419-
let file_name = if file_name.is_relative() {
420-
sess.local_crate_source_file
421-
.as_deref()
422-
.and_then(Path::parent)
423-
.unwrap_or_else(|| Path::new(""))
424-
.join(file_name)
425-
} else {
426-
file_name
427-
};
428-
429418
let TryConf { conf, errors } = utils::conf::read(&file_name);
430419
// all conf errors are non-fatal, we just use the default conf in case of error
431420
for error in errors {

clippy_lints/src/utils/conf.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,13 @@ pub fn lookup_conf_file() -> io::Result<Option<PathBuf>> {
210210
.map_or_else(|| PathBuf::from("."), PathBuf::from);
211211
loop {
212212
for config_file_name in &CONFIG_FILE_NAMES {
213-
let config_file = current.join(config_file_name);
214-
match fs::metadata(&config_file) {
215-
// Only return if it's a file to handle the unlikely situation of a directory named
216-
// `clippy.toml`.
217-
Ok(ref md) if !md.is_dir() => return Ok(Some(config_file)),
218-
// Return the error if it's something other than `NotFound`; otherwise we didn't
219-
// find the project file yet, and continue searching.
220-
Err(e) if e.kind() != io::ErrorKind::NotFound => return Err(e),
221-
_ => {},
213+
if let Ok(config_file) = current.join(config_file_name).canonicalize() {
214+
match fs::metadata(&config_file) {
215+
Err(e) if e.kind() == io::ErrorKind::NotFound => {},
216+
Err(e) => return Err(e),
217+
Ok(md) if md.is_dir() => {},
218+
Ok(_) => return Ok(Some(config_file)),
219+
}
222220
}
223221
}
224222

0 commit comments

Comments
 (0)