Skip to content

Add new lint zero_repeat_side_effects #12449

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

Merged
merged 2 commits into from
Mar 9, 2024
Merged

Conversation

Jacherr
Copy link
Contributor

@Jacherr Jacherr commented Mar 9, 2024

Fixes #6439

Adds a new suspicious lint zero_repeat_side_effects. This lint warns the user when initializing an array or Vec using the Repeat syntax, i.e., [x; y]. If x is an Expr::Call/MethodCall or contains an Expr::Call/MethodCall and y is zero, then there is a chance that the internal call can produce side effects, such as printing to console, which is not very obvious.

This lint warns against this and instead suggests to separate out the function call and the array/Vec initialization.

changelog: Add new lint zero_repeat_side_effects

@rustbot
Copy link
Collaborator

rustbot commented Mar 9, 2024

r? @llogiq

rustbot has assigned @llogiq.
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 Mar 9, 2024
@llogiq
Copy link
Contributor

llogiq commented Mar 9, 2024

This looks good. As a possible extension, we have a quasi-purity test in must_use_candidate that could even allow us to suggest getting rid of the call altogether (although the user should check that, the test might fail to find some side effects).

@llogiq
Copy link
Contributor

llogiq commented Mar 9, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Mar 9, 2024

📌 Commit 0c82fd0 has been approved by llogiq

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Mar 9, 2024

⌛ Testing commit 0c82fd0 with merge d8a9068...

@bors
Copy link
Contributor

bors commented Mar 9, 2024

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

@bors bors merged commit d8a9068 into rust-lang:master Mar 9, 2024
@Jacherr Jacherr deleted the issue-6439 branch March 9, 2024 20:23
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.

Warn the user about side effects when creating empty arrays and vectors
4 participants