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

auto-fix slow_vector_initialization in some cases #13947

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lapla-cogito
Copy link
Contributor

@lapla-cogito lapla-cogito commented Jan 5, 2025

I made a change for slow_vector_initialization lint suggestion to use vec! with size and remove the unneeded resize (or similar one) call in #13912, while only the former one was suggested in the previous implementation. Now, I think this lint can be automatically fixed with no unnecessary code in some cases. I wrote “in some cases” because if there are comments between vector declaration and resize, Clippy shouldn't apply auto-fix because the comment may informational.

changelog: [slow_vector_initialization]: auto-fix when appropriate

@rustbot
Copy link
Collaborator

rustbot commented Jan 5, 2025

r? @blyxyas

rustbot has assigned @blyxyas.
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

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 5, 2025
Comment on lines +211 to +216
// If there is no comment in `span_to_replace`, Clippy can automatically fix the code.
let app = if span_contains_comment(cx.tcx.sess.source_map(), span_to_replace) {
Applicability::Unspecified
} else {
Applicability::MachineApplicable
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the span to be linted contains comments, use Applicability::Unspecified, otherwise use Applicability::MachineApplicable.

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.

3 participants