Skip to content

Commit

Permalink
fix(config): Deprecate non-extension files
Browse files Browse the repository at this point in the history
In #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/
  • Loading branch information
epage committed Jan 26, 2024
1 parent a1525bc commit 6eb2dde
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
24 changes: 17 additions & 7 deletions src/cargo/util/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,7 @@ impl Config {
let possible_with_extension = dir.join(format!("{}.toml", filename_without_extension));

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

if !skip_warning {
self.shell().warn(format!(
"Both `{}` and `{}` exist. Using `{}`",
possible.display(),
possible_with_extension.display(),
possible.display()
))?;
if possible_with_extension.exists() {
self.shell().warn(format!(
"Both `{}` and `{}` exist. Using `{}`",
possible.display(),
possible_with_extension.display(),
possible.display()
))?;
} else {
self.shell().warn(format!(
"`{}` is deprecated in favor of `{filename_without_extension}.toml`",
possible.display(),
))?;
self.shell().note(
format!("If you need to support cargo 1.38 or earlier, you can symlink `{filename_without_extension}` to `{filename_without_extension}.toml`"),
)?;
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion tests/testsuite/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,10 @@ f1 = 1

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

#[cargo_test]
Expand Down

0 comments on commit 6eb2dde

Please sign in to comment.