From 125eeca8f4481a73d4b78ce4c2480bcbd6ff4585 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 26 Jan 2024 11:48:46 -0600 Subject: [PATCH] fix(config): Deprecate non-extension files 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/ --- src/cargo/util/config/mod.rs | 24 +++++++++++++++++------- tests/testsuite/config.rs | 5 ++++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/cargo/util/config/mod.rs b/src/cargo/util/config/mod.rs index 0e161ba8af4e..028cb874b75d 100644 --- a/src/cargo/util/config/mod.rs +++ b/src/cargo/util/config/mod.rs @@ -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 @@ -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}.toml` to `{filename_without_extension}`"), + )?; + } } } diff --git a/tests/testsuite/config.rs b/tests/testsuite/config.rs index e02cd445d903..9a75bfe71bc9 100644 --- a/tests/testsuite/config.rs +++ b/tests/testsuite/config.rs @@ -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.toml` to `config`"; + assert_match(expected, &output); } #[cargo_test]