From 0b17a7503a47bfa1e14f8289957938391fb3293b Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Fri, 22 May 2020 09:52:38 -0700 Subject: [PATCH] fixup! Merge configs from parent directories --- rustfmt-core/rustfmt-bin/src/bin/main.rs | 2 +- rustfmt-core/rustfmt-lib/src/config.rs | 12 ++++-------- rustfmt-core/rustfmt-lib/src/config/options.rs | 3 +-- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/rustfmt-core/rustfmt-bin/src/bin/main.rs b/rustfmt-core/rustfmt-bin/src/bin/main.rs index 62be94da77c..9839dfa7ad3 100644 --- a/rustfmt-core/rustfmt-bin/src/bin/main.rs +++ b/rustfmt-core/rustfmt-bin/src/bin/main.rs @@ -488,7 +488,7 @@ fn format(opt: Opt) -> Result { if opt.verbose { if let Some(paths) = config_paths.as_ref() { println!( - "Using rustfmt config files {}", + "Using rustfmt config file(s) {}", paths .into_iter() .map(|p| p.display().to_string()) diff --git a/rustfmt-core/rustfmt-lib/src/config.rs b/rustfmt-core/rustfmt-lib/src/config.rs index cacaa014385..36c991f8147 100644 --- a/rustfmt-core/rustfmt-lib/src/config.rs +++ b/rustfmt-core/rustfmt-lib/src/config.rs @@ -273,14 +273,10 @@ impl Config { // List of closest -> most distant rustfmt config from the current directory. let config_paths: Option> = paths.into_iter().filter(|p| p.is_some()).collect(); - let has_paths = config_paths.as_ref().and_then(|paths| { - if paths.is_empty() { - None - } else { - Some(paths.len()) - } - }); - if has_paths.is_some() { + let has_paths = config_paths + .as_ref() + .map_or(false, |paths| !paths.is_empty()); + if has_paths { return Ok(config_paths); } diff --git a/rustfmt-core/rustfmt-lib/src/config/options.rs b/rustfmt-core/rustfmt-lib/src/config/options.rs index fbaa2e026e7..8a0f548a708 100644 --- a/rustfmt-core/rustfmt-lib/src/config/options.rs +++ b/rustfmt-core/rustfmt-lib/src/config/options.rs @@ -292,8 +292,7 @@ impl IgnoreList { p.strip_prefix(new_rustfmt_toml_path.parent().unwrap()) .map(PathBuf::from) }) - .filter(|p| p.is_ok()) - .map(|p| p.unwrap()) + .flatten() .collect(); let mut path_set = other.path_set;