Skip to content

Commit 3a72bf3

Browse files
committed
Auto merge of #13349 - epage:config, r=weihanglo
fix(config): Deprecate non-extension files ### What does this PR try to resolve? 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/ ### How should we test and review this PR? It'll be important to look at the individual commits as one updates tests from using `.cargo/config` to `.cargo/config.toml` which touches a lot of code. I added a test for `.cargo/config` in a separate commit so you can see how the output changes. ### Additional information Discussed on [zulip](https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Deprecating.20credential.20provider.20default.3F)
2 parents f4bafa7 + 6eb2dde commit 3a72bf3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+359
-330
lines changed

crates/cargo-test-support/src/registry.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ impl RegistryBuilder {
279279
/// Initializes the registry.
280280
#[must_use]
281281
pub fn build(self) -> TestRegistry {
282-
let config_path = paths::home().join(".cargo/config");
282+
let config_path = paths::home().join(".cargo/config.toml");
283283
t!(fs::create_dir_all(config_path.parent().unwrap()));
284284
let prefix = if let Some(alternative) = &self.alternative {
285285
format!("{alternative}-")
@@ -1195,7 +1195,7 @@ impl Package {
11951195
/// Creates a new package builder.
11961196
/// Call `publish()` to finalize and build the package.
11971197
pub fn new(name: &str, vers: &str) -> Package {
1198-
let config = paths::home().join(".cargo/config");
1198+
let config = paths::home().join(".cargo/config.toml");
11991199
if !config.exists() {
12001200
init();
12011201
}

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}` to `{filename_without_extension}.toml`"),
1537+
)?;
1538+
}
15291539
}
15301540
}
15311541

tests/testsuite/alt_registry.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ You may press ctrl-c to skip waiting; the crate should be available shortly.
621621
fn passwords_in_registries_index_url_forbidden() {
622622
registry::alt_init();
623623

624-
let config = paths::home().join(".cargo/config");
624+
let config = paths::home().join(".cargo/config.toml");
625625

626626
fs::write(
627627
config,
@@ -638,7 +638,7 @@ fn passwords_in_registries_index_url_forbidden() {
638638
.with_status(101)
639639
.with_stderr(
640640
"\
641-
error: invalid index URL for registry `alternative` defined in [..]/home/.cargo/config
641+
error: invalid index URL for registry `alternative` defined in [..]/home/.cargo/config.toml
642642
643643
Caused by:
644644
registry URLs may not contain passwords
@@ -1153,7 +1153,7 @@ fn unknown_registry() {
11531153
.publish();
11541154

11551155
// Remove "alternative" from config.
1156-
let cfg_path = paths::home().join(".cargo/config");
1156+
let cfg_path = paths::home().join(".cargo/config.toml");
11571157
let mut config = fs::read_to_string(&cfg_path).unwrap();
11581158
let start = config.find("[registries.alternative]").unwrap();
11591159
config.insert(start, '#');
@@ -1296,7 +1296,7 @@ fn unknown_registry() {
12961296
#[cargo_test]
12971297
fn registries_index_relative_url() {
12981298
registry::alt_init();
1299-
let config = paths::root().join(".cargo/config");
1299+
let config = paths::root().join(".cargo/config.toml");
13001300
fs::create_dir_all(config.parent().unwrap()).unwrap();
13011301
fs::write(
13021302
&config,
@@ -1343,7 +1343,7 @@ fn registries_index_relative_url() {
13431343
#[cargo_test]
13441344
fn registries_index_relative_path_not_allowed() {
13451345
registry::alt_init();
1346-
let config = paths::root().join(".cargo/config");
1346+
let config = paths::root().join(".cargo/config.toml");
13471347
fs::create_dir_all(config.parent().unwrap()).unwrap();
13481348
fs::write(
13491349
&config,
@@ -1379,7 +1379,7 @@ fn registries_index_relative_path_not_allowed() {
13791379
error: failed to parse manifest at `{root}/foo/Cargo.toml`
13801380
13811381
Caused by:
1382-
invalid index URL for registry `relative` defined in [..]/.cargo/config
1382+
invalid index URL for registry `relative` defined in [..]/.cargo/config.toml
13831383
13841384
Caused by:
13851385
invalid url `alternative-registry`: relative URL without a base

tests/testsuite/bad_config.rs

+32-32
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn bad1() {
99
let p = project()
1010
.file("src/lib.rs", "")
1111
.file(
12-
".cargo/config",
12+
".cargo/config.toml",
1313
r#"
1414
[target]
1515
nonexistent-target = "foo"
@@ -21,7 +21,7 @@ fn bad1() {
2121
.with_stderr(
2222
"\
2323
[ERROR] expected table for configuration key `target.nonexistent-target`, \
24-
but found string in [..]/config
24+
but found string in [..]/config.toml
2525
",
2626
)
2727
.run();
@@ -32,7 +32,7 @@ fn bad2() {
3232
let p = project()
3333
.file("src/lib.rs", "")
3434
.file(
35-
".cargo/config",
35+
".cargo/config.toml",
3636
r#"
3737
[http]
3838
proxy = 3.0
@@ -46,7 +46,7 @@ fn bad2() {
4646
[ERROR] could not load Cargo configuration
4747
4848
Caused by:
49-
failed to load TOML configuration from `[..]config`
49+
failed to load TOML configuration from `[..]config.toml`
5050
5151
Caused by:
5252
failed to parse key `http`
@@ -67,7 +67,7 @@ fn bad3() {
6767
let p = project()
6868
.file("src/lib.rs", "")
6969
.file(
70-
".cargo/config",
70+
".cargo/config.toml",
7171
r#"
7272
[http]
7373
proxy = true
@@ -84,7 +84,7 @@ fn bad3() {
8484
error: failed to update registry [..]
8585
8686
Caused by:
87-
error in [..]config: `http.proxy` expected a string, but found a boolean
87+
error in [..]config.toml: `http.proxy` expected a string, but found a boolean
8888
",
8989
)
9090
.run();
@@ -94,7 +94,7 @@ Caused by:
9494
fn bad4() {
9595
let p = project()
9696
.file(
97-
".cargo/config",
97+
".cargo/config.toml",
9898
r#"
9999
[cargo-new]
100100
vcs = false
@@ -108,7 +108,7 @@ fn bad4() {
108108
[ERROR] Failed to create package `foo` at `[..]`
109109
110110
Caused by:
111-
error in [..]config: `cargo-new.vcs` expected a string, but found a boolean
111+
error in [..]config.toml: `cargo-new.vcs` expected a string, but found a boolean
112112
",
113113
)
114114
.run();
@@ -120,7 +120,7 @@ fn bad6() {
120120
let p = project()
121121
.file("src/lib.rs", "")
122122
.file(
123-
".cargo/config",
123+
".cargo/config.toml",
124124
r#"
125125
[http]
126126
user-agent = true
@@ -137,7 +137,7 @@ fn bad6() {
137137
error: failed to update registry [..]
138138
139139
Caused by:
140-
error in [..]config: `http.user-agent` expected a string, but found a boolean
140+
error in [..]config.toml: `http.user-agent` expected a string, but found a boolean
141141
",
142142
)
143143
.run();
@@ -158,7 +158,7 @@ fn invalid_global_config() {
158158
foo = "0.1.0"
159159
"#,
160160
)
161-
.file(".cargo/config", "4")
161+
.file(".cargo/config.toml", "4")
162162
.file("src/lib.rs", "")
163163
.build();
164164

@@ -788,7 +788,7 @@ or workspace dependency to use. This will be considered an error in future versi
788788
#[cargo_test]
789789
fn invalid_toml_historically_allowed_fails() {
790790
let p = project()
791-
.file(".cargo/config", "[bar] baz = 2")
791+
.file(".cargo/config.toml", "[bar] baz = 2")
792792
.file("src/main.rs", "fn main() {}")
793793
.build();
794794

@@ -880,7 +880,7 @@ use `rev = \"foo\"` in the dependency declaration.
880880
fn bad_source_config1() {
881881
let p = project()
882882
.file("src/lib.rs", "")
883-
.file(".cargo/config", "[source.foo]")
883+
.file(".cargo/config.toml", "[source.foo]")
884884
.build();
885885

886886
p.cargo("check")
@@ -906,7 +906,7 @@ fn bad_source_config2() {
906906
)
907907
.file("src/lib.rs", "")
908908
.file(
909-
".cargo/config",
909+
".cargo/config.toml",
910910
r#"
911911
[source.crates-io]
912912
registry = 'http://example.com'
@@ -952,7 +952,7 @@ fn bad_source_config3() {
952952
)
953953
.file("src/lib.rs", "")
954954
.file(
955-
".cargo/config",
955+
".cargo/config.toml",
956956
r#"
957957
[source.crates-io]
958958
registry = 'https://example.com'
@@ -997,7 +997,7 @@ fn bad_source_config4() {
997997
)
998998
.file("src/lib.rs", "")
999999
.file(
1000-
".cargo/config",
1000+
".cargo/config.toml",
10011001
r#"
10021002
[source.crates-io]
10031003
replace-with = 'bar'
@@ -1046,7 +1046,7 @@ fn bad_source_config5() {
10461046
)
10471047
.file("src/lib.rs", "")
10481048
.file(
1049-
".cargo/config",
1049+
".cargo/config.toml",
10501050
r#"
10511051
[source.crates-io]
10521052
registry = 'https://example.com'
@@ -1120,7 +1120,7 @@ fn bad_source_config6() {
11201120
)
11211121
.file("src/lib.rs", "")
11221122
.file(
1123-
".cargo/config",
1123+
".cargo/config.toml",
11241124
r#"
11251125
[source.crates-io]
11261126
registry = 'https://example.com'
@@ -1133,10 +1133,10 @@ fn bad_source_config6() {
11331133
.with_status(101)
11341134
.with_stderr(
11351135
"\
1136-
[ERROR] error in [..]/foo/.cargo/config: could not load config key `source.crates-io.replace-with`
1136+
[ERROR] error in [..]/foo/.cargo/config.toml: could not load config key `source.crates-io.replace-with`
11371137
11381138
Caused by:
1139-
error in [..]/foo/.cargo/config: `source.crates-io.replace-with` expected a string, but found a array
1139+
error in [..]/foo/.cargo/config.toml: `source.crates-io.replace-with` expected a string, but found a array
11401140
"
11411141
)
11421142
.run();
@@ -1207,7 +1207,7 @@ fn bad_source_config7() {
12071207
)
12081208
.file("src/lib.rs", "")
12091209
.file(
1210-
".cargo/config",
1210+
".cargo/config.toml",
12111211
r#"
12121212
[source.foo]
12131213
registry = 'https://example.com'
@@ -1241,7 +1241,7 @@ fn bad_source_config8() {
12411241
)
12421242
.file("src/lib.rs", "")
12431243
.file(
1244-
".cargo/config",
1244+
".cargo/config.toml",
12451245
r#"
12461246
[source.foo]
12471247
branch = "somebranch"
@@ -1253,7 +1253,7 @@ fn bad_source_config8() {
12531253
.with_status(101)
12541254
.with_stderr(
12551255
"[ERROR] source definition `source.foo` specifies `branch`, \
1256-
but that requires a `git` key to be specified (in [..]/foo/.cargo/config)",
1256+
but that requires a `git` key to be specified (in [..]/foo/.cargo/config.toml)",
12571257
)
12581258
.run();
12591259
}
@@ -1532,7 +1532,7 @@ fn bad_target_cfg() {
15321532
// the message.
15331533
let p = project()
15341534
.file(
1535-
".cargo/config",
1535+
".cargo/config.toml",
15361536
r#"
15371537
[target.'cfg(not(target_os = "none"))']
15381538
runner = false
@@ -1545,17 +1545,17 @@ fn bad_target_cfg() {
15451545
.with_status(101)
15461546
.with_stderr(
15471547
"\
1548-
[ERROR] error in [..]/foo/.cargo/config: \
1548+
[ERROR] error in [..]/foo/.cargo/config.toml: \
15491549
could not load config key `target.\"cfg(not(target_os = \\\"none\\\"))\".runner`
15501550
15511551
Caused by:
1552-
error in [..]/foo/.cargo/config: \
1552+
error in [..]/foo/.cargo/config.toml: \
15531553
could not load config key `target.\"cfg(not(target_os = \\\"none\\\"))\".runner`
15541554
15551555
Caused by:
15561556
invalid configuration for key `target.\"cfg(not(target_os = \\\"none\\\"))\".runner`
15571557
expected a string or array of strings, but found a boolean for \
1558-
`target.\"cfg(not(target_os = \\\"none\\\"))\".runner` in [..]/foo/.cargo/config
1558+
`target.\"cfg(not(target_os = \\\"none\\\"))\".runner` in [..]/foo/.cargo/config.toml
15591559
",
15601560
)
15611561
.run();
@@ -1571,7 +1571,7 @@ fn bad_target_links_overrides() {
15711571
// currently is designed with serde.
15721572
let p = project()
15731573
.file(
1574-
".cargo/config",
1574+
".cargo/config.toml",
15751575
&format!(
15761576
r#"
15771577
[target.{}.somelib]
@@ -1587,12 +1587,12 @@ fn bad_target_links_overrides() {
15871587
.with_status(101)
15881588
.with_stderr(
15891589
"[ERROR] Only `-l` and `-L` flags are allowed in target config \
1590-
`target.[..].rustc-flags` (in [..]foo/.cargo/config): `foo`",
1590+
`target.[..].rustc-flags` (in [..]foo/.cargo/config.toml): `foo`",
15911591
)
15921592
.run();
15931593

15941594
p.change_file(
1595-
".cargo/config",
1595+
".cargo/config.toml",
15961596
&format!(
15971597
"[target.{}.somelib]
15981598
warning = \"foo\"
@@ -1611,7 +1611,7 @@ fn redefined_sources() {
16111611
// Cannot define a source multiple times.
16121612
let p = project()
16131613
.file(
1614-
".cargo/config",
1614+
".cargo/config.toml",
16151615
r#"
16161616
[source.foo]
16171617
registry = "https://github.com/rust-lang/crates.io-index"
@@ -1632,7 +1632,7 @@ note: Sources are not allowed to be defined multiple times.
16321632
.run();
16331633

16341634
p.change_file(
1635-
".cargo/config",
1635+
".cargo/config.toml",
16361636
r#"
16371637
[source.one]
16381638
directory = "index"

0 commit comments

Comments
 (0)