uutils / coreutils

Cross-platform Rust rewrite of the GNU coreutils
https://uutils.github.io/
MIT License
17.23k stars 1.24k forks source link

shuf: lint error legacy_numeric_constants with Rust 1.79.0 #6478

Closed lcheylus closed 2 weeks ago

lcheylus commented 2 weeks ago

When checking lint errors with Rust v1.79.0 (cargo clippy), there are some "usage of a legacy numeric method" errors in src/uu/shuf/src/shuf.rs:

$ cargo clippy --all-targets -puu_shuf -- -W clippy::manual_string_new -D warnings
(...)
    Checking uu_shuf v0.0.26 (/home/fox/dev/Perso/rust-coreutils.git/src/uu/shuf)
error: usage of a legacy numeric constant
   --> src/uu/shuf/src/shuf.rs:534:63
    |
534 |         assert_eq!(false, number_set_should_list_remaining(0, std::usize::MAX));
    |                                                               ^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants
    = note: `-D clippy::legacy-numeric-constants` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::legacy_numeric_constants)]`
help: use the associated constant instead
    |
534 |         assert_eq!(false, number_set_should_list_remaining(0, usize::MAX));
    |                                                               ~~~~~~~~~~

error: usage of a legacy numeric constant
   --> src/uu/shuf/src/shuf.rs:539:63
    |
539 |         assert_eq!(false, number_set_should_list_remaining(1, std::usize::MAX));
    |                                                               ^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants
help: use the associated constant instead
    |
539 |         assert_eq!(false, number_set_should_list_remaining(1, usize::MAX));
    |                                                               ~~~~~~~~~~

error: usage of a legacy numeric constant
   --> src/uu/shuf/src/shuf.rs:544:63
    |
544 |         assert_eq!(false, number_set_should_list_remaining(9, std::usize::MAX));
    |                                                               ^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants
help: use the associated constant instead
    |
544 |         assert_eq!(false, number_set_should_list_remaining(9, usize::MAX));
    |                                                               ~~~~~~~~~~

error: usage of a legacy numeric constant
   --> src/uu/shuf/src/shuf.rs:590:53
    |
590 |             number_set_should_list_remaining(12345, std::usize::MAX)
    |                                                     ^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants
help: use the associated constant instead
    |
590 |             number_set_should_list_remaining(12345, usize::MAX)
    |                                                     ~~~~~~~~~~

error: usage of a legacy numeric constant
   --> src/uu/shuf/src/shuf.rs:598:46
    |
598 |             number_set_should_list_remaining(std::usize::MAX - 1, std::usize::MAX)
    |                                              ^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants
help: use the associated constant instead
    |
598 |             number_set_should_list_remaining(usize::MAX - 1, std::usize::MAX)
    |                                              ~~~~~~~~~~

error: usage of a legacy numeric constant
   --> src/uu/shuf/src/shuf.rs:598:67
    |
598 |             number_set_should_list_remaining(std::usize::MAX - 1, std::usize::MAX)
    |                                                                   ^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants
help: use the associated constant instead
    |
598 |             number_set_should_list_remaining(std::usize::MAX - 1, usize::MAX)
    |                                                                   ~~~~~~~~~~

error: usage of a legacy numeric constant
   --> src/uu/shuf/src/shuf.rs:606:46
    |
606 |             number_set_should_list_remaining(std::usize::MAX, std::usize::MAX)
    |                                              ^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants
help: use the associated constant instead
    |
606 |             number_set_should_list_remaining(usize::MAX, std::usize::MAX)
    |                                              ~~~~~~~~~~

error: usage of a legacy numeric constant
   --> src/uu/shuf/src/shuf.rs:606:63
    |
606 |             number_set_should_list_remaining(std::usize::MAX, std::usize::MAX)
    |                                                               ^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants
help: use the associated constant instead
    |
606 |             number_set_should_list_remaining(std::usize::MAX, usize::MAX)
    |                                                               ~~~~~~~~~~

error: could not compile `uu_shuf` (lib test) due to 8 previous errors

std::usize::MAX needs to be replaced by usize::MAX => deprecated in future version, see https://rust-lang.github.io/rust-clippy/master/index.html#/legacy_numeric_constants

cakebaker commented 2 weeks ago

Hm, wondering why those warnings don't show up with cargo clippy --all-targets.

lcheylus commented 2 weeks ago

Hm, wondering why those warnings don't show up with cargo clippy --all-targets.

There is an issue with UTILITY_LIST used in CI (generated by util/show-utils.sh script) => the list of tools to test with cargo clippy is empty.

I will create a specific entry for this issue.

cakebaker commented 2 weeks ago

I will create a specific entry for this issue.

Great, thanks!