-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
repeat_once
triggers when the parameter is a constant
#7306
Comments
@rustbot claim |
Hey @giraffate and @flip1995 the lint implementation contains a deliberate test that resolves the value of constants, like in this case. You two discussed the check here. Would you also consider this to be a false positive, or working as intended? 🙃 |
Yes, that was the intention. I thought that warning is valid in many cases at that time.
However, if this is a common case, it's a good idea to change that behavior. |
I'd like to note that I don't feel too strongly about this - I can always just disable the lint. I just wanted to report it since it felt a little surprising. |
I mean, if you change this constant the lint will no longer trigger. But as long as the constant is So I would keep the current behavior. Especially because code like "x".repeat(NUMBER + const_fn() * ANOTHER_CONST); may result in an unintentional |
Thank you for the feedback. I'm still undecided on this one, constants are usually used for readability and to make parts kind of configurable. This ticket basically addresses the second reason of making things configurable. Due to the previous comments, I would suggest keeping the current behavior and adding a note about this to the lint documentation. Would that work for everyone? |
Yes, and on the other hand they may hide the real value of the constant. Linting also on constants is therefore generally a good idea IMO.
SGTM |
I like the point raised by @flip1995 in #7306 (comment), so I agree that this behaviour is correct. |
Lint name:
repeat_once
I tried this code:
I expected to see this happen: the lint is not triggered because if I used a constant as a parameter I probably intend to allow changing the constant value to something else in the future.
Instead, this happened: the lint triggers
Meta
cargo clippy -V
: clippy 0.1.54 (1c6868a 2021-05-27rustc -Vv
:The text was updated successfully, but these errors were encountered: