Skip to content

Commit bf627a3

Browse files
committed
fixup! Merge configs from parent directories
1 parent 9cf09c7 commit bf627a3

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

rustfmt-core/rustfmt-lib/src/config.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,7 @@ impl Config {
293293
Ok(None)
294294
}
295295

296-
let files = resolve_project_files(dir);
297-
298-
match files? {
296+
match resolve_project_files(dir)? {
299297
None => Ok((Config::default(), None)),
300298
Some(paths) => {
301299
let mut config = Config::default();

rustfmt-core/rustfmt-lib/src/config/config_type.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ impl ConfigType for IgnoreList {
5050
}
5151
}
5252

53-
macro_rules! update {
54-
($self:ident, ignore = $val:ident, $dir:ident) => {
55-
$self.ignore.1 = true;
53+
macro_rules! update_config {
54+
($config:ident, ignore = $val:ident, $dir:ident) => {
55+
$config.ignore.1 = true;
5656

5757
let mut new_ignored = $val;
5858
new_ignored.add_prefix($dir);
59-
let old_ignored = $self.ignore.2;
60-
$self.ignore.2 = old_ignored.merge_into(new_ignored);
59+
let old_ignored = $config.ignore.2;
60+
$config.ignore.2 = old_ignored.merge_into(new_ignored);
6161
};
6262

63-
($self:ident, $i:ident = $val:ident, $dir:ident) => {
64-
$self.$i.1 = true;
65-
$self.$i.2 = $val;
63+
($config:ident, $i:ident = $val:ident, $dir:ident) => {
64+
$config.$i.1 = true;
65+
$config.$i.2 = $val;
6666
};
6767
}
6868

@@ -165,10 +165,10 @@ macro_rules! create_config {
165165
$(
166166
if let Some(val) = parsed.$i {
167167
if self.$i.3 {
168-
update!(self, $i = val, dir);
168+
update_config!(self, $i = val, dir);
169169
} else {
170170
if is_nightly_channel!() {
171-
update!(self, $i = val, dir);
171+
update_config!(self, $i = val, dir);
172172
} else {
173173
eprintln!("Warning: can't set `{} = {:?}`, unstable features are only \
174174
available in nightly channel.", stringify!($i), val);

rustfmt-core/rustfmt-lib/src/config/options.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,18 @@ impl IgnoreList {
277277
&self.rustfmt_toml_path
278278
}
279279

280+
/// Merges `self` into `other`, returning a new `IgnoreList`. The resulting `IgnoreList` uses
281+
/// the `rustfmt_toml_path` of `other`, and only contains paths that are in `other`'s
282+
/// `rustfmt_toml_path`.
280283
pub fn merge_into(self, other: Self) -> Self {
281284
let old_rustfmt_toml_path = self.rustfmt_toml_path;
282-
let new_rustfmt_toml_path = other.rustfmt_toml_path.clone();
285+
let new_rustfmt_toml_path = other.rustfmt_toml_path;
283286
let relocalized_old_paths: HashSet<PathBuf> = self
284287
.path_set
285288
.into_iter()
286289
.map(|p| old_rustfmt_toml_path.parent().unwrap().join(p))
287290
.map(|p| {
291+
// Only keep old paths that are also in the new config path
288292
p.strip_prefix(new_rustfmt_toml_path.parent().unwrap())
289293
.map(PathBuf::from)
290294
})

0 commit comments

Comments
 (0)