You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
std::i32::MAX is not i32::MAX, but i32::max_value() is on the type
This does not make any sense to me: why should const fn be preferred over consts?
the const fns for integers are disputed, but the const fns for atomics are the way to go, the old constants were hacks that existed because of the lack of const fn.
see also the discussion on the PR adding this lint #2344
Maybe what this lint needs is just better docs? The argument that ::std::usize::MAX needs the whole path, but usize::max_value() does not because it works on the type is a good one actually.
it is more idiomatic to directly associate constants with a type than to put them in a module that only contains the type using associcated consts or const fn
this allows you to use the constant without the full path, like so usize::max_value().
now that associated consts are stable there is discussion about moving these constants into these types, and deprecating the module level ones (so using the module level ones should not be encouraged)
@petrochenkov you had strong thoughts about this. How would you document this?
rust-lang/rust#68952 stabilized the assoc_int_consts feature for Rust 1.34. For Clippy this is relevant for at least the replace_consts lint:
As far as I can tell, that lint was meant to suggest to use the associated methods on the integer primitives, instead of the constants that have now been soft-deprecated in rust-lang/rust#68952. Although, the lint doesn't really provide a reason why one is better over the other. (Please correct me if I misunderstood that lint)
The RFC also mentions a deprecation of the associated functions the lint is currently suggesting, so we might want to deprecate replace_consts altogether.
Activity
oli-obk commentedon Jan 18, 2018
no, but there are none ;)
std::i32::MAXis noti32::MAX, buti32::max_value()is on the typethe const fns for integers are disputed, but the const fns for atomics are the way to go, the old constants were hacks that existed because of the lack of const fn.
see also the discussion on the PR adding this lint #2344
gnzlbg commentedon Jan 18, 2018
FWIW I got this error on
std::usize::MAX.This makes sense.
gnzlbg commentedon Jan 18, 2018
Maybe what this lint needs is just better docs? The argument that
::std::usize::MAXneeds the whole path, butusize::max_value()does not because it works on the type is a good one actually.gnzlbg commentedon Jan 19, 2018
So I think the main arguments are:
associcated constsorconst fnusize::max_value().associated constsare stable there is discussion about moving these constants into these types, and deprecating the module level ones (so using the module level ones should not be encouraged)@petrochenkov you had strong thoughts about this. How would you document this?
Yet more Clippy
Yet more Clippy
Yet more Clippy
phansch commentedon Mar 5, 2020
rust-lang/rust#68952 stabilized the
assoc_int_constsfeature for Rust 1.34. For Clippy this is relevant for at least thereplace_constslint:As far as I can tell, that lint was meant to suggest to use the associated methods on the integer primitives, instead of the constants that have now been soft-deprecated in rust-lang/rust#68952. Although, the lint doesn't really provide a reason why one is better over the other. (Please correct me if I misunderstood that lint)
The RFC also mentions a deprecation of the associated functions the lint is currently suggesting, so we might want to deprecate
replace_constsaltogether.oli-obk commentedon Mar 5, 2020
We can keep it but suggest moving from module consts to associated constant instead of to associated functions
tesuji commentedon Apr 1, 2020
This could be closed now with #5380.