Default use sparse index in .crates.toml

Hi, I noticed that cargo install writes registry information to .crates.toml using the git-based index format.

When I switched to USTC's crates.io-index mirror and ran:

cargo install cargo-expand --registry ustc

I noticed an interesting difference in the file format:

​Current default (git index):​

"cargo-expand 1.0.108 (registry+https://github.com/rust-lang/crates.io-index)" = ["cargo-expand.exe"]

​With USTC mirror (sparse protocol):​

"cargo-expand 1.0.108 (sparse+https://mirrors.ustc.edu.cn/crates.io-index/)" = ["cargo-expand.exe"]

I suggest changing Cargo's default behavior to use the sparse registry protocol for crates.io:

sparse+https://index.crates.io/

The registry url that is written to .crates.toml matches what is written to Cargo.lock. To prevent everyone's lockfile to change whenever they switch between a cargo version that uses the git index vs the sparse protocol (or has their cargo configured to override the default choice), cargo uses registry+https://github.com/rust-lang/crates.io-index as canonical name for the registry and only internally redirects it to sparse+https://index.crates.io/ when it is configured to use the sparse protocol for crates.io.

2 Likes