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

Encourage fixed-size integer #16446

Closed
l0kod opened this Issue Aug 12, 2014 · 20 comments

Comments

Projects
None yet
5 participants
@l0kod
Copy link
Contributor

l0kod commented Aug 12, 2014

The #6023 force to use a type suffix for integers. As discussed in rust-lang/rfcs#115 and #9940, the int and uint should only be used for memory-related values (e.g. length).

The documentations mostly use i suffix examples. It should encourage the use of fixed-size integer (e.g. u32) for common uses.

A more strict rule could be to remove the u and i from allowed suffixes, but to rely on full explicit typing (e.g. : int) when really needed.
This could be annoying for range-like functions but it's not that burdensome to use the explicit generic typing (e.g. range::<uint>(0, 5)).

@huonw

This comment has been minimized.

Copy link
Member

huonw commented Aug 12, 2014

cc #11831

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Aug 12, 2014

The documentations

Can you be more specific? I also feel like #15526 is related, this may just be a superset of that issue.

@l0kod

This comment has been minimized.

Copy link
Contributor Author

l0kod commented Aug 12, 2014

The documentations (i.e. tutorial, guide…) part is definitely #15526.

The strict rule about removing i and/or u can be discussed here.

@thestinger

This comment has been minimized.

Copy link
Contributor

thestinger commented Aug 15, 2014

I don't think the suffixes should be removed. Fixed-size integers are a better choice for anything not being used for sizes / indexing, but I have a feeling that the most common case is tied to container lengths. I didn't like the fallback because it was prone to causing mistakes, but I don't think we should go out of the way to make things more painful.

@vks

This comment has been minimized.

Copy link
Contributor

vks commented Aug 15, 2014

Currently the documentation teaches new users to use int and uint in a lot of places where it is not related to any container size. Especially int is very rarely related to container sizes (which are never negative).

@l0kod

This comment has been minimized.

Copy link
Contributor Author

l0kod commented Aug 18, 2014

@l0kod

This comment has been minimized.

Copy link
Contributor Author

l0kod commented Aug 25, 2014

cc #16736

@l0kod

This comment has been minimized.

Copy link
Contributor Author

l0kod commented Sep 1, 2014

@l0kod

This comment has been minimized.

Copy link
Contributor Author

l0kod commented Sep 1, 2014

cc #14758

@l0kod

This comment has been minimized.

Copy link
Contributor Author

l0kod commented Sep 1, 2014

@thestinger, could you please change the label for "metabug" (if appropriate)?

@l0kod

This comment has been minimized.

Copy link
Contributor Author

l0kod commented Sep 3, 2014

@l0kod

This comment has been minimized.

Copy link
Contributor Author

l0kod commented Oct 18, 2014

Some int/uint bugs:

@l0kod

This comment has been minimized.

Copy link
Contributor Author

l0kod commented Nov 15, 2014

@l0kod

This comment has been minimized.

Copy link
Contributor Author

l0kod commented Jan 3, 2015

Other int/uint bug:

@l0kod

This comment has been minimized.

Copy link
Contributor Author

l0kod commented Jan 3, 2015

@l0kod

This comment has been minimized.

Copy link
Contributor Author

l0kod commented Jan 3, 2015

Another related bug:

@l0kod

This comment has been minimized.

Copy link
Contributor Author

l0kod commented Jan 3, 2015

Integer overflow bug:

@huonw

This comment has been minimized.

Copy link
Member

huonw commented Jan 3, 2015

@l0kod #17795 doesn't seem to be caused by the names/sizes/conventions of integers in Rust. At some point in the past libc::c_uint was precisely correct (LLVM used unsigned int) but then LLVM was changed to use unsigned long long without us realising, causing the FFI declaration to become incorrect.

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Jan 12, 2015

We've gone through and made a lot of changes related to this, and so I'm gonna give it a close. If we find anything else, it should also be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.