fix(info): resolve underscore vs hyphen mismatch in schema lookup#16455
fix(info): resolve underscore vs hyphen mismatch in schema lookup#16455epage merged 2 commits intorust-lang:masterfrom
Conversation
|
i will add one more commit for the functionality change, before that please check this code if it is good or not? |
b577f22 to
d371702
Compare
This comment has been minimized.
This comment has been minimized.
d371702 to
e590ced
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
From discussion in #general > writing test for cargo @ 💬
Currently Cargo will prioritize crates that match the current workspace's MSRV (ref) when selecting the package. Not sure how others feel about this behavior but I wanted to call this out during review. Edit: Apparently crates.io does not allow publishing crates with the same name as an existing crate with hyphens instead of underscores and vise versa. So my concern here might not be a problem in practice. Though unsure if we need to worry about 3rd party registries. I don't see this behavior specified in the Cargo registry API docs. |
ee9afc3 to
3e8367f
Compare
|
I just renamed the PR title, as we usually only include one type in the Conventional Message. |
tests/testsuite/cargo_info/crate_name_normalization_from_hyphen_to_underscore/mod.rs
Show resolved
Hide resolved
11b9042 to
dea0635
Compare
There was a problem hiding this comment.
Thanks @dhruv-38 for implementing this and @ranger-ross for reviewing it!
Update cargo submodule 5 commits in 8c133afcd5e0d69932fe11f5907683723f8d361d..6d1bd93c47f059ec1344cb31e68a2fb284cbc6b1 2026-01-09 03:50:15 +0000 to 2026-01-10 12:53:59 +0000 - fix: preserve `dep_name` for build script metadata (rust-lang/cargo#16494) - refactor(toml): clarify `to_dependency` for config patch (rust-lang/cargo#16492) - Add `--id` flag to `cargo report timings` and `cargo report rebuilds` (rust-lang/cargo#16490) - Display lockfile path in very verbose mode when blocking (rust-lang/cargo#16491) - fix(info): resolve underscore vs hyphen mismatch in schema lookup (rust-lang/cargo#16455) --- An extra submodule update right after <#150739> due to a relatively impactful nightly regression <rust-lang/cargo#16493>
Update cargo submodule 5 commits in 8c133afcd5e0d69932fe11f5907683723f8d361d..6d1bd93c47f059ec1344cb31e68a2fb284cbc6b1 2026-01-09 03:50:15 +0000 to 2026-01-10 12:53:59 +0000 - fix: preserve `dep_name` for build script metadata (rust-lang/cargo#16494) - refactor(toml): clarify `to_dependency` for config patch (rust-lang/cargo#16492) - Add `--id` flag to `cargo report timings` and `cargo report rebuilds` (rust-lang/cargo#16490) - Display lockfile path in very verbose mode when blocking (rust-lang/cargo#16491) - fix(info): resolve underscore vs hyphen mismatch in schema lookup (rust-lang/cargo#16455) --- An extra submodule update right after <#150739> due to a relatively impactful nightly regression <rust-lang/cargo#16493>
Update cargo submodule 5 commits in 8c133afcd5e0d69932fe11f5907683723f8d361d..6d1bd93c47f059ec1344cb31e68a2fb284cbc6b1 2026-01-09 03:50:15 +0000 to 2026-01-10 12:53:59 +0000 - fix: preserve `dep_name` for build script metadata (rust-lang/cargo#16494) - refactor(toml): clarify `to_dependency` for config patch (rust-lang/cargo#16492) - Add `--id` flag to `cargo report timings` and `cargo report rebuilds` (rust-lang/cargo#16490) - Display lockfile path in very verbose mode when blocking (rust-lang/cargo#16491) - fix(info): resolve underscore vs hyphen mismatch in schema lookup (rust-lang/cargo#16455) --- An extra submodule update right after <rust-lang/rust#150739> due to a relatively impactful nightly regression <rust-lang/cargo#16493>
Update cargo submodule 5 commits in 8c133afcd5e0d69932fe11f5907683723f8d361d..6d1bd93c47f059ec1344cb31e68a2fb284cbc6b1 2026-01-09 03:50:15 +0000 to 2026-01-10 12:53:59 +0000 - fix: preserve `dep_name` for build script metadata (rust-lang/cargo#16494) - refactor(toml): clarify `to_dependency` for config patch (rust-lang/cargo#16492) - Add `--id` flag to `cargo report timings` and `cargo report rebuilds` (rust-lang/cargo#16490) - Display lockfile path in very verbose mode when blocking (rust-lang/cargo#16491) - fix(info): resolve underscore vs hyphen mismatch in schema lookup (rust-lang/cargo#16455) --- An extra submodule update right after <rust-lang/rust#150739> due to a relatively impactful nightly regression <rust-lang/cargo#16493>
Update cargo submodule 15 commits in 8c133afcd5e0d69932fe11f5907683723f8d361d..85eff7c80277b57f78b11e28d14154ab12fcf643 2026-01-09 03:50:15 +0000 to 2026-01-15 16:18:08 +0000 - fix(lockfile): switch to `resolver.lockfile-path` config (rust-lang/cargo#16510) - Moved build-script bins to `deps` directory (rust-lang/cargo#16515) - Invalidate the whole build cache when `-Zno-embed-metadata` changes (rust-lang/cargo#16513) - Do not create examples dir in build dir with new layout (rust-lang/cargo#16514) - fix(git): avoid partial oid got zero padded (rust-lang/cargo#16511) - Optimize cargo locate-project --workspace (rust-lang/cargo#16423) - chore: Update typos (rust-lang/cargo#16507) - refactor(git): remove unnecessary serialization (rust-lang/cargo#16505) - fix(build-std): std link metadata propagate to user (rust-lang/cargo#16496) - Improve error message for missing dependencies (rust-lang/cargo#16500) - fix: preserve `dep_name` for build script metadata (rust-lang/cargo#16494) - refactor(toml): clarify `to_dependency` for config patch (rust-lang/cargo#16492) - Add `--id` flag to `cargo report timings` and `cargo report rebuilds` (rust-lang/cargo#16490) - Display lockfile path in very verbose mode when blocking (rust-lang/cargo#16491) - fix(info): resolve underscore vs hyphen mismatch in schema lookup (rust-lang/cargo#16455) r? ghost
What does this PR try to resolve?
This PR makes
cargo infohandle crate names with underscores (_) the same way as cargo add, by translating underscores to hyphens (-) and emitting a warning and also the other way around.Currently,
cargo info my_packageandcargo info my-cratefails even when the actual crate name ismy-packageandmy_craterespectively, which is surprising and inconsistent with other Cargo commands. This change aligns cargo info withexisting behavior and improves usability.
Fixes #16442
How to test and review this PR?
Run the added tests:
cargo test --test testsuite -- cargo_info::crate_name_normalization_from_hyphen_to_underscorecargo test --test testsuite -- cargo_info::crate_name_normalization_from_underscore_to_hyphenManually verify behavior:
cargo info esp_printlncargo info big-sThis should succeed, show a warning about translating
_to-and also-to_, and display the crate info.The change includes a test that captures the previous failing behavior and verifies the new expected output.