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

Warn against using legacy std integral constants #10995

Closed
pitaj opened this issue Jun 20, 2023 · 1 comment · Fixed by #12312
Closed

Warn against using legacy std integral constants #10995

pitaj opened this issue Jun 20, 2023 · 1 comment · Fixed by #12312
Labels
A-lint Area: New lints

Comments

@pitaj
Copy link
Contributor

pitaj commented Jun 20, 2023

What it does

This lint triggers on usage of legacy integral constants and functions, such as:

  • std::i32::MAX
  • u64::max_value()

Advantage

Enforce a consistent style across the ecosystem.

This lint should probably be placed into the clippy::style group.

Drawbacks

Older projects will experience some churn, but this should be trivially auto-fixable in most cases.

T-libs-api opposes deprecating this outright so a clippy lint is the next best thing.

Example

if x == std::i32::MAX {

Could be written using the associated constant as:

if x == i32::MAX {
@xFrednet
Copy link
Member

The PR was closed due to inactivity, if anyone is interested in picking up this issue, that PR would be a good starting point. We also discussed, how the lint should behave in that PR.

bors added a commit that referenced this issue Mar 30, 2024
new lint `legacy_numeric_constants`

Rework of #10997

- uses diagnostic items
- does not lint imports of the float modules (`use std::f32`)
- does not lint usage of float constants that look like `f32::MIN`

I chose to make the float changes because the following pattern is actually pretty useful
```rust
use std::f32;
let omega = freq * 2 * f32::consts::PI;
```
and the float modules are not TBD-deprecated like the integer modules.

Closes #10995

---

changelog: New lint [`legacy_numeric_constants`]
[#12312](#12312)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
2 participants