From 4f77f6d21be7e54e18a618e84e55898357254cc8 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..901357dbc595 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}` to `{filename_without_extension}.toml`"), + )?; + } } } diff --git a/tests/testsuite/config.rs b/tests/testsuite/config.rs index e02cd445d903..39bc30e41e05 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` to `config.toml`"; + assert_match(expected, &output); } #[cargo_test]