Skip to content

Conversation

@dhruv-38
Copy link
Contributor

@dhruv-38 dhruv-38 commented Jan 1, 2026

What does this PR try to resolve?

This PR makes cargo info handle 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_package and cargo info my-crate fails even when the actual crate name is my-package and my_crate respectively, which is surprising and inconsistent with other Cargo commands. This change aligns cargo info with
existing 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_underscore
cargo test --test testsuite -- cargo_info::crate_name_normalization_from_underscore_to_hyphen

Manually verify behavior:
cargo info esp_println
cargo info big-s

This 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.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 1, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 1, 2026

r? @ehuss

rustbot has assigned @ehuss.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@dhruv-38
Copy link
Contributor Author

dhruv-38 commented Jan 1, 2026

i will add one more commit for the functionality change, before that please check this code if it is good or not?

Copy link
Member

@ranger-ross ranger-ross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test looks good and does what we want. Though rustfmt is failing so you'll need to fix that.
otherwise I think you should be good to start implementing the change :)

View changes since this review

@dhruv-38 dhruv-38 force-pushed the cargo-info-normalize-underscore branch from b577f22 to d371702 Compare January 2, 2026 16:13
@rustbot

This comment has been minimized.

@dhruv-38 dhruv-38 force-pushed the cargo-info-normalize-underscore branch from d371702 to e590ced Compare January 3, 2026 06:53
@rustbot
Copy link
Collaborator

rustbot commented Jan 3, 2026

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.

@ranger-ross
Copy link
Member

ranger-ross commented Jan 4, 2026

From discussion in #general > writing test for cargo @ 💬

One question about the selection behavior (MSRV) is: If there are 2 crates foo-bar (MSRV 1.91) and foo_bar (MSRV 1.70) and I execute cargo info foo-bar from a workspace that has an MSRV lower than 1.91 which crate should be selected. For me I feel cargo info should not change the crate name if there is an exact match, even if that exact match does not satisfy the MSRV of the current workspace.

Currently Cargo will prioritize crates that match the current workspace's MSRV (ref) when selecting the package.
This is less noticable when we have an Exact query as it only affects versions.
With normalized queries its possible for Cargo have an exact match that does not satisfy the MSRV, so we could potentially select a different crate even though the exact match exists. (which feels like the wrong behavior for cargo info to me)

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.

@rustbot rustbot added A-interacts-with-crates.io Area: interaction with registries Command-info labels Jan 4, 2026
@dhruv-38 dhruv-38 changed the title test(cargo-info): reproduce underscore vs hyphen lookup failure test&fix(cargo-info): reproduce and fix underscore vs hyphen lookup failure Jan 4, 2026
@dhruv-38 dhruv-38 force-pushed the cargo-info-normalize-underscore branch 2 times, most recently from ee9afc3 to 3e8367f Compare January 7, 2026 10:31
Copy link
Member

@ranger-ross ranger-ross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look good to me.

Given that @0xPoe is the one that added this command originally, I'll assign them for a Cargo team member review :)

r? @0xPoe

View changes since this review

@rustbot rustbot assigned 0xPoe and unassigned ehuss Jan 7, 2026
@0xPoe 0xPoe changed the title test&fix(cargo-info): reproduce and fix underscore vs hyphen lookup failure fix(info): resolve underscore vs hyphen mismatch in schema lookup Jan 7, 2026
@0xPoe
Copy link
Member

0xPoe commented Jan 7, 2026

I just renamed the PR title, as we usually only include one type in the Conventional Message.

@dhruv-38 dhruv-38 force-pushed the cargo-info-normalize-underscore branch from 11b9042 to dea0635 Compare January 8, 2026 22:35
Copy link
Contributor

@epage epage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dhruv-38 for implementing this and @ranger-ross for reviewing it!

View changes since this review

@epage epage added this pull request to the merge queue Jan 9, 2026
Merged via the queue into rust-lang:master with commit fe13bb8 Jan 9, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 9, 2026
rust-bors bot added a commit to rust-lang/rust that referenced this pull request Jan 11, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-interacts-with-crates.io Area: interaction with registries Command-info

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cargo info does not support underscore (_) for packages named with hyphen (-)

6 participants