Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix [multiple_crate_versions] to correctly normalize package names to avoid missing the local one #12146

Merged

Conversation

kristof-mattei
Copy link
Contributor

Fixes #12145

changelog: [multiple_crate_versions]: correctly normalize package name

@rustbot
Copy link
Collaborator

rustbot commented Jan 14, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Manishearth (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 14, 2024
@@ -16,7 +16,7 @@ pub(super) fn check(cx: &LateContext<'_>, metadata: &Metadata) {

if let Some(resolve) = &metadata.resolve
&& let Some(local_id) = packages.iter().find_map(|p| {
if p.name == local_name.as_str() {
if p.name.replace('-', "_") == local_name.as_str() {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we can avoid the allocation by using iteration here

May be a premature optimization

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've replaced it by iterating over the chars. While this allocates a char on each end per char compared at least it stops once they're not equal.

A further (and nastier) optimization would be to go through it as bytes to avoid the u8 -> char bloat but then we're introducing a (hidden) dependency on the fact that the name never is anything else than ASCII.

This feels like a better tradeoff.

Thanks for the review, it made me read up on a lot of stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

While this allocates a char on each end per char compared at least it stops once they're not equal.

it's a stack allocation, not usually what people mean when talking about allocations.

Copy link
Member

Choose a reason for hiding this comment

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

but yeah why not make the change to use .as_bytes() and normalize b'-' to b'_'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While this allocates a char on each end per char compared at least it stops once they're not equal.

it's a stack allocation, not usually what people mean when talking about allocations.

Thanks for that. I didn't think of that. It's all new for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but yeah why not make the change to use .as_bytes() and normalize b'-' to b'_'

Let me do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Manishearth Done. Thanks for the mentoring.

@kristof-mattei
Copy link
Contributor Author

@rustbot review

@kristof-mattei
Copy link
Contributor Author

@rustbot review

@Manishearth
Copy link
Member

@bors r+

thanks!

@bors
Copy link
Collaborator

bors commented Jan 17, 2024

📌 Commit e8ec998 has been approved by Manishearth

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Jan 17, 2024

⌛ Testing commit e8ec998 with merge bb2d497...

@bors
Copy link
Collaborator

bors commented Jan 17, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Manishearth
Pushing bb2d497 to master...

@bors bors merged commit bb2d497 into rust-lang:master Jan 17, 2024
5 checks passed
@kristof-mattei kristof-mattei deleted the multiple-crate-versions-with-dashes branch February 8, 2024 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

multiple_crate_versions doesn't report when name contains a dash
4 participants