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

Numeric type module constants should be moved into inherent impls #1099

Open
lilyball opened this issue Apr 29, 2015 · 6 comments
Open

Numeric type module constants should be moved into inherent impls #1099

lilyball opened this issue Apr 29, 2015 · 6 comments
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.

Comments

@lilyball
Copy link
Contributor

All of the methods provided on our numeric types are part of the inherent impls found in core::num. But the various constants provided for these types (e.g. usize::MAX, i8::MIN, f32::EPSILON) are vended as part of modules named after the types. This seems like it should no longer be necessary now that we have associated constants, and it's confusing because clicking on the documentation for a primitive type (e.g. usize) doesn't show these constants.

@lilyball
Copy link
Contributor Author

The numeric type modules and their constants are marked as #[stable], which poses a problem for moving the constants. Experimentally, it seems that if a type and a module share a name and both define the same constant, references to the constant via the type name ends up resolving to the module constant (as opposed to throwing an ambiguity error). I don't know if this is intentional, or is actually a bug, but it does mean that we could simply duplicate the constants into the inherent impls and no existing code would break. We could then consider deprecating the constants in the numeric modules (and the modules themselves for the integral types, but not for f32 and f64 as those both have a submodule consts).

@lilyball
Copy link
Contributor Author

/cc @aturon

@lilyball
Copy link
Contributor Author

Also see rust-lang/rust#23947 which suggests the addition of these associated consts.

@petrochenkov
Copy link
Contributor

I tried to do this today, but encountered an ICE
rust-lang/rust#24938

@petrochenkov
Copy link
Contributor

I think it's a minor enough breaking change to move the constants and deprecate the modules u8, u16, etc. Not so sure about removing these modules entirely, I'd appreciate that, but it'll break all the code use-ing them.

@nrc nrc added the T-libs-api Relevant to the library API team, which will review and decide on the RFC. label Aug 30, 2016
@bstrie
Copy link
Contributor

bstrie commented May 13, 2019

Spongebob Narrator voice: "Four years later."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

4 participants