-
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
Lint for soft-deprecated {integer}::max_value
and min_value
#5841
Comments
I'll try to do this |
I'm a bit stuck because I can't properly figure out a way to detect "indirect" impl Foo {
type Int = i32;
fn min_value() -> Int {
Self::Int::min_value() // lint
}
}
Foo::min_value(); // shouldn't lint!
Foo::Int::min_value(); // lint
type Int = i32;
let _ = Int::min_value(); // lint I'm helpless with the rustc internals and its documentation is hardly helping. |
You have to compare the path of the functions. You can search the Clippy codebase for |
As far as I can tell, match_qpath is for matching a path 1:1. However, I need a way to "resolve" paths to the actual function and call against that. I don't see any way of using match_qpath that would catch all three cases I've outlined above |
Ah I see. This may work with rust-clippy/clippy_lints/src/utils/mod.rs Line 1358 in 2e0f8b6
which you can then compare to the rust-clippy/clippy_lints/src/utils/mod.rs Line 1184 in 2e0f8b6
|
There has been some progress on the Rust side of things (tracking issue). Rust has recently added support for 'soft-deprecation' of items: rust-lang/rust#79877. The next step will be to soft-deprecate the old items in std directly. Considering that, I don't think it makes sense to implement this in Clippy anymore and I'm going to go ahead and close this issue. Thanks everyone for your interest in working on this lint 💙 |
What it does
Currently, Rust have three way to getting min/max of an integers:
std::i32::MAX
i32::MAX
i32::max_value()
(3) is soft-deprecated and replaced by 2) when possible.
T-libs doesn't want to deprecate 1) and 3) now until next Rust edition,
but we have no tools to enforce style for 2),
it is great to have such a lint in Clippy.
Categories (optional)
Drawbacks
None.
The text was updated successfully, but these errors were encountered: