Skip to content

Commit 125eeca

Browse files
committed
fix(config): Deprecate non-extension files
In rust-lang#7295 (released in 1.39), we said we'd want to warn on use of `.cargo/config` after about 6 months. Over 4 years later, we are now getting that warning. This is important for addressing user confusion, like in https://www.reddit.com/r/rust/comments/19fd5q2/cargoconfig/
1 parent a1525bc commit 125eeca

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/cargo/util/config/mod.rs

+17-7
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ impl Config {
15071507
let possible_with_extension = dir.join(format!("{}.toml", filename_without_extension));
15081508

15091509
if possible.exists() {
1510-
if warn && possible_with_extension.exists() {
1510+
if warn {
15111511
// We don't want to print a warning if the version
15121512
// without the extension is just a symlink to the version
15131513
// WITH an extension, which people may want to do to
@@ -1520,12 +1520,22 @@ impl Config {
15201520
};
15211521

15221522
if !skip_warning {
1523-
self.shell().warn(format!(
1524-
"Both `{}` and `{}` exist. Using `{}`",
1525-
possible.display(),
1526-
possible_with_extension.display(),
1527-
possible.display()
1528-
))?;
1523+
if possible_with_extension.exists() {
1524+
self.shell().warn(format!(
1525+
"Both `{}` and `{}` exist. Using `{}`",
1526+
possible.display(),
1527+
possible_with_extension.display(),
1528+
possible.display()
1529+
))?;
1530+
} else {
1531+
self.shell().warn(format!(
1532+
"`{}` is deprecated in favor of `{filename_without_extension}.toml`",
1533+
possible.display(),
1534+
))?;
1535+
self.shell().note(
1536+
format!("If you need to support cargo 1.38 or earlier, you can symlink `{filename_without_extension}.toml` to `{filename_without_extension}`"),
1537+
)?;
1538+
}
15291539
}
15301540
}
15311541

tests/testsuite/config.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,10 @@ f1 = 1
275275

276276
// It should NOT have warned for the symlink.
277277
let output = read_output(config);
278-
assert_match("", &output);
278+
let expected = "\
279+
warning: `[ROOT]/.cargo/config` is deprecated in favor of `config.toml`
280+
note: If you need to support cargo 1.38 or earlier, you can symlink `config.toml` to `config`";
281+
assert_match(expected, &output);
279282
}
280283

281284
#[cargo_test]

0 commit comments

Comments
 (0)