Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 24daa17

Browse files
committed
Look for a global rustfmt.toml.
If no rustfmt.toml is found in the usual way, the directory 'rustfmt' in the user's config directory is checked. - $XDG_CONFIG_HOME/rustfmt/ (or $HOME/.config/rustfmt/), or - $HOME/Library/Preferences/rustfmt/ on Mac, or - %AppData%\rustfmt\ on Windows.
1 parent 203e6d2 commit 24daa17

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

Cargo.lock

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ failure = "0.1.3"
5555
bytecount = "0.5"
5656
unicode-width = "0.1.5"
5757
unicode_categories = "0.1.1"
58+
dirs = "1.0.4"
5859

5960
# A noop dependency that changes in the Rust repository, it's a bit of a hack.
6061
# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`

src/config/config_type.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,19 @@ macro_rules! create_config {
345345

346346
// If the current directory has no parent, we're done searching.
347347
if !current.pop() {
348-
return Ok(None);
348+
break;
349349
}
350350
}
351+
352+
// If none was found, check in the global configuration directory.
353+
if let Some(mut config_dir) = dirs::config_dir() {
354+
config_dir.push("rustfmt");
355+
if let Some(path) = get_toml_path(&config_dir)? {
356+
return Ok(Some(path));
357+
}
358+
}
359+
360+
return Ok(None);
351361
}
352362

353363
match resolve_project_file(dir)? {

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ extern crate derive_new;
1313
extern crate atty;
1414
extern crate bytecount;
1515
extern crate diff;
16+
extern crate dirs;
1617
extern crate failure;
1718
extern crate itertools;
1819
#[cfg(test)]

0 commit comments

Comments
 (0)