Skip to content

Commit 96ab890

Browse files
committed
fixup! Merge configs from parent directories
1 parent f3c72eb commit 96ab890

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

rustfmt-core/rustfmt-bin/src/bin/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ fn format(opt: Opt) -> Result<i32> {
507507
.into_iter()
508508
.map(|p| p.display().to_string())
509509
.collect::<Vec<_>>()
510-
.join(","),
510+
.join(", "),
511511
file.display()
512512
);
513513
}

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,7 @@ impl Config {
307307
Ok(None)
308308
}
309309

310-
let files = resolve_project_files(dir);
311-
312-
match files? {
310+
match resolve_project_files(dir)? {
313311
None => Ok((Config::default(), None)),
314312
Some(paths) => {
315313
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
@@ -331,14 +331,18 @@ impl IgnoreList {
331331
&self.rustfmt_toml_path
332332
}
333333

334+
/// Merges `self` into `other`, returning a new `IgnoreList`. The resulting `IgnoreList` uses
335+
/// the `rustfmt_toml_path` of `other`, and only contains paths that are in `other`'s
336+
/// `rustfmt_toml_path`.
334337
pub fn merge_into(self, other: Self) -> Self {
335338
let old_rustfmt_toml_path = self.rustfmt_toml_path;
336-
let new_rustfmt_toml_path = other.rustfmt_toml_path.clone();
339+
let new_rustfmt_toml_path = other.rustfmt_toml_path;
337340
let relocalized_old_paths: HashSet<PathBuf> = self
338341
.path_set
339342
.into_iter()
340343
.map(|p| old_rustfmt_toml_path.parent().unwrap().join(p))
341344
.map(|p| {
345+
// Only keep old paths that are also in the new config path
342346
p.strip_prefix(new_rustfmt_toml_path.parent().unwrap())
343347
.map(PathBuf::from)
344348
})

0 commit comments

Comments
 (0)