-
Notifications
You must be signed in to change notification settings - Fork 1.7k
False positive of zero_repeat_side_effects
with a const function
#13110
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
Comments
I think clippy is right about this warning. |
Thank you for your reply. I agree that the provided code snippet doesn't do anything meaningful, as it just creates a zero-sized array with a redundant initializer call. If a developer can easily rewrite the code, fixing it would be straightforward. However, my initial concern was that generating a warning about a side effect itself doesn't seem reasonable because it is a compile-time constant expression, which clearly cannot cause a side effect. Additionally, I thought that it might create unnecessary Clippy CI failures on automatically generated code (e.g., macro expansion). For example, I encountered this issue while working on a project with a macro functionality. To explain it briefly, there was a macro ( In summary, I think this lint might reject many old use cases of zero-sized arrays with constant initializers, and it would be great if we could allow cases where the initializer is a constant expression. |
I do agree though that it probably still shouldn't lint in your linked PR. |
Looking at the code you linked, I think we could silent this lint when the array length initializer are from macro expansion. |
Summary
When a zero-sized array is declared with a
const
initializer function, azero_repeat_side_effects
warning is generated, despite the initializer being constant.Lint Name
zero_repeat_side_effects
Reproducer
I tried this code:
I saw this happen:
I expected to see no warning from the Clippy.
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: