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

Replace uses of T::max_value() with T::MAX #156

Closed
brycx opened this issue Dec 13, 2020 · 4 comments · Fixed by #160
Closed

Replace uses of T::max_value() with T::MAX #156

brycx opened this issue Dec 13, 2020 · 4 comments · Fixed by #160
Labels
good first issue Good for newcomers improvement General improvements to code

Comments

@brycx
Copy link
Member

brycx commented Dec 13, 2020

The max value that a primitive type can represent has been made accessible as an associated constant. The max_value()/min_value() functions are soft-deprecated.

u32::max_value()

should change to

u32::MAX

If T::min_value() is used anywhere, this should be replaced with T::MIN.

Bumps MSRV to 1.43.0.

@brycx brycx added good first issue Good for newcomers improvement General improvements to code labels Dec 13, 2020
@u5surf
Copy link
Contributor

u5surf commented Dec 14, 2020

@brycx
Hi, I'd like to tackle this issue.
In my grep results, T::min_value() is not used anywhere.

% grep -rn "T::min_value" ./
%

@brycx
Copy link
Member Author

brycx commented Dec 14, 2020

@u5sur, you're more than welcome!

And yes, that's the immediate impression I got as well. So, just looking for the maximum should suffice.

Edit: Just a heads-up, T in my description is simply a placeholder for any type. You'd probably have to look for something like u64::min_value(), or just min_value() (when you're greping).

u5surf added a commit to u5surf/orion that referenced this issue Dec 19, 2020
u5surf added a commit to u5surf/orion that referenced this issue Dec 19, 2020
@u5surf
Copy link
Contributor

u5surf commented Dec 19, 2020

@brycx
Unfortunately, because this MSRV is 1.41.1, we cannot use associated constant directly. From 1.43.0 can use them, or use std::T::MAX

see:
https://blog.rust-lang.org/2020/04/23/Rust-1.43.0.html

@brycx
Copy link
Member Author

brycx commented Dec 19, 2020

Indeed, this requires 1.43.0, as I've mentioned in the description. This is no problem at all.

If you want, you can change the MSRV to 1.43.0, in tests.yml in the .github folder:

       rust:
          - stable
          - beta
          - nightly
          - 1.41.0 # MSRV

brycx pushed a commit that referenced this issue Dec 20, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
* Replace T::max_value() with MAX (#156)

* Update MSRV 1.43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers improvement General improvements to code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants