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

Consider excluding Duration's associated constants from identity_op lint #3866

Closed
dtolnay opened this issue Mar 11, 2019 · 2 comments
Closed
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@dtolnay
Copy link
Member

dtolnay commented Mar 11, 2019

This came up in the tracking issue for std::time::Duration::SECOND and friends: rust-lang/rust#57391.

The following code using 1 * SECOND arguably reads more clearly in English than thread::sleep(SECOND).

#![feature(duration_constants)]

use std::thread;
use std::time::Duration;

fn main() {
    thread::sleep(1 * Duration::SECOND);
}
warning: the operation is ineffective. Consider reducing it to `Duration::SECOND`
 --> src/main.rs:7:19
  |
7 |     thread::sleep(1 * Duration::SECOND);
  |                   ^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(clippy::identity_op)] on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_op

The same pattern is common in Go which uses a similar mechanism for time constants. From a brief search, here are some articles that use 1 * time.Second or 1*time.Second in Go:

This may indicate that this pattern does not fall under the "obscures what’s going on" description of the identity_op lint.

clippy 0.0.212 (5d78250 2019-03-07)

@oli-obk oli-obk added the C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages label Mar 11, 2019
@oli-obk
Copy link
Contributor

oli-obk commented Mar 11, 2019

I agree, we should maybe just whitelist multiplying with constants, since no matter what the constant is, the user is probably doing that multiplication out of a reason.

@rustbot rustbot added the I-false-positive Issue: The lint was triggered on code it shouldn't have label Sep 13, 2021
@xFrednet xFrednet removed the I-false-positive Issue: The lint was triggered on code it shouldn't have label Sep 13, 2021
@camsteffen camsteffen added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have good-first-issue These issues are a good way to get started with Clippy and removed C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Nov 15, 2021
@Alexendoo
Copy link
Member

No longer linted: #8204

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

6 participants