diff --git a/rustfmt-core/rustfmt-lib/src/formatting/syntux/session/ignore_path.rs b/rustfmt-core/rustfmt-lib/src/formatting/syntux/session/ignore_path.rs index d4e798315b7..437ba5dc8cf 100644 --- a/rustfmt-core/rustfmt-lib/src/formatting/syntux/session/ignore_path.rs +++ b/rustfmt-core/rustfmt-lib/src/formatting/syntux/session/ignore_path.rs @@ -1,3 +1,5 @@ +use std::path::Path; + use ignore::gitignore::{Gitignore, GitignoreBuilder}; use crate::config::{FileName, IgnoreList}; @@ -8,7 +10,11 @@ pub(crate) struct IgnorePathSet { impl IgnorePathSet { pub(crate) fn from_ignore_list(ignore_list: &IgnoreList) -> Result { - let mut ignore_builder = GitignoreBuilder::new(ignore_list.rustfmt_toml_path()); + let root = ignore_list + .rustfmt_toml_path() + .parent() + .unwrap_or(&Path::new("")); + let mut ignore_builder = GitignoreBuilder::new(root); for ignore_path in ignore_list { ignore_builder.add_line(None, &ignore_path.to_string_lossy())?;